Thanks for your interest in improving nationid. This document explains how to add countries, fix algorithms, and propose changes.
Requires Node 20+ and pnpm 9+.
git clone https://github.com/lu1tr0n/nationid.git
cd nationid
pnpm install
pnpm verify # runs lint, typecheck, test, build, dist testsUseful scripts:
| Command | Purpose |
|---|---|
pnpm test |
Run unit tests |
pnpm test:watch |
Watch mode |
pnpm typecheck |
TS strict checks |
pnpm lint |
Biome lint + format check |
pnpm lint:fix |
Auto-fix issues |
pnpm build |
Build dist with tsup |
pnpm test:dist |
Run tests against built output |
pnpm size |
Verify bundle budgets |
pnpm changeset |
Add a changeset for your PR |
src/
core/ # types, normalize helpers (do not edit lightly)
algorithms/ # shared math primitives (Luhn, mod-11, etc.)
countries/<cc>/ # per-country folders — most contributions go here
index.ts # root API + REGISTRY
tests/
countries/<cc>.test.ts # one test file per country
algorithms/ # algorithm primitive tests
dist/ # tests against built output (do not skip these)
docs/
countries/<cc>.md # per-country reference, sources, examples
- Read
docs/countries/_template.mdand createdocs/countries/<cc>.mdfirst — citing every official source you used. - Create
src/countries/<cc>/<doc>.tsfor each document type, exporting oneDocumentSpecper file. - Create
src/countries/<cc>/index.tsthat exportsvalidate,format,normalize,parse, the country bundle, and individual specs. - Extend
src/core/types.ts: add the country code toCountryCodeand document codes toDocumentTypeCode. - Update
src/index.ts: import the bundle and add its specs to the registry. - Update
package.jsonexports map andtsup.config.tscountry list. - Write
tests/countries/<cc>.test.tswith at least 5 valid + 5 invalid + 3 edge case vectors per document. - Run
pnpm verifyand ensure everything passes. - Add a changeset:
pnpm changesetand chooseminorfor a new country. - Open a PR using the country-add template.
- Open an issue first using the
algorithm_correctiontemplate — include the official source that proves the current implementation is wrong. - Add new test vectors that fail under the current implementation and pass under the correct one.
- Fix the implementation.
- Verify all existing vectors still pass.
- Add a changeset of
patchseverity.
- Add a regression test that reproduces the bug.
- Fix the bug.
- Add a changeset of
patchseverity.
Every PR must:
- Pass
pnpm verifylocally - Stay within the bundle size budget defined in
package.json#size-limit - Cite official sources for any algorithm change
- Use synthetic test vectors only — never commit real document numbers, even your own or your company's
- Include a changeset describing the change in plain language
We follow Conventional Commits 1.0.0. Common prefixes:
| Prefix | When to use |
|---|---|
feat: |
New country, new document, new public API |
fix: |
Algorithm correction, type fix, bug fix |
docs: |
README, country docs, comments |
test: |
Test additions / improvements |
refactor: |
Internal restructure with no behavior change |
perf: |
Performance improvement |
chore: |
Dependencies, tooling, CI |
Breaking changes get a ! after the type: feat!: rename DocumentSpec.code to id.
By contributing you agree that your contributions are licensed under the MIT License.
Contributors are credited in CHANGELOG.md under each release. Significant ongoing contributors may be invited as maintainers.