formatToCnpj function removes all non-numeric characters from a string and formats it as a CNPJ in the XX.XXX.XXX/XXXX-XX pattern.ts
import { formatToCnpj } from "@arkyn/shared";
valuestringXX.XXX.XXX/XXXX-XX pattern.Error("Invalid CNPJ length"): If the input string, after removing non-numeric characters, does not have 14 digits.javascript
import { formatToCnpj } from "./formatToCnpj";const formattedCnpj = formatToCnpj("12345678000195");console.log(formattedCnpj); // Output: "12,345,678/0001-95"
javascript
import { formatToCnpj } from "./formatToCnpj";try {formatToCnpj("12345");} catch (error) {console.error(error.message); // Output: "Invalid CNPJ length"}