Skip to content

Features

Everything you need to trust a RUT in production.

rut.ts is a focused, hardened toolkit for Chilean RUT values — secure by default, fully typed, and fast everywhere your code runs.

Functions

9

Tests

394

Dependencies

0

Bundle size

~1.4 KB

Why rut.ts in production

Secure

Built for the path where untrusted input becomes a trusted identity.

  • Bounded input parsing — ReDoS-safe
  • Strict, canonical validation (strict rejects placeholders)
  • Generic errors — never echoes the RUT
  • Crypto-backed generate()

Complete

Nine focused functions that compose into anything.

  • Validation, formatting, cleaning, decomposition, generation, verifier math
  • Non-throwing safe mode on every throwing function
  • Full TypeScript types across the whole API surface

Fast

Lightweight and quick by design.

  • <1 ms execution
  • ~1.4 KB gzipped (full bundle)
  • Tree-shakeable ESM, no side effects
  • Optimized for frontend workloads

Multi-runtime

Runs everywhere your JS/TS runs.

  • Zero dependencies, pure TypeScript
  • Node, Deno, Bun, Edge, Vercel Functions
  • React, Next.js, Astro, or vanilla browser

Reliable by proof

Every function is exercised against valid, invalid, and adversarial input — happy paths, edge cases, and safe mode included.

Test cases

394

Test suites

12

Pass rate

100%

Per suite

  • validate()93
  • format()69
  • clean()62
  • calculateVerifier()47
  • getVerifier()41
  • getBody()29
  • decompose()21
  • generate()9
  • getInvalidRutError()9
  • Differential harness9
  • Built-bundle smoke4
  • Compile-time types1

What's covered

Valid RUT shapes

  • Formats with/without dots & hyphens
  • K verifier (upper & lower case)
  • Leading zeros
  • 8 & 9-character RUTs
  • All verifier digits 0–9 / K

Invalid RUT shapes

  • Wrong verifier digit
  • Too short / too long
  • Invalid characters
  • K not at the end
  • Empty strings
  • Non-string inputs

Edge cases

  • Min 10.000.002-4 & max 99.999.999-9
  • Verifier digit 0
  • Multiple K letters
  • Special characters & whitespace
  • Parentheses

Safe mode

  • throwOnError: false on all functions
  • Null-return validation
  • Combined options

Strict mode

  • Suspicious / placeholder rejection
  • Normal RUTs still pass
  • Strict-mode edge cases

Incremental formatting

  • Progressive formatting per length
  • Hyphen at 8+ characters
  • Leading zeros in incremental mode
  • Very long / empty inputs
rut.ts

MIT License © 2026 Arrow Software