borgar / numfmt

Full ECMA-376 number and date formatting in JavaScript
40 stars 9 forks source link

0.00_ parse error #54

Closed sunnyawake5 closed 1 month ago

sunnyawake5 commented 2 months ago

0.00 parse error: SyntaxError: Illegal character: 0.00 (at parseFormatSection.js:436:13) at parseFormatSection (parseFormatSection.js:436:13) at parsePattern (parsePattern.js:48:12) at prepareFormatterData (index.js:45:19)

borgar commented 1 month ago

That seems to be correct behavior. 0.00_ is not a legal format pattern and should throw an error.

If you want the formatter to handle invalid patterns for you, you need to enable that via an option:

format("0.00_", 12.34, { throws: false }); // → "######"

Also, consider - if you think this pattern comes from a trusted source, that you may have an error in you application that it is trimming the pattern strings where it should not: 0.00_ is a valid pattern.