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

rutify-cl

v1.1.0

Published

A modern Node.js library for formatting and validating Chilean RUT (Rol Único Tributario) numbers with comprehensive error handling and multiple output formats

Readme

Rutify

A Node.js library for formatting and validating Chilean RUT (Rol Único Tributario) numbers.

What is a Chilean RUT?

The RUT (Rol Único Tributario) is Chile's national identification number, similar to a Social Security Number in the United States. It consists of:

  • Body: 7-8 digits (the main number)
  • Check digit: 1 digit or 'K' (validation character)

The RUT is formatted as XX.XXX.XXX-X where:

  • XX.XXX.XXX is the body with dots as thousand separators
  • -X is the check digit (can be a number 0-9 or 'K')

Installation

npm install --save rutify-cl

Usage

Import the library

const rutify = require('rutify');

Format a RUT

The rutify() function takes any string containing a RUT and formats it to the standard Chilean format XX.XXX.XXX-X.

// Examples of input formats that will be formatted
const formatted1 = rutify('18927589-7');     // Returns: "18.927.589-7"
const formatted2 = rutify('18.927.589-7');   // Returns: "18.927.589-7"
const formatted3 = rutify('20901792K');      // Returns: "20.901.792-K"
const formatted4 = rutify('18927589');       // Returns: "1.892.758-9"
const formatted5 = rutify('1.892.758-9');    // Returns: "1.892.758-9"

// Invalid inputs return false
const invalid1 = rutify('');                 // Returns: false
const invalid2 = rutify('123');              // Returns: false
const invalid3 = rutify(null);               // Returns: false

Validate a RUT

The validateRut() function checks if a RUT is valid by verifying the check digit using the Chilean validation algorithm.

// Valid RUTs
console.log(validateRut('18.927.589-7'));    // true
console.log(validateRut('20.901.792-K'));    // true
console.log(validateRut('18927589-7'));      // true

// Invalid RUTs
console.log(validateRut('18.927.589-8'));    // false (wrong check digit)
console.log(validateRut('20.901.792-1'));    // false (wrong check digit)
console.log(validateRut(''));                // false

Complete Example

const rutify = require('rutify');

// Test various RUT formats
const testRuts = [
    '18927589-7',
    '18.927.589-7', 
    '20901792K',
    '18927589',
    'invalid-rut'
];

testRuts.forEach(rut => {
    const formatted = rutify.rutify(rut);
    const isValid = rutify.validateRut(rut);
    
    console.log(`Input: ${rut}`);
    console.log(`Formatted: ${formatted}`);
    console.log(`Valid: ${isValid}`);
    console.log('---');
});

Output:

Input: 18927589-7
Formatted: 18.927.589-7
Valid: true
---
Input: 18.927.589-7
Formatted: 18.927.589-7
Valid: true
---
Input: 20901792K
Formatted: 20.901.792-K
Valid: true
---
Input: 18927589
Formatted: 1.892.758-9
Valid: false
---
Input: invalid-rut
Formatted: false
Valid: false
---

API Reference

rutify(str)

Formats a RUT string to the standard Chilean format XX.XXX.XXX-X.

Parameters:

  • str (string): The RUT string to format. Can contain numbers, dots, dashes, and 'K'.

Returns:

  • string: Formatted RUT in XX.XXX.XXX-X format
  • false: If the input is invalid or too short

Examples:

rutify('18927589-7')     // "18.927.589-7"
rutify('20901792K')      // "20.901.792-K"
rutify('')               // false

validateRut(str)

Validates a RUT using the Chilean validation algorithm.

Parameters:

  • str (string): The RUT string to validate

Returns:

  • boolean: true if the RUT is valid, false otherwise

Validation Algorithm: The function uses the official Chilean RUT validation algorithm:

  1. Extracts the body (all digits except the last one)
  2. Multiplies each digit by weights (2, 3, 4, 5, 6, 7, 2, 3...)
  3. Sums all products
  4. Calculates the check digit using the formula: 11 - (sum % 11)
  5. Compares the calculated check digit with the provided one

Examples:

validateRut('18.927.589-7')    // true
validateRut('20.901.792-K')    // true
validateRut('18.927.589-8')    // false

Input Format Support

The library accepts RUTs in various formats:

  • 18927589-7 (plain with dash)
  • 18.927.589-7 (formatted)
  • 20901792K (plain with K)
  • 20.901.792-K (formatted with K)
  • 18927589 (plain without check digit - will be formatted but validation will fail)

Error Handling

  • Empty strings: Return false for formatting, false for validation
  • Invalid characters: Non-numeric characters (except 'K') are stripped
  • Too short: RUTs with less than 2 characters return false for formatting
  • Null/undefined: Return false for both functions

Contributing

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

License

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

Author

Martin Carrasco

Related

npm install --save rutify-cl