zod-br-tax-id
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

Zod Brazilian Tax Ids

npm version License: MIT

Installation

pnpm add zod-br-tax-id

npm i zod-br-tax-id

yarn add zod-br-tax-id

Usage with Zod

import { z } from "zod";
import { cpf, cnpj } from "zod-br-tax-id";

const schema = z.object({
  cpf: cpf(),
  cnpj: cnpj({ strict: true, message: "Invalid CNPJ, only number are allowed" }),
  optionalCpf: z.union([z.literal(""), cpf()]),
  undefinedCnpj: z.union([z.undefined(), cnpj()]),
});

try {
  schema.parse({
    cpf: "123.456.789-00",
    cnpj: "12.345.678/0001-00",
    optionalCpf: "",
    undefinedCnpj: undefined,
  });
} catch (err) {
  if (err instanceof z.ZodError) {
    console.log(err.issues);
  }
}

Options

Option Type Default Description
strict boolean false If true, also invalidates masked strings
message string 'CPF/CNPJ inválido' Custom error message

Package Sidebar

Install

npm i zod-br-tax-id

Weekly Downloads

2

Version

1.0.5

License

MIT

Unpacked Size

12.9 kB

Total Files

8

Last publish

Collaborators

  • abensur