esamattis / esamattis/underscore.string
.sprintf and .numberFormat should work on numeric strings.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 3.4k
- Forks
- 367
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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.
Beitragsleitfaden
Rechercherichtung
Finde die Implementierungen und Tests für sprintf und numberFormat und stelle dann die numerischen String-Beispiele aus dem Issue nach. Kläre das beabsichtigte Opt-in-Verhalten und die API, bevor du beide Utilities änderst; als erledigt gilt die Aufgabe, wenn numerische Strings wie vereinbart funktionieren, ohne das bestehende Verhalten der Typprüfung zu beeinträchtigen, und die demonstrierten Fälle abgedeckt sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript
- Bereich
- tooling
- Issue-Typ
- Feature
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100