npm.io
2.0.0 • Published 7 months ago

cuit

Licence
MIT
Version
2.0.0
Deps
0
Size
13 kB
Vulns
0
Weekly
0
Stars
3

cuit

npm version npm downloads CI License: MIT

Lightweight utilities for validating, formatting, and generating Argentine CUIT/CUIL numbers.

What is a CUIT?

CUIT (Clave Única de Identificación Tributaria) is Argentina's tax identification number. It's an 11-digit number with the format XX-XXXXXXXX-X:

  • First 2 digits: Type prefix (20/23/24 = male, 27 = female, 30/33/34 = company)
  • Middle 8 digits: DNI (national ID) or company registration number
  • Last digit: Check digit (mod 11 algorithm)

Installation

npm install cuit
pnpm add cuit
bun add cuit

Usage

import { isValid, generate, format, normalize } from "cuit";

// Validate a CUIT
isValid("20-12345678-6"); // true
isValid("20-12345678-0"); // false (wrong check digit)
isValid("20123456786");   // true (works without separators)

// Generate a CUIT from a DNI
generate("12345678", "M"); // "20123456786" (male)
generate("12345678", "F"); // "27123456781" (female)
generate("12345678", "E"); // "30123456786" (entity/company)

// Format a CUIT
format("20123456786");      // "20-12345678-6"
format("20123456786", "/"); // "20/12345678/6"
format("20123456786", "");  // "20123456786"

// Normalize (remove separators)
normalize("20-12345678-6"); // "20123456786"

API

isValid(input: string): boolean

Validates whether a CUIT is valid using the mod 11 algorithm.

isValid("20-12345678-6"); // true
isValid("invalid");       // false
isValid("20123456780");   // false (wrong check digit)
generate(dni: string, type: EntityType): string

Generates a valid CUIT from a DNI and entity type.

  • dni - The DNI number (8 digits, can include separators)
  • type - "M" (male), "F" (female), or "E" (entity/company)
generate("12345678", "M"); // "20123456786"
generate("12.345.678", "F"); // "27123456781" (separators are stripped)
generate("1234567", "M"); // "20012345672" (short DNIs are padded)
format(input: string, separator?: string): string

Formats a CUIT with the specified separator (default: "-").

format("20123456786");      // "20-12345678-6"
format("20123456786", "/"); // "20/12345678/6"
format("20123456786", " "); // "20 12345678 6"
format("20123456786", "");  // "20123456786"
normalize(input: string): string

Removes all non-digit characters from the input.

normalize("20-12345678-6"); // "20123456786"
normalize("20.12345678.6"); // "20123456786"
getPrefix(input: string): string

Extracts the 2-digit prefix from a CUIT.

getPrefix("20-12345678-6"); // "20"
getDni(input: string): string

Extracts the 8-digit DNI from a CUIT.

getDni("20-12345678-6"); // "12345678"
getCheckDigit(input: string): string

Extracts the check digit from a CUIT.

getCheckDigit("20-12345678-6"); // "6"
getEntityType(input: string): EntityType | null

Determines the entity type from a CUIT prefix.

getEntityType("20-12345678-6"); // "M" (male)
getEntityType("27-12345678-1"); // "F" (female)
getEntityType("30-12345678-6"); // "E" (entity)
getEntityType("99-12345678-0"); // null (unknown prefix)

Types

type EntityType = "M" | "F" | "E";
type CuitPrefix = "20" | "23" | "27" | "30";

Features

  • Zero dependencies
  • Full TypeScript support
  • Works in Node.js, browsers, and edge runtimes
  • ESM and CommonJS support
  • Tree-shakeable
  • Tiny bundle size (~800 bytes gzipped)

License

MIT

Keywords