underscore.string
underscore.string copied to clipboard
.sprintf and .numberFormat should work on numeric strings.
The current behavior of .sprintf and numberFormat is briefly demonstrated below. Providing numeric strings throws an error.
> ._str.sprintf("%.2f", 0.5);
"0.50"
> ._str.sprintf("%.2f", "0.5");
Error: [_.sprintf] expecting number but found string
With respect to keeping the utility functions as simple as possible, this behavior is considered 'correct'. Since JS is loose-typed, at least having an option to run these would be beneficial to developers. I'd prefer not to cast all inputs with parseFloat or parseInt before using the utility, when it does it already just after it's own type check.
I agree! Any improvement on this so far?
Thank you.