Repository navigation
Add z.currencyCode() over a vendored ISO 4217 list with a weekly refresh - #6595
Conversation
…eekly by CI The list is the SIX Group's list one, regenerated into core/regexes.ts by scripts/update-iso-4217.ts. A weekly workflow reruns it and opens a PR whenever the active codes change. The custom formats now read core/regexes.ts through a direct namespace import. Reaching it as core.regexes.x made esbuild materialize every regex in the module, which cost a z.hostname() or z.httpUrl() bundle about 2 KB gzipped and would have charged them the code list too.
There was a problem hiding this comment.
Important
The validator and generated list are sound, but the exported string-format union is incomplete and the refresh job can repeatedly replace an already-reviewed generated PR head.
Reviewed changes Reviewed the new Classic and Mini currency validator, generated ISO 4217 data path, JSON Schema behavior, locale coverage, tree-shaking changes, documentation, and weekly refresh automation.
- Currency validator Adds
currencyCode()backed by SIX Group's current 178-code list with runtime, Mini, and JSON Schema coverage. - Generated refresh Adds a deterministic update script and a scheduled workflow that tests and opens or updates a generated PR.
- Bundle isolation Uses direct regex-module imports and adds an esbuild regression test so unrelated format regexes shake out.
- Localized errors and docs Adds the
currency_codelabel to every locale and documents the new API.
GPT Sol | 𝕏
…sh job off an open generated PR The weekly job now leaves the iso-4217 branch alone when the open generated PR already carries the regenerated list, and runs one at a time.
There was a problem hiding this comment.
Important
The new no-op guard still compares the entire source file, so unrelated edits can unnecessarily replace a reviewed generated PR head.
Reviewed changes Reviewed the follow-up commit that completed the string-format type surface and added serialization and open-PR handling to the refresh workflow.
- String-format typing Added
currency_codeto the exported string-format union and pinned the assignability. - Refresh automation Serialized refresh runs and added an open generated-PR comparison before pushing the shared branch.
GPT Sol | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes Reviewed the workflow idempotency fix added since the prior Pullfrog review.
- Generated-list comparison Exported the generated code list from the updater and compared it with the open PR head, so unrelated edits to
regexes.tsno longer replace a reviewed generated commit.
GPT Sol | 𝕏
|
Landed in v4.6.4. |
…eekly by CI (#6595) The list is SIX Group's list one, regenerated into core/regexes.ts by scripts/update-iso-4217.ts. A weekly workflow reruns it and opens a PR whenever the active codes change, and leaves an open generated PR alone while it still carries the same list. The custom formats now read core/regexes.ts through a direct namespace import. Reaching it as core.regexes.x made esbuild materialize every regex in the module, about 2 KB gzipped on a z.hostname() or z.httpUrl() bundle.

Adds
z.currencyCode(), a format validator for three-letter ISO 4217 currency codes. The list is vendored rather than taken from thecurrency-codesnpm package: that package still ships the June 2024 list and its maintainer has been silent since, so it has no XCG or XAD and still treats BGN as active.The source is SIX Group's list one, the XML the ISO maintenance agency publishes. A script (
nub run update:iso4217) fetches it and rewrites the regex incore/regexes.ts, and a weekly workflow reruns the script and opens a PR whenever the active codes change, naming the added and removed codes. The workflow opens that PR with the default token, which never triggers the test workflow, so it runs the tests that read the list before it pushes.Placement is top-level on purpose. Under esbuild a member of a nested namespace is paid for by everyone who touches that namespace, so
z.iso.currency()would have cost everyz.iso.date()user the whole list, while a top-level export is free for anyone who does not call it. The same mechanism was already chargingz.hostname(),z.hex()andz.httpUrl()for every regex in the module, because they reached it ascore.regexes.x. They now import the module directly, and a treeshake test pins that.Bundle, esbuild and gzipped:
z.currencyCode(): +944 B overz.string()alone, of which the regex is 435 Bz.hostname()mini 5449 → 3390,z.httpUrl()mini 5703 → 3650, classicz.hostname()21033 → 19136Runtime is a 178-way anchored alternation, about 20 ns per test, under the E.164 regex. Memory matches
z.hostname()at 1420 retained bytes per schema. Every locale gets acurrency_codenoun, which the parity test requires.