Socket
Socket
Sign inDemoInstall

zod-br-tax-id

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zod-br-tax-id

Zod Custom Objects for Brazilian Tax Ids


Version published
Weekly downloads
221
increased by151.14%
Maintainers
1
Weekly downloads
 
Created
Source

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

OptionTypeDefaultDescription
strictbooleanfalseIf true, also invalidates masked strings
messagestring'CPF/CNPJ inválido'Custom error message

Keywords

FAQs

Package last updated on 01 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc