Skip to content

Add z.currencyCode() over a vendored ISO 4217 list with a weekly refresh - #6595

Merged
colinhacks merged 3 commits into
mainfrom
iso-currency
Sep 12, 2026
Merged

colinhacks merged 3 commits into
mainfrom
iso-currency

Conversation

@colinhacks

Copy link
Copy Markdown
Owner

Adds z.currencyCode(), a format validator for three-letter ISO 4217 currency codes. The list is vendored rather than taken from the currency-codes npm 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 in core/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 every z.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 charging z.hostname(), z.hex() and z.httpUrl() for every regex in the module, because they reached it as core.regexes.x. They now import the module directly, and a treeshake test pins that.

Bundle, esbuild and gzipped:

  • a mini bundle that calls z.currencyCode(): +944 B over z.string() alone, of which the regex is 435 B
  • z.hostname() mini 5449 → 3390, z.httpUrl() mini 5703 → 3650, classic z.hostname() 21033 → 19136
  • bundles that use none of these: unchanged, apart from +18 B on full classic for the export itself

Runtime 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 a currency_code noun, which the parity test requires.

…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.
Copilot AI lite review requested due to automatic review settings September 12, 2026 19:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_code label to every locale and documents the new API.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using GPT Sol | 𝕏

Comment thread packages/zod/src/v4/classic/schemas.ts Resolved
Comment thread .github/workflows/iso-4217.yml Resolved
…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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_code to 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using GPT Sol | 𝕏

Comment thread .github/workflows/iso-4217.yml Resolved

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.ts no longer replace a reviewed generated commit.

Pullfrog  | View workflow run | Using GPT Sol | 𝕏

@colinhacks
colinhacks merged commit d6bc1e3 into main Sep 12, 2026
11 checks passed
@colinhacks
colinhacks deleted the iso-currency branch September 12, 2026 19:53
@colinhacks

Copy link
Copy Markdown
Owner Author

Landed in v4.6.4.

colinhacks added a commit that referenced this pull request Sep 13, 2026
colinhacks added a commit that referenced this pull request Sep 13, 2026
…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.
colinhacks added a commit that referenced this pull request Sep 13, 2026
…ist, refreshed weekly by CI (#6595)""

This reverts commit ca0229a.

z.currencyCode() shipped in 4.6.4, so reverting it would pull a published API back out. It stays in. The announcement waits for the 4.7 post.

This branch was successfully deployed

1 active deployment
Preview – zod-v4 — 67a700f2 Deployed Sep 12, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants