Skip to content

Features

rut.ts is deliberately a focused toolkit: nine small functions that each do one job well, so you compose only what you need. Every throwing function also has a non-throwing safe mode ({ throwOnError: false }).

The nine functions#

How they group#

Validation#

  • validate() — the acceptance gate (shape + verifier, optional strict mode)
  • isRutLike() — cheap pre-filter, no verifier math

Formatting & cleaning#

  • format() — canonical display shape, with incremental typing mode
  • clean() — strip formatting and leading zeros down to digits

Decomposition#

Generation & math#

Shared behavior#

All functions:

  • Are fully typed — complete TypeScript definitions
  • Bound input length before parsing (ReDoS-safe)
  • Emit generic errors — never echo the offending value
  • Accept multiple shapes — dots, hyphens, or plain digits
  • Handle leading zeros — normalized away automatically

clean(), decompose(), getBody(), and getVerifier() normalize shape but do not check the verifier digit. Gate acceptance with validate().

See it run#

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