Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behavior when parsing a human-readable expression #115

Closed
osher opened this issue Dec 9, 2018 · 2 comments
Closed

Unexpected behavior when parsing a human-readable expression #115

osher opened this issue Dec 9, 2018 · 2 comments

Comments

@osher
Copy link

osher commented Dec 9, 2018

Use-Case Overview

I added ms to let Ops configure some intervals on their ~/config/local.yaml in a human-readable fashion.

The ops tried:

app:
   interval: 1h 30min

This evidently did not behave as expected.

Reproduction steps:

const ms = require('ms');
const v = ms('1h 30min')
console.log(v)

expected behavior

5400000

found behavior

undefined
@osher
Copy link
Author

osher commented Dec 9, 2018

Workaround:
parse every part by yourself, and sum the elements

const s = '1h 30min';
const v = s.replace(/([0-9])[ \t]+([^ \t])/g, (_, digit, char) => `${digit}${char}`)
      .trim().split(/[ \t]+/)
      .map(val => parse(val)).reduce((a,b) => a + b);

@styfle
Copy link
Member

styfle commented Dec 7, 2020

ms('1h') + ms('30m') is the best workaround.

Colons are probably better like this feature request #24

Parse errors are suggested in feature request #123

@styfle styfle closed this as completed Dec 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants