From 7052174723cb1c43fdf0c96fc70782cc8e315721 Mon Sep 17 00:00:00 2001 From: Melonges Date: Tue, 26 Mar 2024 11:58:42 +0300 Subject: [PATCH] v0.2.0 rename functions --- README.md | 19 ++++++++++--------- package.json | 2 +- src/convertToMilliseconds.js | 2 +- src/convertToReadableFormat.js | 2 +- src/index.js | 4 ++-- types/time-format.d.ts | 2 +- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 2060d11..b114783 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ The time-convector library provides utility functions for converting time between human-readable format and milliseconds. +## No dependencies + +This library does not depend on any other libraries. + ## Installation You can install the time-convector library using npm: `npm install time-convector` @@ -9,26 +13,23 @@ You can install the time-convector library using npm: `npm install time-convecto ## Usage ```javascript -const { - convertToReadableFormat, - convertToMilliseconds, -} = require('time-convector'); +const { convertToHumanReadable, convertToMs } = require("time-convector"); // Convert milliseconds to human-readable format -convertToReadableFormat(114048000000); // Output: 3Y 8M 23h +convertToHumanReadable(114048000000); // Output: 3Y 8M 23h // Convert human-readable time to milliseconds -convertToMilliseconds('44M'); // Output: 114048000000 +convertToMs("44M"); // Output: 114048000000 // you can combine this functions -convertToReadableFormat(convertToMilliseconds('44M')); // Output: 3Y 8M 23h +convertToHumanReadable(convertToMs("44M")); // Output: 3Y 8M 23h ``` -### `convertToReadableFormat(milliseconds)` +### `convertToHumanReadable(milliseconds)` This function takes a time duration in milliseconds as input and returns a human-readable format representing years, months, days, hours, minutes, and seconds. -### `convertToMilliseconds(timeString)` +### `convertToMs(timeString)` This function takes a human-readable time duration string as input and returns the equivalent duration in milliseconds. The string should be in the format of , where the unit can be 'Y' for years, 'M' for months, 'D' for days, 'h' for hours, 'm' for minutes, and 's' for seconds. diff --git a/package.json b/package.json index 36188ea..e3f1f03 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "time-convector", "private": false, - "version": "0.1.0", + "version": "0.2.0", "type": "module", "main": "build/time-format.cjs.js", "module": "build/time-format.esm.js", diff --git a/src/convertToMilliseconds.js b/src/convertToMilliseconds.js index bd1ff2f..502e197 100644 --- a/src/convertToMilliseconds.js +++ b/src/convertToMilliseconds.js @@ -2,7 +2,7 @@ import { keysValues } from "./internal"; const regExp = /(\d+(\.\d+)?)\s*(s|m|h|D|M|Y)/; -export function convertToMilliseconds(str = "") { +export function convertToMs(str = "") { let sum = 0; let array = null; diff --git a/src/convertToReadableFormat.js b/src/convertToReadableFormat.js index ac37cce..ed97627 100644 --- a/src/convertToReadableFormat.js +++ b/src/convertToReadableFormat.js @@ -1,5 +1,5 @@ import { keysDels } from "./internal.js"; -export function convertToReadableFormat(time) { +export function convertToHumanReadable(time) { const object = { s: ((time * keysDels.s) | 0) % 60, m: ((time * keysDels.m) | 0) % 60, diff --git a/src/index.js b/src/index.js index 5b1690e..4153abd 100644 --- a/src/index.js +++ b/src/index.js @@ -1,2 +1,2 @@ -export {convertToMilliseconds} from "./convertToMilliseconds" -export {convertToReadableFormat} from "./convertToReadableFormat" \ No newline at end of file +export { convertToMs } from "./convertToMilliseconds"; +export { convertToHumanReadable } from "./convertToReadableFormat"; diff --git a/types/time-format.d.ts b/types/time-format.d.ts index 720cf8f..6b3e292 100644 --- a/types/time-format.d.ts +++ b/types/time-format.d.ts @@ -6,7 +6,7 @@ declare module "time-convector" { * @example * convertToMilliseconds('3D 2h 5s'); // returns 266405000 */ - export function convertToMilliseconds(str?: string): number; + export function convertToMs(str?: string): number; /** * The string should be in the format of where the unit can be: * 'Y' for years,