Skip to content

Handle 🇨🇱 RUT values with ease using TypeScript.

example.ts
import { validate, format, clean } from 'rut.ts'
import { isValidRut, type Rut } from 'rut.ts'

validate('12.345.678-5')   // → true
format('123456785')        // → '12.345.678-5'
clean('12.345.678-5')      // → '123456785'

validate('11.111.111-1', { strict: true })  // → false

if (isValidRut(input)) save(input)  // input: Rut ✓

Rut.ts provides a comprehensive and battle tested set of functions for working with Chilean RUT values.

Execution time

<0.001ms

Ultra Lightweight

~1.62 KB1

License

MIT

Built lean,
battle tested;
ready for your use cases

From verifier-digit math to live input formatting — each function does one job well, so you compose only what you need.

By example

More than validate & format

Twelve composable functions across real scenarios — a branded Rut type, live-input formatting, masking, PII-safe errors, and crypto-backed generation. Tab through to see them in context.

import { validate, format, clean } from 'rut.ts'

validate('12.345.678-5')              // → true
format('123456785')                   // → '12.345.678-5'
format('123456785', { dots: false })  // → '12345678-5'
clean('12.345.678-5')                 // → '123456785'

Live demo

Paste any RUT — watch it validate

Every value below is computed live by rut.ts running in your browser. No server, no mocks — the exact functions you'd call in your own app.

isRutLike()true
validate()true
validate({ strict: true })true
clean()123456785
format()12.345.678-5
decompose().body12345678
decompose().verifier5
calculateVerifier(body)5
verifier if input is a bodynot applicable

Why a library

“Why not just use a regex?”

Most options — and a regex plus a Modulo 11 check — will validate a well-formed RUT. The difference is everything around it: strict and ReDoS-safe input handling, a branded Rut type that flows through your code, PII-safe typed errors, masking, generation, and the breadth to compose anything. Here's how the alternatives compare.

CapabilityOther librariesManual regex + Modulo 11rut.ts
Matches the RUT shapeSupportedSupportedSupported
Verifies the Modulo 11 check digitSupportedSupportedSupported
Strict mode — rejects placeholders & non-canonical inputPartial supportNot supportedSupported
Bounded input length — ReDoS-safePartial supportPartial supportSupported
Branded Rut type + type guard (isValidRut)Not supportedNot supportedSupported
Non-throwing safe mode (throwOnError: false)Partial supportNot supportedSupported
Incremental formatting for live inputsNot supportedNot supportedSupported
RUT masking for safe logging (mask)Not supportedNot supportedSupported
Typed, PII-safe errors (InvalidRutError)Not supportedNot supportedSupported
Crypto-backed valid RUT generationPartial supportNot supportedSupported
Decomposition & value-based comparison (decompose, equals)Partial supportNot supportedSupported
Actively maintained & tested (523 cases)Partial supportNot supportedSupported

rut.ts is the focused, hardened, fully-typed version of all this — twelve composable functions with safe and strict modes, a branded Rut type, and PII-safe errors, in ~1.62 KB and actively maintained.

Runs everywhere your TypeScript or JavaScript runs

Zero dependencies and pure TypeScript. Rut.ts behaves identically on Node, Deno, and Bun, at the Edge and on Vercel Functions, and inside any frontend framework — React, Next.js, Astro, or vanilla in the browser.

Node.js
Bun
React
Astro
Node.js
Bun
React
Astro
Deno
TypeScript
Next.js
Vercel
Deno
TypeScript
Next.js
Vercel

Get started in seconds

1

Install the library

Add the package with your manager of choice: npm install rut.ts — also works with bun, pnpm, and yarn.

2

Import the function(s)

Pull in only what you need: import { validate, format } from 'rut.ts'. Fully typed and tree-shakeable.

3

Use the function(s)

Call validate('12.345.678-5') to check a RUT, or format('123456785') to clean it up. Strict and safe (non-throwing) modes included.

4

Ship anywhere. Enjoy!

Zero dependencies, zero config. The same code runs on Node, Deno, Bun, the Edge, and the browser.

FAQs

  • The RUT (Rol Único Tributario) is Chile's unique identification number, used for tax purposes, legal identification, government services, and banking. It's written as XX.XXX.XXX-Y — a 7–8 digit body followed by a single verifier digit (0–9 or K). For example: 12.345.678-5.

    That final character is a check digit derived from the body using the Modulo 11 algorithm, which is what lets a RUT be validated for authenticity without contacting any registry. Computing and verifying it correctly is exactly what rut.ts handles for you.

Go deeper on rut.ts.

The blog covers the engineering behind rut.ts — how validation, formatting, and manipulation actually work, and the trade-offs behind the API.

rut.ts

MIT License © 2026 Arrow Software