-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e91e219
commit a655411
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"time-morph": patch | ||
--- | ||
|
||
add a readme |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Time Morph | ||
|
||
TimeMorph is a lightweight package for converting between different time units in JavaScript. It provides a simple API for converting durations from one unit of time to another, such as milliseconds to seconds or hours to days. | ||
|
||
## Installation | ||
|
||
You can install TimeMorph via npm: | ||
|
||
```bash | ||
npm install time-morph | ||
``` | ||
|
||
## Usage | ||
|
||
To use TimeMorph, import the `convertTime` function and pass in an object with the duration to convert and the source and target units. For example: | ||
|
||
```typescript | ||
import convertTime from 'time-morph'; | ||
|
||
const durationInSeconds = convertTime({ | ||
duration: 1000, | ||
from: 'ms', | ||
to: 'sec', | ||
}); // 1 | ||
``` | ||
|
||
In this example, the `convertTime` function takes an object with the following properties: | ||
|
||
- `duration` (required): The duration to convert, in the source unit of time. | ||
- `from` (required): The source unit of time, specified as one of the following strings: ms, sec, min, hour, day, week, month, or year. | ||
- `to` (optional): The target unit of time, specified as one of the same strings as from. If not specified, the function will return the duration in the source unit of time. | ||
|
||
The function returns the converted duration, rounded to the nearest integer. | ||
|
||
## Contributing | ||
|
||
Contributions to TimeMorph are welcome! To contribute, please fork the [repository](https://github.com/tonyaellie/convert-time) and submit a pull request with your changes. | ||
|
||
## License | ||
|
||
TimeMorph is licensed under the MIT License. See the LICENSE file for more information. |