https://github.com/semibran/css-duration
Converts CSS-style durations to milliseconds.
https://github.com/semibran/css-duration
css duration milliseconds
Last synced: 6 months ago
JSON representation
Converts CSS-style durations to milliseconds.
- Host: GitHub
- URL: https://github.com/semibran/css-duration
- Owner: semibran
- License: mit
- Created: 2016-11-18T07:12:38.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-05T08:07:36.000Z (over 8 years ago)
- Last Synced: 2025-03-16T00:35:05.002Z (7 months ago)
- Topics: css, duration, milliseconds
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# css-duration
> Converts CSS-style durations to milliseconds.
```javascript
var duration = require("css-duration")duration('1000ms')
// > 1000duration('1.5s')
// > 1500duration('30m')
// > 1800000duration('8h')
// > 28800000duration('2d')
// > 172800000
```## Installation
`npm install --save css-duration`
## Usage
### `duration(time)`
Normalizes "unit-based time" (similar to CSS values) into a `Number` of milliseconds.
#### Parameters
- `time` (`String`): A CSS-style value of a duration of time (i.e. `10s`, `5h`, `0.5d`)
#### Units
- `ms`: Milliseconds
- `s`: Seconds
- `h`: Hours
- `d`: Days
- `w`: Weeks**Note:** Anything past seconds is not a valid CSS unit. Use another package for validating.
#### Example
```js
duration('0.25d')
// => 21600000duration('-1w')
// => -604800000
```## License
MIT © [Brandon Semilla](https://github.com/grandonbroseph)