Numeral-js: Parsing behavior is weird, invalid numeral values aren't always NaN

Created on 3 Jan 2018  路  5Comments  路  Source: adamwdraper/Numeral-js

I'm playing around with sanitizing some bulk data and came across this:

numeral('2:23:57').value()
8637
numeral('hello').value()
null
isNaN(numeral('hello').value())
false

This contradicts the documentation here which asserts two things:

  1. numeral('2:23:57') should be invalid, but it isn't. Not sure how it's coming up with a value of 8637. Could this be a bug?
  2. numeral('some invalid string').value() should equal NaN, but is instead null. This is a breaking issue because validating numerals using isNaN() no longer works!

Most helpful comment

screen shot 2018-06-08 at 1 29 38 pm
example from docs is broken
numeral('2:23:57').value() returns 8637

All 5 comments

Yeah, in general, Numeral's behavior is a bit strange. For example,

numeral('11/22/17')
112217

it parses this kind of datestring as a valid number, but when you parse a full datestring

numeral(new Date().toString()).value()
NaN

you get NaN, as opposed to null? Very odd.

Same with 1-18, value comes up as -118.

screen shot 2018-06-08 at 1 29 38 pm
example from docs is broken
numeral('2:23:57').value() returns 8637

Closing as this hasn't received any attention. I think Numeral is a great library and works well for the vast majority of use cases when you have formatted data intended to represent numbers.

@leosco what about this https://github.com/adamwdraper/Numeral-js/issues/581#issuecomment-395720712 maybe it worth to update the docs at least?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

donnyv picture donnyv  路  8Comments

rogerfar picture rogerfar  路  8Comments

chumager picture chumager  路  3Comments

rvanmil picture rvanmil  路  4Comments

jfstephe picture jfstephe  路  4Comments