Inconsistent number-parsing behavior on Clojurescript
KingMob opened this issue · 1 comments
parse-double and parse-int don't quite match with each other, and they're not drop-in replacements for js/parseInt and js/parseFloat, either.
Most of the cuerdas fns expect strings and return nil if the input is not a string, but (parse-double 123)
will return 123
and (parse-int 123)
will return ##NaN
, neither of which are nil, nor do they match.
They should definitely agree with each other, and I'd like to make the argument that they should handle numbers, too. In Clojurescript, they seem like natural replacements for parseInt and parseFloat, both of which handle numbers already.
user> (require '[cuerdas.core :as str])
user> (str/parse-int 123)
##NaN
user> (str/parse-double 123)
123
user> (js/parseInt 123)
123
user> (js/parseFloat 123)
123
Let me know which direction you want to go in, and I can make a PR for you, if you like.
Thanks for reporting, is already fixed in master ;)