Registry / security / rut-validator-formatter

rut-validator-formatter

JSON →
library1.0.1jsnpmunverified

A lightweight (zero-dependency) library for validating, formatting, and cleaning Chilean RUT (Rol Único Tributario). Current stable version: 1.0.1. It provides three primary functions: validateRut (returns boolean), formatRut (adds dots and dash, uppercase K), and cleanRut (removes separators). Ships TypeScript types. Unlike alternatives, it has a simple API with no dependencies and is focused only on Chilean RUT operations.

npm install rut-validator-formatter
INSTALL
IMPORT
SIG · RUT-VALIDATOR-FORM
R
rut-validator-formatter
securityjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

validateRut
import { validateRut } from 'rut-validator-formatter'
import validateRut from 'rut-validator-formatter'
Named export, not default. ESM only.
formatRut
import { formatRut } from 'rut-validator-formatter'
const { formatRut } = require('rut-validator-formatter')
Library is ESM only; require() will fail in Node < 22 with default settings.
cleanRut
import { cleanRut } from 'rut-validator-formatter'
import { cleanRut } from 'rut-validator-formatter/src/index'
Do not import from subpaths; only the main entry is supported.
TypeScript types
import type { RutValidator } from 'rut-validator-formatter'
import { RutValidator } from 'rut-validator-formatter' (if used as value)
Types are included, but there is no exported type named 'RutValidator' in the current version. Use the function types directly.

Validates, formats, and cleans a Chilean RUT. Shows three core functions: validate (boolean), format (with dots and dash), clean (remove separators).

import { validateRut, formatRut, cleanRut } from 'rut-validator-formatter'; const rut = '111111111'; const isValid = validateRut(rut); // true console.log(isValid); const formatted = formatRut(rut); // '11.111.111-1' console.log(formatted); const cleaned = cleanRut('11.111.111-1'); // '111111111' console.log(cleaned);
Debug
Known issues
gotchaformatRut always returns the check digit (last part) as uppercase 'K' if the check digit is 'k'. Ensure your input is a valid RUT (numbers only for the first part) to avoid unexpected formatting.
fix
Use cleanRut before formatRut if the input may contain dots or dash.
affects: >=1.0.0
gotchavalidateRut expects a string of digits (with optional check digit). Passing a non-string or empty string may throw or return false unexpectedly.
fix
Always pass a string representation of the RUT, e.g., '11111111-1' or '111111111'.
affects: >=1.0.0
breakingVersion 1.0.0 introduced ESM-only exports. CommonJS require() will not work in Node.js without ESM interop flags.
fix
Use dynamic import() or switch to ESM (type: 'module' in package.json or .mjs files).
affects: >=1.0.0
deprecatedNo deprecations yet, but the API is minimal. Future versions may add parameters or options.
fix
None needed.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Using ESM import in a CommonJS context without type: 'module'
fix
Add 'type': 'module' to your package.json or rename file to .mjs.
TypeError: validateRut is not a function
Incorrect import style (default import instead of named import)
fix
Change import to: import { validateRut } from 'rut-validator-formatter'
Error: Expected string, got number
Passing a number instead of a string to any function
fix
Convert number to string: validateRut(String(rut))
Cannot find module 'rut-validator-formatter'
Package not installed or typo in package name
fix
Run: npm install rut-validator-formatter
TypeError: cleanRut is not a function (but it exists?)
Possible stale node_modules or import from wrong path
fix
Delete node_modules and package-lock.json, then reinstall.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
10
Amazon
1
Resources
rut-validator-formatter — npm install rut-validator-formatter · libregistry