formatToCpf function removes all non-numeric characters from a string and formats it as a CPF (Individual Taxpayer Registry) in the XXX.XXX.XXX-XX pattern.ts
import { formatToCpf } from "@arkyn/shared";
valuestringstring with the CPF (Individual Taxpayer Registry) formatted in the XXX.XXX.XXX-XX pattern.Error("Invalid CPF format"): If the input string, after removing non-numeric characters, does not have 11 digits.javascript
import { formatToCpf } from "./formatToCpf";const formattedCpf = formatToCpf("12345678909");console.log(formattedCpf); // Output: "123.456.789-09"
javascript
import { formatToCpf } from "./formatToCpf";try {formatToCpf("12345");} catch (error) {console.error(error.message); // Output: "Invalid CPF format"}