soff-id
v0.2.1
Published
LATAM document validation library - Validate NIT, RUT, CPF, CUIT, and more
Maintainers
Readme
Zero dependencies · TypeScript · ~1KB per locale
Table of Contents
🤔 Why?
Validating identity documents in LATAM is something every developer in the region has to implement:
| Country | Documents | Complexity | | ------------ | --------------- | ------------------------ | | 🇨🇴 Colombia | NIT, CC, CE, TI | ✅ Check digit algorithm | | 🇧🇷 Brasil | CPF, CNPJ | ✅ Two check digits | | 🇦🇷 Argentina | DNI, CUIT, CUIL | ✅ Modulus 11 | | 🇨🇱 Chile | RUT, RUN | ✅ Check digit with 'K' | | 🇲🇽 México | RFC, CURP | ✅ Complex validation |
This library provides official algorithms in a modular, tree-shakeable way. Import only what you need! 🌳
📦 Install
# npm
npm install soff-id
# pnpm
pnpm add soff-id
# yarn
yarn add soff-id
# bun
bun add soff-id🚀 Quick Start
// Only Colombia included in bundle (~1KB)
import { validateNIT, formatNIT, calculateNITCheckDigit } from 'soff-id/locales/co';
// ✅ Validate NIT
validateNIT('900123456-7'); // → true
// 🧠 Calculate check digit
calculateNITCheckDigit('900123456'); // → '7'
// 🎨 Format NIT
formatNIT('9001234567'); // → '900.123.456-7'Multi-country Usage
import { validateCPF, validateCNPJ } from 'soff-id/locales/br';
import { validateRUT } from 'soff-id/locales/cl';
import { validateCUIT } from 'soff-id/locales/ar';
import { validateRFC } from 'soff-id/locales/mx';
// Brazilian CPF
validateCPF('123.456.789-09'); // → true/false
// Chilean RUT
validateRUT('12.345.678-5'); // → true/false
// Argentine CUIT
validateCUIT('20-12345678-9'); // → true/false
// Mexican RFC
validateRFC('XAXX010101000'); // → true/falseAvailable Locales
| Locale | Import | Documents | Description |
| ------------ | -------------------- | --------------- | ----------------------------------------- |
| 🇨🇴 Colombia | soff-id/locales/co | NIT, CC, CE, TI | Tax ID, Cédula, Foreign ID, Identity Card |
| 🇧🇷 Brasil | soff-id/locales/br | CPF, CNPJ | Individual & Business Tax IDs |
| 🇦🇷 Argentina | soff-id/locales/ar | DNI, CUIT, CUIL | National ID & Tax IDs |
| 🇨🇱 Chile | soff-id/locales/cl | RUT, RUN | Tax ID & National ID |
| 🇲🇽 México | soff-id/locales/mx | RFC, CURP | Tax ID & Personal ID |
API Reference
Each locale exports a consistent set of functions for each document type:
validate{DOC}(value)
Validates if the document is valid.
import { validateNIT } from 'soff-id/locales/co';
validateNIT('900123456-7'); // → true
validateNIT('900123456-0'); // → false (wrong check digit)format{DOC}(value)
Formats the document with proper separators.
import { formatNIT } from 'soff-id/locales/co';
formatNIT('9001234567'); // → '900.123.456-7'clean{DOC}(value)
Removes all formatting from the document.
import { cleanNIT } from 'soff-id/locales/co';
cleanNIT('900.123.456-7'); // → '9001234567'calculate{DOC}CheckDigit(value)
Calculates the check digit (where applicable).
import { calculateNITCheckDigit } from 'soff-id/locales/co';
calculateNITCheckDigit('900123456'); // → '7'Bundle Size
| Import | Size (minified) |
| ------------ | --------------- |
| locales/co | ~1.1KB |
| locales/br | ~1.0KB |
| locales/ar | ~1.0KB |
| locales/cl | ~0.8KB |
| locales/mx | ~1.3KB |
| Core only | ~0.5KB |
Tree-shaking ensures you only ship what you import.
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests.
License
This project is licensed under the MIT License - see the LICENSE file for details.
