Repository navigation
feat: add validateVat (#50) - #257
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
validateVat(country, value), next tovalidatePersonandvalidateEntity, with the same return shape. It looks up onlyeuVat, which besides the EU member states includes some non-EU countries (AD, CH). A country not ineuVatreturns{ checked: false }.Fixes #50
Tree shaking
validateVatreads onlyeuVat, so it doesn't pull in thestdnum,personValidatorsorentityValidatorstables. Measured with esbuild (--bundle --minify --format=esm) on an ESM build:import { BR } from 'stdnum'; BR.cpf.validate()import { validatePerson } from 'stdnum'import { validateVat } from 'stdnum'This depends on
"sideEffects": falseinpackage.json: without it the first entry grows to about 281 KB. The README now says so.Changes
src/index.ts:validateVat. It usestoUpperCase()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 inentityValidatorsbut noteuVat). All values come from existing spec fixtures. All 7 fail without the function.README.md: a "Validating by country code" section coveringvalidatePerson,validateEntityandvalidateVat(the first two weren't documented), and a note onsideEffects.Not verified
npx prettier --check README.mdfails 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.