parse-duration
Advanced tools
Comparing version 1.0.3 to 1.1.0
// ./index.d.ts | ||
/** | ||
* convert `str` to ms | ||
*/ | ||
export type Units = | ||
'nanosecond' | 'ns' | | ||
'µs' | 'μs' | 'us' | 'microsecond' | | ||
'millisecond' | 'ms' | | ||
'second' | 'sec' | 's' | | ||
'minute' | 'min' | 'm' | | ||
'hour' | 'hr' | 'h' | | ||
'day' | 'd' | | ||
'week' | 'wk' | 'w' | | ||
'month' | 'b' | | ||
'year' | 'yr' | 'y' | ||
declare namespace parse { | ||
/** | ||
* convert `str` to ms | ||
*/ | ||
type Units = | ||
'nanosecond' | 'ns' | | ||
'µs' | 'μs' | 'us' | 'microsecond' | | ||
'millisecond' | 'ms' | | ||
'second' | 'sec' | 's' | | ||
'minute' | 'min' | 'm' | | ||
'hour' | 'hr' | 'h' | | ||
'day' | 'd' | | ||
'week' | 'wk' | 'w' | | ||
'month' | 'b' | | ||
'year' | 'yr' | 'y' | ||
} | ||
declare const parse: ((input: string, format?: Units) => number) & { | ||
type Parse = { | ||
(input: string, format?: parse.Units): number | undefined; | ||
[key: string]: number; | ||
}; | ||
} & { | ||
default: Parse | ||
} | ||
export default parse; | ||
declare const parse: Parse; | ||
export = parse; |
@@ -64,8 +64,9 @@ 'use strict' | ||
str = (str+'').replace(/(\d)[,_](\d)/g, '$1$2') | ||
var isNegative = str[0] === '-'; | ||
str.replace(durationRE, function(_, n, units){ | ||
units = unitRatio(units) | ||
if (units) result = (result || 0) + parseFloat(n, 10) * units | ||
if (units) result = (result || 0) + Math.abs(parseFloat(n, 10)) * units | ||
}) | ||
return result && (result / (unitRatio(format) || 1)) | ||
return result && ((result / (unitRatio(format) || 1)) * (isNegative ? -1 : 1)) | ||
} | ||
@@ -72,0 +73,0 @@ |
{ | ||
"name": "parse-duration", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "convert a human readable duration string to a duration format", | ||
@@ -14,5 +14,4 @@ "keywords": [ | ||
"exports": { | ||
"require": "./index.js", | ||
"import": "./index.mjs", | ||
"types": "./index.d.ts" | ||
"default": "./index.js" | ||
}, | ||
@@ -32,3 +31,4 @@ "dependencies": {}, | ||
"index.mjs", | ||
"index.d.ts" | ||
"index.d.ts", | ||
"index.d.mts" | ||
], | ||
@@ -35,0 +35,0 @@ "license": "MIT", |
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
6776
7
138