Skip to Content
🎉 Rut.ts 3.4.0 is released! Check out Safe Mode and improved API.
DocumentationAPI Reference

API Reference

Complete API documentation for all rut.ts functions.

Functions

Validation

Formatting & Cleaning

Decomposition

Generation & Calculation

Utilities

TypeScript Types

import type { DecomposedRut, FormatOptions, SafeOptions, ValidateOptions, VerifierDigit } from 'rut.ts'

DecomposedRut

type DecomposedRut = { body: string // RUT body (7-8 digits) verifier: string // Verifier digit ('0'-'9' or 'K') }

FormatOptions

type FormatOptions = { incremental?: boolean // Progressive formatting mode dots?: boolean // Include dot separators (default: true) throwOnError?: boolean // Return null on error (default: true) }

SafeOptions

type SafeOptions = { throwOnError?: boolean // Return null on error (default: true) }

ValidateOptions

type ValidateOptions = { strict?: boolean // Reject suspicious patterns (default: false) }

VerifierDigit

type VerifierDigit = | '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | 'K'

Quick Reference

FunctionInputOutputSafe ModePurpose
validate()RUT stringbooleanN/ACheck validity
format()RUT stringFormatted string✅Add formatting
clean()RUT stringClean string✅Remove formatting
decompose()RUT string{ body, verifier }✅Split RUT
getBody()RUT stringBody string✅Extract body
getVerifier()RUT stringVerifier char✅Extract verifier
calculateVerifier()Body stringVerifier char✅Calculate verifier
generate()NoneValid RUTN/AGenerate random
isRutLike()StringbooleanN/AFormat check

Common Patterns

Validation Pipeline

import { isRutLike, validate, clean } from 'rut.ts' function validateRutPipeline(input: unknown) { // Step 1: Type check if (typeof input !== 'string') return false // Step 2: Format check (fast) if (!isRutLike(input)) return false // Step 3: Full validation (slower) return validate(input) }

Safe Processing

import { clean, decompose, calculateVerifier } from 'rut.ts' function safeProcessRut(input: string) { const cleaned = clean(input, { throwOnError: false }) if (!cleaned) return null const parts = decompose(cleaned, { throwOnError: false }) if (!parts) return null return parts }

Format + Validate

import { format, validate } from 'rut.ts' function formatAndValidate(input: string) { const formatted = format(input, { throwOnError: false }) if (!formatted) return { valid: false, formatted: null } return { valid: validate(formatted), formatted } }
Last updated on