rut.ts
A tiny, zero-dependency TypeScript toolkit for validating, formatting, cleaning, and generating Chilean RUT/RUN values — built and hardened for production identity flows.
Version 4.0.0 is a major, breaking release. It adds production identity
hardening: bounded (ReDoS-safe) input parsing, strict format validation,
verifier checking inside format(), generic error messages, and a
crypto-backed generate(). Coming from 3.x? Read the
migration guide before upgrading.
Why rut.ts#
A regular expression can tell you a string looks like a RUT. It cannot tell you the verifier digit is correct, and a careless one is easy to make vulnerable to catastrophic backtracking. rut.ts does the real work:
Validates the actual Modulo 11 check digit — the difference between “looks like a RUT” and “is a valid RUT”.
Bounds input length before parsing, rejects non-canonical and placeholder values in strict mode, and never echoes ID values into errors or logs.
Zero runtime dependencies. ESM + CJS, fully tree-shakeable, identical on Node, Deno, Bun, the Edge, and the browser.
Comprehensive TypeScript definitions across the entire API surface, with safe (non-throwing) modes built in.
Try it now#
This runs the same Modulo 11 algorithm rut.ts ships. Type any RUT and watch every function respond live:
What is a RUT?#
The RUT (Rol Único Tributario) is Chile's unique identification number, used for taxes, legal identification, government services, and banking. For natural persons it is also called a RUN (Rol Único Nacional) — same structure, same check digit, so every function here works identically for both.
It is written as XX.XXX.XXX-Y:
X— body, 7–8 digitsY— verifier digit,0–9orK
Example: 12.345.678-5
The verifier is derived from the body with the Modulo 11 algorithm, which is what lets a RUT be checked for authenticity without contacting any registry.
Quick example#
import { validate, format, clean } from 'rut.ts'
validate('12.345.678-5') // true
validate('12.345.678-0') // false (wrong verifier)
format('123456785') // '12.345.678-5'
clean('12.345.678-5') // '123456785'
clean('invalid', { throwOnError: false }) // null (safe mode)Where to next#
Install with npm, pnpm, bun, or yarn — and verify your setup.
Quick StartValidate, format, and store a RUT end to end in five minutes.
FeaturesThe nine focused functions and how they compose.
API ReferenceSignatures, options, and types for the whole surface.
SecurityThe hardening model behind v4 and how to use it safely.
ExamplesForms, React, Zod, error handling, and real-world patterns.
License#
MIT © Arrow Software. Free for personal and commercial use, including closed-source and paid products — no usage limit, no attribution required beyond keeping the license notice.