nif-dni-nie-cif-validation/valibot
Functions
Section titled “Functions”vCif()
Section titled “vCif()”vCif(
opts?):NifSchema
Defined in: valibot/index.ts:255
A Valibot 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”import { parse } from "valibot";
parse(vCif(), " b-1234567-4 "); // "B12345674"import { safeParse } from "valibot";
safeParse(vCif(), "G1234567D").success; // false (CIF-3)safeParse(vCif({ cifControl: "lenient" }), "G1234567D").success; // true2.0.0
vDni()
Section titled “vDni()”vDni(
opts?):NifSchema
Defined in: valibot/index.ts:211
A Valibot 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”import { parse } from "valibot";
parse(vDni(), "1234567-l"); // "01234567L"import { safeParse } from "valibot";
safeParse(vDni(), "X1234567L").success; // false: UNSUPPORTED_TYPE2.0.0
vNie()
Section titled “vNie()”vNie(
opts?):NifSchema
Defined in: valibot/index.ts:233
A Valibot 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”import { parse } from "valibot";
parse(vNie(), "x-01234567-l"); // "X1234567L"import { safeParse } from "valibot";
safeParse(vNie(), "12345678Z").success; // false: a DNI is not an NIE2.0.0
vNif()
Section titled “vNif()”vNif(
opts?):NifSchema
Defined in: valibot/index.ts:187
A Valibot 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 { object, parse } from "valibot";import { vNif } from "nif-dni-nie-cif-validation/valibot";import { es } from "nif-dni-nie-cif-validation/locales/es";
const form = object({ nif: vNif({ types: ["DNI", "NIE"], locale: es }) });parse(form, { nif: " 12.345.678-z " }); // { nif: "12345678Z" }import { safeParse } from "valibot";
const result = safeParse(vNif(), "12345678A");result.issues?.[0]?.message;// 'The control character is not correct: for this DNI it should be "Z".'(result.issues?.[0] as NifIssue).rule; // "DNI-2"2.0.0
vSpanishVat()
Section titled “vSpanishVat()”vSpanishVat(
opts?):NifSchema
Defined in: valibot/index.ts:278
A Valibot 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”import { parse } from "valibot";
parse(vSpanishVat(), "es b-1234567-4"); // "ESB12345674"import { safeParse } from "valibot";
safeParse(vSpanishVat(), "B12345674").success; // false: no ES prefix2.0.0
Interfaces
Section titled “Interfaces”NifAction
Section titled “NifAction”Defined in: valibot/index.ts:89
The transformation of the schemas: a string to its normalized form.
2.0.0
Extends
Section titled “Extends”BaseTransformation<string,string,NifIssue>
Properties
Section titled “Properties”
readonlyasync:false
Whether it’s async.
Inherited from
Section titled “Inherited from”BaseTransformation.async
readonlykind:"transformation"
The object kind.
Inherited from
Section titled “Inherited from”BaseTransformation.kind
reference
Section titled “reference”
readonlyreference: (kind,opts?) =>NifAction
Defined in: valibot/index.ts:92
The transformation reference.
The transformation itself: Valibot runs ~run on the dataset of the pipe.
It checks the string and replaces it with the normalized value, or fails
with a NifIssue.
Parameters
Section titled “Parameters”NifSchemaKind
Returns
Section titled “Returns”Overrides
Section titled “Overrides”BaseTransformation.reference
readonlytype:"nif"
Defined in: valibot/index.ts:91
The transformation type.
Overrides
Section titled “Overrides”BaseTransformation.type
NifIssue
Section titled “NifIssue”Defined in: valibot/index.ts:71
The issue of a refused value: a Valibot issue with what validate() says.
Examples
Section titled “Examples”import { safeParse } from "valibot";
const result = safeParse(vDni(), "12345678A");const issue = result.issues?.[0] as NifIssue;issue.code; // "INVALID_CONTROL_CHARACTER"issue.rule; // "DNI-2"issue.expected; // "Z"import { safeParse } from "valibot";
const issue = safeParse(vNif(), "").issues?.[0] as NifIssue;issue.code; // "EMPTY"issue.expected; // null: only a wrong control character has an expected value2.0.0
Extends
Section titled “Extends”BaseIssue<string>
Properties
Section titled “Properties”abortEarly?
Section titled “abortEarly?”
readonlyoptionalabortEarly?:boolean
Whether it should be aborted early.
Inherited from
Section titled “Inherited from”BaseIssue.abortEarly
abortPipeEarly?
Section titled “abortPipeEarly?”
readonlyoptionalabortPipeEarly?:boolean
Whether a pipe should be aborted early.
Inherited from
Section titled “Inherited from”BaseIssue.abortPipeEarly
readonlycode:NifErrorCode
Defined in: valibot/index.ts:75
The error code of validate().
expected
Section titled “expected”
readonlyexpected:string|null
Defined in: valibot/index.ts:82
The right control character, for INVALID_CONTROL_CHARACTER; null
otherwise (Valibot’s own property, which says what was expected).
Overrides
Section titled “Overrides”BaseIssue.expected
readonlyinput:string
The raw input data.
Inherited from
Section titled “Inherited from”BaseIssue.input
issues?
Section titled “issues?”
readonlyoptionalissues?: [BaseIssue<string>,...BaseIssue<string>[]]
The sub issues.
Inherited from
Section titled “Inherited from”BaseIssue.issues
readonlykind:"transformation"
Defined in: valibot/index.ts:72
The issue kind.
Overrides
Section titled “Overrides”BaseIssue.kind
readonlyoptionallang?:string
The selected language.
Inherited from
Section titled “Inherited from”BaseIssue.lang
message
Section titled “message”
readonlymessage:string
The error message.
Inherited from
Section titled “Inherited from”BaseIssue.message
readonlyoptionalpath?: [IssuePathItem,...IssuePathItem[]]
The issue path.
Inherited from
Section titled “Inherited from”BaseIssue.path
received
Section titled “received”
readonlyreceived:string
The received property.
Inherited from
Section titled “Inherited from”BaseIssue.received
requirement?
Section titled “requirement?”
readonlyoptionalrequirement?:unknown
The input requirement.
Inherited from
Section titled “Inherited from”BaseIssue.requirement
readonlyrule:string
Defined in: valibot/index.ts:77
The SPEC.md rule that failed, for example "DNI-2".
readonlytype:"nif"
Defined in: valibot/index.ts:73
The issue type.
Overrides
Section titled “Overrides”BaseIssue.type
Type Aliases
Section titled “Type Aliases”NifSchema
Section titled “NifSchema”NifSchema =
SchemaWithPipe<readonly [StringSchema<string>,NifAction]>
Defined in: valibot/index.ts:114
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 { type InferOutput, parse } from "valibot";import { type NifSchema, vNif } from "nif-dni-nie-cif-validation/valibot";
const schema: NifSchema = vNif();const output: InferOutput<NifSchema> = parse(schema, " 12.345.678-z ");output; // "12345678Z"import { type InferInput, parse } from "valibot";import { type NifSchema, vCif } from "nif-dni-nie-cif-validation/valibot";
const input: InferInput<NifSchema> = "b-1234567-4";parse(vCif(), input); // "B12345674"2.0.0
References
Section titled “References”NifSchemaOptions
Section titled “NifSchemaOptions”Re-exports NifSchemaOptions
SpanishVatSchemaOptions
Section titled “SpanishVatSchemaOptions”Re-exports SpanishVatSchemaOptions
TypedNifSchemaOptions
Section titled “TypedNifSchemaOptions”Re-exports TypedNifSchemaOptions