LATAM document validation library - Validate NIT, RUT, CPF, CUIT, and more
npm install soff-id
LATAM document validation library - Validate NIT, RUT, CPF, CUIT, and more.






---
Zero dependencies Β· TypeScript Β· ~1KB per locale
- Table of Contents
- Why?
- Install
- Quick Start
- Multi-country Usage
- Available Locales
- API Reference
- validate{DOC}(value)
- format{DOC}(value)
- clean{DOC}(value)
- calculate{DOC}CheckDigit(value)
- Bundle Size
- Contributing
- License
- Documentation
- Contributors
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! π³
``bashnpm
npm install soff-id
π Quick Start
`typescript
// 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'
`$3
`typescript
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/false
`Available 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:
$3
Validates if the document is valid.
`typescript
import { validateNIT } from 'soff-id/locales/co';validateNIT('900123456-7'); // β true
validateNIT('900123456-0'); // β false (wrong check digit)
`$3
Formats the document with proper separators.
`typescript
import { formatNIT } from 'soff-id/locales/co';formatNIT('9001234567'); // β '900.123.456-7'
`$3
Removes all formatting from the document.
`typescript
import { cleanNIT } from 'soff-id/locales/co';cleanNIT('900.123.456-7'); // β '9001234567'
`$3
Calculates the check digit (where applicable).
`typescript
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 |Tree-shaking ensures you only ship what you import.
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
This project is licensed under the MIT License - see the LICENSE file for details.
- EspaΓ±ol
Thanks goes to these wonderful people (emoji key):
Luis C. Rojas π» π π§ |
This project follows the all-contributors specification. Contributions of any kind welcome!