Skip to content

bennu/cl-rut-validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CL RUT Validator

A TypeScript package for validating and formatting Chilean RUT (Rol Único Tributario) numbers.

Version TypeScript Downloads Bundle Size Test Coverage License

📋 Features

  • Zero Dependencies - Lightweight and efficient implementation
  • TypeScript Native - Full type definitions and type safety
  • Comprehensive Validation - Complete validation for Chilean RUT numbers

🚀 Installation

# Using npm
npm install @bennu/cl-rut-validator

# Using yarn
yarn add @bennu/cl-rut-validator

# Using pnpm
pnpm add @bennu/cl-rut-validator

💻 Usage

JavaScript (CommonJS)

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'

TypeScript / ES Modules

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'

🔍 Understanding Chilean RUT

The Chilean RUT (Rol Único Tributario) is the national tax ID number in Chile. It consists of:

  1. A sequence of digits (typically 7-8 digits)
  2. A verification digit (0-9 or 'K')

The verification digit is calculated using Module 11 algorithm to ensure validity.

🔒 Security Features

This package includes several security measures:

  • Protection against DoS attacks with input length limits
  • Proper type handling for all inputs

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •