API reference
The reference is generated from the JSDoc of the library’s source each time the site is built, so it always matches the code. It has one page per entry point of the package, with every export: its signature, what each parameter and the return value mean, two examples that the library’s tests run, the SPEC rule it follows, and the version that added it.
| Entry point | What it exports |
|---|---|
nif-dni-nie-cif-validation | The validators, validate(), normalize(), format(), getNifType(), computeControlCharacter(), describeCifOrganisation(), the v1 constants and the types. English messages are built in. |
nif-dni-nie-cif-validation/locales/en | The English locale object, to pass as locale to validate(), describeCifOrganisation() and the schemas. |
nif-dni-nie-cif-validation/locales/es | The Spanish locale object, to pass as locale to validate(), describeCifOrganisation() and the schemas. |
nif-dni-nie-cif-validation/locales/ca | The Catalan (also for Valencian) locale object, to pass as locale to validate(), describeCifOrganisation() and the schemas. |
nif-dni-nie-cif-validation/locales/eu | The Basque locale object, to pass as locale to validate(), describeCifOrganisation() and the schemas. |
nif-dni-nie-cif-validation/locales/gl | The Galician locale object, to pass as locale to validate(), describeCifOrganisation() and the schemas. |
nif-dni-nie-cif-validation/generate | Seeded generators of valid and invalid numbers, for tests. Never imported by the main entry point. |
nif-dni-nie-cif-validation/zod | Zod 4 schemas for every type and for VAT numbers. Zod is an optional peer dependency. |
nif-dni-nie-cif-validation/valibot | Valibot 1 schemas for every type and for VAT numbers. Valibot is an optional peer dependency. |
nif-dni-nie-cif-validation/yup | Yup 1 schemas for every type and for VAT numbers. Yup is an optional peer dependency. |
Your editor shows the same documentation as you type, from the type declarations that the package ships.
Reading the reference
Section titled “Reading the reference”- Options. The validators take
IsValidOptions,validate()takesValidateOptions, and the schemas take the options ofvalidate(). Each option’s default and effect are listed on the main entry point’s page. - Rules. The links to rule IDs, such as
DNI-2, open the official sources page. - Aliases.
isValidCifandisValidLegalEntityNifare the same function, as areisValidCifControlCodeandisValidLegalEntityNifControlCode;CIF_REGEXandLEGAL_ENTITY_NIF_REGEX, andCIF_CONTROL_LETTERSandLEGAL_ENTITY_CONTROL_LETTERS, are the same constants. - Deprecated.
replaceNieLetteris kept for version 1 code. It throws on bad input, unlike the validators and the other helpers (the generators also throw aRangeError, when their options are impossible).
For a task-oriented introduction, start with Getting started. The decisions behind the API are in docs/api-design.md.