Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
TypeScript library for validating, formatting, and generating CUITs (Argentine tax identification codes) with ease and accuracy.
@brielov/cuit
A lightweight TypeScript library for validating, formatting, and generating CUITs (Código Único de Identificación Tributaria) used in Argentina. This package helps ensure CUITs are valid and properly formatted.
Installation
deno add jsr:@brielov/cuit npx jsr add @brielov/cuit yarn dlx jsr add @brielov/cuit pnpm dlx jsr add @brielov/cuit bunx jsr add @brielov/cuit
Usage
Validate and Sanitize a CUIT
The validateCuit function checks if a given CUIT is valid and returns a
sanitized CUIT if valid, or null if invalid.
import { validateCuit } from "@brielov/cuit"; const validCuit = validateCuit("20-12345678-3"); // "20123456783" const invalidCuit = validateCuit("invalid-cuit"); // null
Format a CUIT
The formatCuit function formats a sanitized CUIT with a custom separator
(default is -).
import { formatCuit } from "@brielov/cuit"; const formattedCuit = formatCuit("20123456783", "/"); // "20/12345678/3"
Guess a CUIT from DNI
The guessCuit function attempts to guess a CUIT based on a DNI and gender. It
returns a formatted CUIT string.
import { Gender, guessCuit } from "@brielov/cuit"; const guessedCuit = guessCuit("12345678", Gender.Male); // "20-12345678-X" const guessedCuitFemale = guessCuit("12345678", Gender.Female); // "27-12345678-X"
API Reference
validateCuit(input: string): CUIT | null
- input: The CUIT string to validate.
- Returns: A sanitized CUIT string if valid, otherwise
null.
formatCuit(cuit: CUIT, separator: string = "-"): string
- cuit: The sanitized and validated CUIT string.
- separator: (Optional) Separator to use (default is
-). - Returns: The formatted CUIT string.
guessCuit(dniInput: string, gender: Gender): string
- dniInput: A DNI string to process.
- gender: The gender type (
Gender.MaleorGender.Female). - Returns: A guessed CUIT string in the format
XX-XXXXXXXX-X.
Types
CUIT
A branded type representing a valid CUIT.
type CUIT = string & { _tag: "cuit" };
Gender
An enumeration for specifying gender when guessing a CUIT.
enum Gender { Male, Female, }
License
MIT
Add Package
deno add jsr:@brielov/cuit
Import symbol
import * as cuit from "@brielov/cuit";
Import directly with a jsr specifier
import * as cuit from "jsr:@brielov/cuit";
Add Package
pnpm i jsr:@brielov/cuit
pnpm dlx jsr add @brielov/cuit
Import symbol
import * as cuit from "@brielov/cuit";
Add Package
yarn add jsr:@brielov/cuit
yarn dlx jsr add @brielov/cuit
Import symbol
import * as cuit from "@brielov/cuit";
Add Package
vlt install jsr:@brielov/cuit
Import symbol
import * as cuit from "@brielov/cuit";
Add Package
npx jsr add @brielov/cuit
Import symbol
import * as cuit from "@brielov/cuit";
Add Package
bunx jsr add @brielov/cuit
Import symbol
import * as cuit from "@brielov/cuit";