npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

chilean-rut-formatter

v1.0.4

Published

High-performance library for formatting and validating Chilean RUTs (Rol Único Tributario)

Readme

Chilean RUT Formatter

npm version License: MIT

High-performance TypeScript library for formatting and validating Chilean RUTs (Rol Único Tributario).

Features

  • Validate RUTs using the official Module 11 algorithm
  • Format with customizable options (dots, dashes, case)
  • Clean and sanitize user input
  • TypeScript - Full type definitions included
  • Zero dependencies - Lightweight and fast
  • Secure - Input sanitization and DoS protection
  • Tree-shakeable - ESM and CJS support

Installation

npm install chilean-rut-formatter

Usage

Validate a RUT

import { validateRut, isValidRut } from 'chilean-rut-formatter';

// Full validation with details
const result = validateRut('12.345.678-5');
// { isValid: true, rut: '123456785' }

const invalid = validateRut('12345678-0');
// { isValid: false, error: 'Invalid verification digit' }

// Simple boolean check
isValidRut('12.345.678-5'); // true
isValidRut('12345678-0');   // false

Format a RUT

import { formatRut } from 'chilean-rut-formatter';

// Default: with dots and dash
formatRut('123456785');         // '12.345.678-5'
formatRut('12345678K');         // '12.345.678-K'

// Custom options
formatRut('123456785', { dots: false });       // '12345678-5'
formatRut('123456785', { dash: false });       // '12.345.6785'
formatRut('12345678K', { uppercase: false });  // '12.345.678-k'

// Returns empty string if RUT is invalid
formatRut('12345678-0');  // ''

Format Partial Input (Real-time)

import { formatRutPartial } from 'chilean-rut-formatter';

// Great for live formatting as user types
formatRutPartial('1');         // '1'
formatRutPartial('12');        // '1-2'
formatRutPartial('12345');     // '1.234-5'
formatRutPartial('123456789'); // '12.345.678-9'

Clean a RUT

import { cleanRut } from 'chilean-rut-formatter';

cleanRut('12.345.678-9');    // '123456789'
cleanRut('12 345 678-k');    // '12345678K'
cleanRut('  12#345$678%9 '); // '123456789'

Calculate Verification Digit

import { calculateVerificationDigit } from 'chilean-rut-formatter';

calculateVerificationDigit('12345678');  // '5'
calculateVerificationDigit('16612277');  // 'K'

API Reference

validateRut(rut: string): ValidationResult

Validates a Chilean RUT and returns detailed result.

interface ValidationResult {
  isValid: boolean;
  rut?: string;    // Cleaned RUT if valid
  error?: string;  // Error message if invalid
}

isValidRut(rut: string): boolean

Simple boolean validation check.

formatRut(rut: string, options?: FormatOptions): string

Formats a valid RUT. Returns empty string if RUT is invalid.

interface FormatOptions {
  dots?: boolean;      // Include dots (default: true)
  dash?: boolean;      // Include dash (default: true)
  uppercase?: boolean; // Uppercase K (default: true)
}

formatRutPartial(rut: string, options?: FormatOptions): string

Formats partial RUT input (useful for real-time formatting).

cleanRut(input: string): string

Removes all non-valid characters from input.

calculateVerificationDigit(rutBody: string): string

Calculates the verification digit for a RUT body.

Security

  • Input Sanitization: All inputs are cleaned before processing
  • DoS Protection: Maximum input length enforced (50 chars)
  • No eval/Function: No dynamic code execution
  • TypeScript Strict Mode: Full type safety

Performance

  • Zero dependencies: No external library overhead
  • Pre-compiled regex: Patterns compiled once at module load
  • Early returns: Fast failure for invalid inputs
  • Minimal allocations: Optimized for performance

License

MIT