Examples
Real-world, copy-pasteable patterns. Each page is self-contained — start with Basic Usage, then jump to whichever integration you need.
Basic Usage
The everyday patterns: validate, format, clean, decompose, type guards.
Form IntegrationReact Hook Form, Zod, Formik, Yup, Server Actions, vanilla JS.
React ExampleInputs, controlled components, hooks, and a searchable table.
Error HandlingSafe mode, graceful degradation, and localized error messages.
Three patterns you'll reuse everywhere#
Validate, then format#
TypeScript
import { validate, format } from 'rut.ts'
function processRut(input: string): string {
if (!validate(input)) throw new Error('Invalid RUT')
return format(input)
}Clean, then validate#
TypeScript
import { clean, validate } from 'rut.ts'
function normalizeAndValidate(input: string): boolean {
const cleaned = clean(input, { throwOnError: false })
return cleaned ? validate(cleaned) : false
}Decompose, then verify#
TypeScript
import { decompose, calculateVerifier } from 'rut.ts'
function verifyRut(rut: string): boolean {
const { body, verifier } = decompose(rut)
return calculateVerifier(body) === verifier
}Across every example: format() for display, validate({ strict: true })
to accept, clean() to store.