Skip to content

feat: add validateVat (#50) - #257

Merged
koblas merged 1 commit into
mainfrom
feat/validate-vat
Nov 11, 2026
Merged

koblas merged 1 commit into
mainfrom
feat/validate-vat

Conversation

@koblas

@koblas koblas commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Adds validateVat(country, value), next to validatePerson and validateEntity, with the same return shape. It looks up only euVat, which besides the EU member states includes some non-EU countries (AD, CH). A country not in euVat returns { checked: false }.

Fixes #50

Tree shaking

validateVat reads only euVat, so it doesn't pull in the stdnum, personValidators or entityValidators tables. Measured with esbuild (--bundle --minify --format=esm) on an ESM build:

Entry Before After
import { BR } from 'stdnum'; BR.cpf.validate() 7,240 B 7,240 B
import { validatePerson } from 'stdnum' 117,941 B 117,941 B
import { validateVat } from 'stdnum' n/a 39,954 B

This depends on "sideEffects": false in package.json: without it the first entry grows to about 281 KB. The README now says so.

Changes

  • src/index.ts: validateVat. It uses toUpperCase() for the country code, like the passport helpers.
  • src/index.spec.ts: 7 tests (valid DE, FR and CH VAT numbers; a bad check digit; lowercase codes; an unknown country; US, which is in entityValidators but not euVat). All values come from existing spec fixtures. All 7 fail without the function.
  • README.md: a "Validating by country code" section covering validatePerson, validateEntity and validateVat (the first two weren't documented), and a note on sideEffects.

Not verified

  • Sizes were measured with esbuild only, not webpack or Rollup.
  • npx prettier --check README.md fails because of the passport table added in feat(passport): add passport number validators #175, which was already unformatted. The new section is clean; I didn't reformat the table to keep the diff small.

Add validateVat(country, value), which looks up the euVat table only, so
bundlers can drop the stdnum, personValidators and entityValidators
tables when it is the only lookup used. Document it alongside
validatePerson and validateEntity, and note that "sideEffects": false is
what lets the root entry tree-shake.

Fixes #50
@koblas
koblas merged commit 22318d9 into main Nov 11, 2026
10 checks passed
@koblas
koblas deleted the feat/validate-vat branch November 11, 2026 15:09
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.

No validateVat method

1 participant