New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

css-duration

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-duration - npm Package Compare versions

Comparing version 0.1.2 to 0.2.0

LICENSE

34

index.js

@@ -1,17 +0,19 @@

module.exports=(function(){
var n='1234567890'
return function(v){
var l=v.length
var i=l
while(i--)if(n.indexOf(v[i])!==-1)break
var s=i+1
var u=v.slice(s,l)
var q=parseFloat(v)
var m
if(u==='s')m=1000
else if(u==='m')m=60000
else if(u==='h')m=3600000
else if(u==='d')m=86400000
return q*m
var strip = require('css-strip-units')
module.exports = duration
/**
* Normalize duration value into milliseconds.
*/
function duration (time) {
var number = parseFloat(time)
switch (strip(time)) {
case 'ms': return number
case 's': return number * 1000
case 'm': return number * 60000
case 'h': return number * 3600000
case 'd': return number * 86400000
case 'w': return number * 604800000
default: return null
}
}())
}
{
"name": "css-duration",
"version": "0.1.2",
"version": "0.2.0",
"description": "Converts CSS-style durations to milliseconds.",
"main": "index.js",
"author": "Brandon Semilla (https://github.com/grandonbroseph)",
"repository": "grandonbroseph/css-duration",
"license": "MIT",
"scripts": {
"test": "tape test.js"
},
"files": [
"index.js"
],
"keywords": [

@@ -14,3 +21,9 @@ "css",

"ms"
]
],
"dependencies": {
"css-strip-units": "^1.0.0"
},
"devDependencies": {
"tape": "^4.6.2"
}
}
# css-duration
Converts CSS-style durations to milliseconds.
## Installation
`npm install --save css-duration`
> Converts CSS-style durations to milliseconds.
## Usage
```javascript

@@ -25,3 +22,40 @@ var duration = require("css-duration")

// > 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')
// => 21600000
duration('-1w')
// => -604800000
```
## License
MIT © [Brandon Semilla](https://github.com/grandonbroseph)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc