parse-duration
Advanced tools
Comparing version 0.5.0 to 1.0.0
10
index.js
'use strict' | ||
var durationRE = /(-?(?:\d+\.?\d*|\d*\.?\d+)(?:e[-+]?\d+)?)\s*([a-zµμ]*)/ig | ||
var durationRE = /(-?(?:\d+\.?\d*|\d*\.?\d+)(?:e[-+]?\d+)?)\s*([\p{L}]*)/uig | ||
@@ -65,7 +65,11 @@ module.exports = parse | ||
str.replace(durationRE, function(_, n, units){ | ||
units = parse[units] || parse[units.toLowerCase().replace(/s$/, '')] | ||
units = unitRatio(units) | ||
if (units) result = (result || 0) + parseFloat(n, 10) * units | ||
}) | ||
return result && (result / parse[format]) | ||
return result && (result / (unitRatio(format) || 1)) | ||
} | ||
function unitRatio(str) { | ||
return parse[str] || parse[str.toLowerCase().replace(/s$/, '')] | ||
} |
{ | ||
"name": "parse-duration", | ||
"version": "0.5.0", | ||
"version": "1.0.0", | ||
"description": "convert a human readable duration string to a duration format", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -26,3 +26,3 @@ | ||
convert `str` to ms | ||
Convert `str` to ms | ||
@@ -62,3 +62,3 @@ ```js | ||
```js | ||
parse('running length: 1hour:20mins') // => 1* h + 20 * m | ||
parse('running length: 1hour:20mins') // => 1 * h + 20 * m | ||
``` | ||
@@ -91,4 +91,9 @@ | ||
And its easy to add more | ||
And its easy to add more, including unicode: | ||
```js | ||
parse['сек'] = parse['sec'] | ||
parse('5сек') // => 5000 | ||
``` | ||
The output format can also be defined | ||
@@ -95,0 +100,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
6624
127
1
101