nif-dni-nie-cif-validation/zod
Esta página aún no está disponible en tu idioma.
Functions
Section titled “Functions”zCif()
Section titled “zCif()”zCif(
opts?):NifSchema
Defined in: zod/index.ts:200
A Zod schema for the NIF of a legal person or entity (CIF). The control
character follows CIF-3 unless cifControl: "lenient".
Parameters
Section titled “Parameters”The options of validate() except types.
Returns
Section titled “Returns”A schema from string to the normalized string.
Examples
Section titled “Examples”zCif().parse(" b-1234567-4 "); // "B12345674"zCif().safeParse("G1234567D").success; // false (CIF-3)zCif({ cifControl: "lenient" }).safeParse("G1234567D").success; // true2.0.0
zDni()
Section titled “zDni()”zDni(
opts?):NifSchema
Defined in: zod/index.ts:164
A Zod schema for a DNI (8 digits and a letter) or a K/L/M NIF, like
isValidDni. Another valid document, such as an NIE, gives
UNSUPPORTED_TYPE. The output is the normalized value: a DNI with fewer
than 8 digits is padded with zeros (NORM-4).
Parameters
Section titled “Parameters”The options of validate() except types.
Returns
Section titled “Returns”A schema from string to the normalized string.
Examples
Section titled “Examples”zDni().parse("1234567-l"); // "01234567L"zDni().safeParse("X1234567L").success; // false: UNSUPPORTED_TYPE, a NIE is not a DNIzDni().safeParse("12345678A").success; // false: the letter should be Z (DNI-2)2.0.0
zNie()
Section titled “zNie()”zNie(
opts?):NifSchema
Defined in: zod/index.ts:182
A Zod schema for an NIE. The output is the canonical 9-character form: an old 10-character NIE is shortened (NIE-3).
Parameters
Section titled “Parameters”The options of validate() except types.
Returns
Section titled “Returns”A schema from string to the normalized string.
Examples
Section titled “Examples”zNie().parse("x-01234567-l"); // "X1234567L"zNie().safeParse("12345678Z").success; // false: a DNI is not an NIE2.0.0
zNif()
Section titled “zNif()”zNif(
opts?):NifSchema
Defined in: zod/index.ts:143
A Zod schema for any Spanish NIF: a DNI, a K/L/M NIF, an NIE or a NIF of a
legal person or entity (CIF). The output is the normalized value. Takes the
options of validate(), including types to accept only some documents
(POLICY-2) and locale for the messages.
Parameters
Section titled “Parameters”types, normalize, cifControl, rejectPlaceholders,
allowVatPrefix, locale. See NifSchemaOptions.
Returns
Section titled “Returns”A schema from string to the normalized string.
Examples
Section titled “Examples”import { z } from "zod";import { zNif } from "nif-dni-nie-cif-validation/zod";import { es } from "nif-dni-nie-cif-validation/locales/es";
const form = z.object({ nif: zNif({ types: ["DNI", "NIE"], locale: es }) });form.parse({ nif: " 12.345.678-z " }); // { nif: "12345678Z" }import { z } from "zod";
const result = zNif().safeParse("12345678A");const issue = result.error?.issues[0] as z.core.$ZodIssueCustom;issue.message;// 'The control character is not correct: for this DNI it should be "Z".'issue.params; // { code: "INVALID_CONTROL_CHARACTER", rule: "DNI-2", expected: "Z" }2.0.0
zSpanishVat()
Section titled “zSpanishVat()”zSpanishVat(
opts?):NifSchema
Defined in: zod/index.ts:219
A Zod schema for a Spanish VAT number: ES and a NIF (VAT-1). The prefix
is required, as in isValidSpanishVat, and the output keeps it: ES and
the normalized NIF. It checks the format only: a valid format doesn’t mean
the number is registered in VIES.
Parameters
Section titled “Parameters”The options of validate() except allowVatPrefix.
Returns
Section titled “Returns”A schema from string to the normalized string.
Examples
Section titled “Examples”zSpanishVat().parse("es b-1234567-4"); // "ESB12345674"zSpanishVat().safeParse("B12345674").success; // false: no ES prefix2.0.0
Interfaces
Section titled “Interfaces”NifIssueParams
Section titled “NifIssueParams”Defined in: zod/index.ts:91
The params of the issue of a refused value: what validate() says.
Examples
Section titled “Examples”import { z } from "zod";
const result = zDni().safeParse("12345678A");const issue = result.error?.issues[0] as z.core.$ZodIssueCustom;const params = issue.params as NifIssueParams;params.code; // "INVALID_CONTROL_CHARACTER"params.rule; // "DNI-2"import { z } from "zod";
const issue = zDni().safeParse("12345678A").error?.issues[0] as z.core.$ZodIssueCustom;(issue.params as NifIssueParams).expected; // "Z": the right control character2.0.0
Properties
Section titled “Properties”code:
NifErrorCode
Defined in: zod/index.ts:93
The error code of validate().
expected?
Section titled “expected?”
optionalexpected?:string
Defined in: zod/index.ts:97
The right control character, for INVALID_CONTROL_CHARACTER.
rule:
string
Defined in: zod/index.ts:95
The SPEC.md rule that failed, for example "DNI-2".
Type Aliases
Section titled “Type Aliases”NifSchema
Section titled “NifSchema”NifSchema =
ZodPipe<ZodString,ZodTransform<string,string>>
Defined in: zod/index.ts:71
The schemas of this entry point: a string, transformed to its normalized
form. Its input and its output are string.
Examples
Section titled “Examples”import { z } from "zod";
const schema: NifSchema = zNif();const output: z.output<NifSchema> = schema.parse(" 12.345.678-z ");output; // "12345678Z"import { z } from "zod";
const input: z.input<NifSchema> = "b-1234567-4";zCif().parse(input); // "B12345674"2.0.0
NifSchemaOptions
Section titled “NifSchemaOptions”NifSchemaOptions =
ValidateOptions
Defined in: adapter.ts:43
Options of the generic schema (zNif, vNif, yNif): the options of
validate().
Examples
Section titled “Examples”import { es } from "nif-dni-nie-cif-validation/locales/es";
const options: NifSchemaOptions = { types: ["DNI", "NIE"], locale: es };zNif(options).safeParse("B12345674").success; // false: a CIF is not acceptedconst options: NifSchemaOptions = { rejectPlaceholders: true, cifControl: "lenient" };zNif(options).safeParse("00000000T").success; // false: a placeholder (POLICY-1)2.0.0
SpanishVatSchemaOptions
Section titled “SpanishVatSchemaOptions”SpanishVatSchemaOptions =
Omit<ValidateOptions,"allowVatPrefix">
Defined in: adapter.ts:77
Options of the Spanish VAT schema: the options of validate() except
allowVatPrefix, which the schema always sets (the ES prefix is
required).
Examples
Section titled “Examples”import { es } from "nif-dni-nie-cif-validation/locales/es";
const options: SpanishVatSchemaOptions = { locale: es };zSpanishVat(options).parse("ES 12345678-z"); // "ES12345678Z"const options: SpanishVatSchemaOptions = { rejectPlaceholders: true };zSpanishVat(options).safeParse("ES00000000T").success; // false: a placeholder2.0.0
TypedNifSchemaOptions
Section titled “TypedNifSchemaOptions”TypedNifSchemaOptions =
Omit<ValidateOptions,"types">
Defined in: adapter.ts:60
Options of the schemas for one type (DNI, NIE, CIF): the options of
validate() except types, which the schema fixes.
Examples
Section titled “Examples”import { es } from "nif-dni-nie-cif-validation/locales/es";
const options: TypedNifSchemaOptions = { locale: es };zNie(options).safeParse("12345678Z").error?.issues[0]?.message;// "Aquí no se admite un DNI."const options: TypedNifSchemaOptions = { cifControl: "lenient" };zCif(options).safeParse("G1234567D").success; // true2.0.0