A TypeScript package for validating and formatting Chilean RUT (Rol Único Tributario) numbers.
- Zero Dependencies - Lightweight and efficient implementation
- TypeScript Native - Full type definitions and type safety
- Comprehensive Validation - Complete validation for Chilean RUT numbers
# Using npm
npm install @bennu/cl-rut-validator
# Using yarn
yarn add @bennu/cl-rut-validator
# Using pnpm
pnpm add @bennu/cl-rut-validator
const { isValidRut, validateRut, formatRut } = require('@bennu/cl-rut-validator');
// Basic validation
console.log(isValidRut('12.345.678-5')); // true
// Detailed validation
const validation = validateRut('12.345.678-5');
console.log(validation);
/*
{
isValid: true,
formatted: '12.345.678-5',
raw: '123456785',
rutNumber: '12345678',
verificationDigit: '5'
}
*/
// Formatting
console.log(formatRut('123456785')); // '12.345.678-5'
import { isValidRut, validateRut, formatRut, RutValidationResult } from '@bennu/cl-rut-validator';
// Basic validation
console.log(isValidRut('12.345.678-5')); // true
// Detailed validation with type safety
const validation: RutValidationResult = validateRut('12.345.678-5');
console.log(validation);
/*
{
isValid: true,
formatted: '12.345.678-5',
raw: '123456785',
rutNumber: '12345678',
verificationDigit: '5'
}
*/
// Formatting
console.log(formatRut('123456785')); // '12.345.678-5'
The Chilean RUT (Rol Único Tributario) is the national tax ID number in Chile. It consists of:
- A sequence of digits (typically 7-8 digits)
- A verification digit (0-9 or 'K')
The verification digit is calculated using Module 11 algorithm to ensure validity.
This package includes several security measures:
- Protection against DoS attacks with input length limits
- Proper type handling for all inputs
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.