esamattis / esamattis/underscore.string

.sprintf and .numberFormat should work on numeric strings.

Open
#178 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
3.4k
Forks
367
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.