css-duration
Advanced tools
Comparing version 0.1.2 to 0.2.0
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) |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
61
2990
1
1
4
1
+ Addedcss-strip-units@^1.0.0
+ Addedcss-strip-units@1.0.0(transitive)