🇨🇱 Rut.ts
Handle Chilean RUT values with ease using TypeScript.
✨
Version 3.4.0 is out! New safe mode, improved API, and better TypeScript types.
What is a RUT?
The RUT (Rol Único Tributario) is the unique Chilean identification number used for:
- Tax purposes
- Legal identification
- Government services
- Banking and financial transactions
Format: XX.XXX.XXX-Y where:
X= Body (7-8 digits)Y= Verifier digit (0-9 or K)
Example: 12.345.678-5
The verifier digit is calculated using the Modulo 11 algorithm to validate the RUT’s authenticity.
Installation
npm
npm install rut.tsQuick Example
import { validate, format, clean } from 'rut.ts'
// Validate a RUT
validate('12.345.678-5') // true
validate('12.345.678-0') // false (wrong verifier)
// Format a RUT
format('123456785') // '12.345.678-5'
// Clean a RUT
clean('12.345.678-5') // '123456785'
// Safe mode (no errors thrown)
clean('invalid', { throwOnError: false }) // nullKey Features
- ✅ Full TypeScript support with type exports
- ✅ Safe mode - Return
nullinstead of throwing errors - ✅ Incremental formatting - Format as user types
- ✅ Strict validation - Detect suspicious patterns
- ✅ Zero dependencies - Lightweight and fast
- ✅ Modulo 11 algorithm - Industry standard validation
Next Steps
Last updated on