Skip to content

Harden validator and prep for v2 release#12

Merged
lucasros98 merged 2 commits into
mainfrom
chore/v2-hardening
May 10, 2026
Merged

Harden validator and prep for v2 release#12
lucasros98 merged 2 commits into
mainfrom
chore/v2-hardening

Conversation

@lucasros98
Copy link
Copy Markdown
Contributor

@lucasros98 lucasros98 commented May 10, 2026

Summary

Stabilizing the package ahead of a more robust release. This bundles bug fixes, a real type story, modernized tooling, and a restructured test suite.

Bug fixes

  • Resolve 2-digit years against the current century rather than hardcoding + 2000 (a YY of 99 no longer becomes year 2099).
  • Tighten the Finnish HETU regex — the previous [-|U-Y] character class accidentally allowed a literal |.
  • Validate separator position for SE and DK input. '8601-013496' and similar misplaced hyphens are now rejected instead of silently stripped.
  • Reject non-digit Norwegian input early instead of relying on downstream regex.
  • Rename the misspelled teshLuhn -> testLuhn; the old name is kept as an alias for back-compat.

Types

  • Ship index.d.ts with Validator, CountryCode, and ValidatorInput.
  • Add test/types.test-d.ts and run tsc as part of npm test.

Tooling

  • Migrate ESLint to flat config (eslint.config.js); bump to ESLint 9.
  • Replace the single test workflow with a CI workflow that lints, tests on Node 18/20/22, and builds.
  • Bump dev dependencies (Babel 7.29, AVA 6, ESLint 9, TypeScript 5.9).
  • Raise engines.node to >=18.
  • Add files allowlist and prepublishOnly script to package.json so publishes only ship dist/ + index.d.ts.

Tests

  • Split the single test/test.js into per-country files plus a shared test/fixtures.js and a test/package.test.js smoke test for the public API.
  • Renamed src/dannish-ssn.js -> src/danish-ssn.js (typo fix).

Docs

  • Rewrote README.md with badges, an API table, accepted formats per country, and explicit notes on which checksums are validated (DK mod-11 was phased out in 2007 and is intentionally not checked).

Test plan

  • npm run lint clean
  • npm test — 295 tests pass, tsc passes
  • CI matrix green on Node 18/20/22
  • Verify npm pack only contains dist/ and index.d.ts

- Rename src/dannish-ssn.js -> src/danish-ssn.js (typo fix)
- Rename testLuhn (was teshLuhn); keep alias for back-compat
- Tighten Finnish SSN regex (drop spurious | inside char class)
- Resolve 2-digit years against current century instead of hardcoding 2000
- Validate separator position in SE/DK input; reject misplaced hyphens
- Reject non-digit Norwegian input early
- Add index.d.ts and tsd-style type tests; wire up tsc in test script
- Migrate ESLint config to flat config (eslint.config.js)
- Restructure tests: per-country files, shared fixtures, package smoke test
- Replace single workflow with CI matrix (lint + test on Node 18/20/22 + build)
- Bump devDependencies; raise engines.node to >=18
- Add files allowlist and prepublishOnly to package.json
- Rewrite README with API table, accepted formats, and per-country rules
Comment thread .github/workflows/ci.yml Fixed
Comment thread .github/workflows/ci.yml Fixed
Comment thread .github/workflows/ci.yml Fixed
CodeQL flagged that the workflow didn't declare a permissions block,
defaulting to the repo's broad token scope. We only need contents:read.
@lucasros98 lucasros98 merged commit 55141e7 into main May 10, 2026
8 checks passed
@lucasros98 lucasros98 deleted the chore/v2-hardening branch May 10, 2026 06:56
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