Skip to content

Commit

Permalink
v0.2.0
Browse files Browse the repository at this point in the history
rename functions
  • Loading branch information
melonges committed Mar 26, 2024
1 parent c9b88fb commit 7052174
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,34 @@

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`

## 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 <number><unit>, where the unit can be 'Y' for years, 'M' for months, 'D' for days, 'h' for hours, 'm' for minutes, and 's' for seconds.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/convertToMilliseconds.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/convertToReadableFormat.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export {convertToMilliseconds} from "./convertToMilliseconds"
export {convertToReadableFormat} from "./convertToReadableFormat"
export { convertToMs } from "./convertToMilliseconds";
export { convertToHumanReadable } from "./convertToReadableFormat";
2 changes: 1 addition & 1 deletion types/time-format.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7052174

Please sign in to comment.