parse-duration
Advanced tools
Comparing version 0.2.0 to 0.2.1
13
index.js
'use strict' | ||
var duration = /(-?\d*\.?\d+(?:e[-+]?\d+)?)\s*([a-zµμ]*)/ig | ||
var duration = /(-?(?:\d+\.?\d*|\d*\.?\d+)(?:e[-+]?\d+)?)\s*([a-zµμ]*)/ig | ||
@@ -41,4 +41,5 @@ module.exports = parse | ||
parse.month = | ||
parse.b = | ||
parse.month = parse.d * (365.25 / 12) | ||
parse.d * (365.25 / 12) | ||
@@ -57,12 +58,10 @@ parse.year = | ||
function parse(str){ | ||
var result = 0 | ||
var result = null | ||
// ignore commas | ||
str = str.replace(/(\d),(\d)/g, '$1$2') | ||
str.replace(duration, function(_, n, units){ | ||
units = parse[units] | ||
|| parse[units.toLowerCase().replace(/s$/, '')] | ||
|| 1 | ||
result += parseFloat(n, 10) * units | ||
units = parse[units] || parse[units.toLowerCase().replace(/s$/, '')] | ||
if (units) result = (result || 0) + parseFloat(n, 10) * units | ||
}) | ||
return result | ||
} |
{ | ||
"name": "parse-duration", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "convert a human readable duration string to ms", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
4225
50