Repository navigation
fix: accept uppercase spellings of the standard option - #403
Conversation
The JSDoc for the `standard` option advertises "SI, IEC, JEDEC", but
STANDARD_CONFIGS is keyed on lowercase "si"/"iec"/"jedec", so any
uppercase spelling missed the lookup and silently fell through to the
decimal default:
filesize(1048576, { standard: "iec" }) // "1 MiB"
filesize(1048576, { standard: "IEC" }) // "1.05 MB" (wrong unit system)
Case-normalize the value in getBaseConfiguration() before the lookup.
Unknown values keep the existing fallback behavior (pinned by the
"should fall back to JEDEC default for unknown standard" test).
Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
The standard parameter is a string by contract (the filesize entry point destructures a "" default), so a non-string is invalid input: the lookup ops right after would fail on it anyway. Normalize unconditionally and let bad input fail fast at the toLowerCase call. Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
|
Fair point — guard dropped in 13a8749. The parameter is a string by contract (the entry point destructures a |
|
Why is this a problem? JEDEC is pronounced as 'jedec' in conversation like 'laser' |
|
I'm thinking about my day to day work, where I often use acronyms and my peers also lowercase in slack, email, code, etc., e.g. i often see 'bcp47' or 'bcp-47' but rarely (almost never) do I see BCP-47. I'm targeting the audience with the original version (lower case). |
|
Thanks for the context — that makes sense: lowercase is the spelling people actually type day to day, and this change does not touch the lowercase path at all. The one problem it fixes is silent misbehavior with the spelling the API itself documents: the JSDoc advertises Happy to keep it as-is, or if you would rather document lowercase-only and reject other spellings explicitly, I can rework it that way instead. Your call — just let me know. |
|
great point about the docs - that'd always repeat over time. lets merge this. |
|
This is 11.0.32 |
|
Thank you for the review and the merge! Glad the docs reasoning landed — and thanks for shipping it in 11.0.32. Happy to contribute again anytime. |
What
The JSDoc for the
standardoption advertises"SI, IEC, JEDEC", but theSTANDARD_CONFIGSlookup is keyed on the lowercase"si"/"iec"/"jedec", so an uppercase spelling misses the lookup and silently falls through to the decimal default — the wrong unit system:Fix
Case-normalize the value in
getBaseConfiguration()before the cached lookup. Unknown values keep the existing fallback behavior, which is pinned by theshould fall back to JEDEC default for unknown standardtest, so this change only affects spellings that are case variants of the three real standards — exactly the ones the JSDoc shows. The same normalization coverspartial({ standard: "IEC" }).Verification
tests/unit/filesize.test.js(uppercaseIEC/JEDEC/SI, thepartial()path, and a guard that the unknown-value fallback is unchanged): 3 fail onmain@d2bb4c1, all pass with this change.node --test tests/unit/— 278 pass, 0 fail (273 pre-existing + 5 new).