{
  "id": 7376382,
  "title": "validation-br 2.0: Validação em TypeScript, zero dependências",
  "url": "https://urgent.news/2026/09/14/validation-br-2-0-validacao-em-typescript-zero-dependencias",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-14T18:29:04.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/klawdyo/validation-br-20-validacao-em-typescript-zero-dependencias-h0p"
  },
  "original_language": "pt",
  "account": "The author has just released version 2.0 of the TypeScript library validation-br, which is used for validating Brazilian documents such as CPF, CNPJ, CEP, boleto, Pix, Pix Copia e Cola, Título de Eleitor, PIS/PASEP, CNH, RENAVAM, and many more. The major change in version 2.0 is that each document is now an immutable class, similar to a value object. Instead of calling a function that returns true or false, you instantiate the document and it is already validated.\n\nFor example, to create a new CPF object:\n\nimport { CPF } from \"validation-br/cpf\";\nconst cpf = new CPF(\"906.259.666-51\");\n\nThe value property will return the normalized CPF value without any formatting:\ncpf.value // \"90625966651\"\n\nThe mask() method formats the value with the traditional CPF mask:\ncpf.mask() // \"906.259.666-51\"\n\nIf an invalid value is provided, the constructor will throw an exception instead of returning false. This makes the flow more explicit: you either have a valid CPF or you handle the error. For those who prefer a quick boolean result, the shortcuts like isCPF and isCNPJ are still available and work as before.\n\nOne important point is that the package has zero dependencies in production. It only uses native JS/TS APIs, resulting in a leaner node_modules folder and a smaller attack surface for supply chain concerns.\n\nA notable addition is support for alphanumeric CNPJs, which the Receita Federal began accepting in 2026. The library can now generate fake examples for testing:\n\nimport { CNPJ } from \"validation-br/cnpj\";\n// Generates an alphanumeric CNPJ example\nCNPJ.fake({ alphanumeric: true }).mask();\n// \"WX.BC2.1FX/0001-00\"\n\nYou can create a new CNPJ instance with the masked value and access its normalized value:\nnew CNPJ(\"WX.BC2.1FX/0001-00\").value; // \"WXBC21FX000100\"\n\nThe same class handles calculating the check digit, applying formatting, removing masks, and generating valid fake values in both numeric and alphanumeric formats. For more information, visit the website at https://validation-br.js.org, check out the code on GitHub at https://github.com/klawdyo/validation-br, or install it via npm with the command: npm install validation-br.",
  "summary": "Acabei de lançar a versão 2.0 do validation-br , uma biblioteca em TypeScript para validar documentos brasileiros: CPF, CNPJ (numérico e alfanumérico), CEP, Boleto, chave Pix, Pix Copia e Cola, Título de Eleitor, PIS/PASEP, CNH, RENAVAM e mais uma dezena de outros formatos. A grande mudança da 2.0 é a forma como a validação funciona: cada documento agora é uma classe imutável, no estilo value…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}