Closed alonesuperman closed 3 years ago
No need for dynamic rules/units, locales can be added separately.
On Tue, Jul 21, 2020 at 3:55 AM alonesuperman notifications@github.com wrote:
Hi, jkroso
Although we can use parse.newUnit to extend more unit, your regexp may limit the unit as [a-zµμ]
I suggest it could change to [^\d\s] to make more possibility
var duration = /(-?(?:\d+.?\d|\d.?\d+)(?:e[-+]?\d+)?)\s([^\d\s])/ig
If u agree, I will do this job(by the way, improve the .d.ts file to allow us extend units under typescript) and take a pr in 1~2 day
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jkroso/parse-duration/issues/26, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACJII42FWR3QJJ3DMIEADLR4VCVXANCNFSM4PDI3KRQ .
wu..., but how to add locale without refactor?
@alonesuperman something like
import parse from 'parse-duration'
parse['сек'] = parse['s'] // ru seconds
parse('5сек') // 5000
should be enough. If you wish to come up with a PR, adding locales as
import parse from 'parse-duration'
import 'parse-duration/fr'
or alike - you're welcome
No, I had run test case for some times
If u use 0.4.4 without any change(except test case), let us see the test case below
The problem here as I said: The last capture group not include your unit, because сек
is out of [a-zµμ]*
And, If u apply my suggestion about modify regexp (change the last capture group [a-zµμ] to [^\d\s]), it still can not pass the test case for this threerunning length: 1hour:20mins
, 1y.2b.5days.12hours.34sec.20ms
, -1y.2b.5days 12hours,34sec,20ms
Right, it needs adjusting regex to match unicode property escapes
like that var duration = /(-?(?:\d+\.?\d*|\d*\.?\d+)(?:e[-+]?\d+)?)\s*([\p{L}]*)/uig
I can't contribute for some time, so if you'd like PR welcome!
OK, Let me have a try
Added unicode support in v1.0
Hi, jkroso
Although we can use
parse.newUnit
to extend more unit, your regexp may limit the unit as [a-zµμ]I suggest it could change to some else such as [^\d\s] to make more possibility
The change is just example, It fail to pass test case because of the noisy word
So a safer way could be either of follow:
Check the last capture group
Dynamically create regular expressions by current units collection array
If u agree, I can do some job(by the way, improve the .d.ts file to allow us extend units under typescript) and take a pr in several days