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

12

Tests

523

Dependencies

0

Bundle size

~1.62 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

Twelve focused functions that compose into anything.

  • Validation, formatting, cleaning, decomposition, generation, verifier math
  • Branded type guard, masking, comparison, and typed errors
  • Non-throwing safe mode on every throwing function
  • Full TypeScript types across the whole API surface

Fast

Lightweight and quick by design.

  • <0.001 ms execution
  • ~1.62 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

523

Test suites

16

Pass rate

100%

Per suite

  • validate()106
  • format()69
  • clean()62
  • calculateVerifier()47
  • equals()47
  • getVerifier()41
  • getBody()29
  • decompose()21
  • generate()19
  • InvalidRutError18
  • Property-based18
  • isValidRut()15
  • Differential harness13
  • mask()13
  • Built-bundle smoke4
  • Compile-time types1

What's covered

Valid RUT shapes

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

Invalid RUT shapes

  • Wrong verifier digit
  • Leading-zero padding (rejected since 5.0.0)
  • Too short / too long
  • Invalid characters
  • K not at the end
  • Empty strings
  • Non-string inputs

Edge cases

  • Body bounds: 1.000.000 floor (7 digits) & 99.999.999 max
  • Verifier digit 0
  • Multiple K letters
  • Special characters & whitespace
  • Parentheses

Safe mode

  • throwOnError: false on the 7 throwing helpers
  • 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