Socket
Socket
Sign inDemoInstall

parse-duration

Package Overview
Dependencies
Maintainers
3
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-duration - npm Package Compare versions

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

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