Repository navigation
feat(en): add toCurrencyIn, so a bundle that names one currency ships one - #461
Open
TylerVigario wants to merge 2 commits into
Open
TylerVigario wants to merge 2 commits into
TylerVigario wants to merge 2 commits into
Conversation
… one toCurrency looks its currency up by code, which keeps every English currency in any bundle that uses it. toCurrencyIn takes the currency as an object imported from n2words/en/currencies, so a bundler drops the rest: en-US with GBP bundles to 3,992 B minified, against 5,169 B for toCurrency. Both share one builder and give the same output. The dist bundles leave toCurrencyIn out, since a CDN page has no way yet to import one currency. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NfrA9rAkb8oHNcNHDaPVC4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NfrA9rAkb8oHNcNHDaPVC4
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
toCurrencyInto the English entry points, the shape from my comment on #437.Size
en-US with
GBP, bundled with rollup 4.64.9 (4.63.1 gives the same bytes) and theindividualTerserConfigoptions fromrollup.config.js. Bytes, gzip in parentheses:toCurrencytoCurrencyIn+GBPtoCurrencykeeps every English currency however it's called.toCurrencyInis smallest when the bundler sees every call and none passes options, because Rollup then drops the options handling. A second currency adds 74 B (exported withUSDandGBP: 4,522 B). v6.3.0'stoCurrencyis 32 B smaller than this branch's in every row.Corrections to the first version of this table and to my #437 comment. Both set
toCurrencyIncalled with no options againsttoCurrencyexported, which overstated the saving. Like for like, it saves 759 B with arguments unknown and 1,234 B with no options. The ~4,069 B target in #437 is met only in the no-options case. Both tables also counted characters rather than bytes, a few fewer.The check on the currency object costs 323 B, or 443 B with no options. The 3,513 B in my #437 comment had no check. Without one, a hand-built object with an empty word list returns malformed output, which the conversion contract rules out.
How
currency-vocab.jsgives each English currency its ownEN_<CODE>binding and builds theenmap from them.src/en/currencies.jsre-exports each with itscodeadded, so the words still live in one place. The map itself stays without codes:toCurrencyalready has the code it was passed, and a code per entry madedist/en-US/currency.js344 B larger instead of 32 B.toCurrencyinto a shared builder, whichtoCurrencyandtoCurrencyInboth call. The 13 profiles andenforwardtoCurrencyInthroughexport *.assertCurrencyVocabthrowsTypeErrorfor a malformed currency object, asresolveOptionsdoes for malformed options.dist/leavestoCurrencyInout (rollup.config.js). A CDN page can't import one currency yet, becausesrc/en/currencies.jspulls in the whole matrix. Every non-English file indist/is byte-identical to v6.3.0. Every English full, UMD and currency bundle is 31-32 B larger, from the call into the shared builder.Tests
test/currency-in.test.js:toCurrencyInmatchestoCurrency, errors included, for all 18 English entry points × 24 currencies ×andunset/true/false × 15 amounts, the range ceiling among them.TypeError, and options are validated astoCurrency's are.KESleaves "shilling" as the only one of the 14 English major nouns. AtoCurrencybundle, as the control, keeps all 14.I checked that the gate fails when the object path reads the map again, when
andis ignored, and when the guard is removed.npm testis 877 passing, lint is clean, and LANGUAGES.md regenerates unchanged.Not in this PR
dist/would need a file per currency.toCurrencyInwas a placeholder.Refs #437
🤖 Generated with Claude Code
https://claude.ai/code/session_01NfrA9rAkb8oHNcNHDaPVC4