Validate chilean ruts as easy as abc. A zero dependencies, lightweight library that normalized and validates chilean ruts. Written in typescript.
Just install
with npm:
npm install validate-chilean-rut
yarn
yarn add validate-chilean-rut
or in a html environment with unpkg
<script crossorigin src="https://unpkg.com/validate-chilean-rut"><script/>
Receives either a number or string rut and returns whether it is a valid rut or not
import { validateRut } from "validate-chilean-rut";
console.log(validateRut("96.591.760-8")); // true
console.log(validateRut("96591760-8")); // true
console.log(validateRut("965917608")); // true
console.log(validateRut(965917608)); // true
console.log(validateRut("96.591.760-7")); // false
Receives either a number or string rut and returns a normalized rut (string)
import { clearRut } from "validate-chilean-rut";
console.log(clearRut("96.591.760-8")); // "965917608"
console.log(clearRut("96591760-8")); // "965917608"
console.log(clearRut(965917608)); // "965917608"
Receives rut body (everything but the "- checkDigit") either as a number or string rut and returns the check digit as string
import { getCheckDigit } from "validate-chilean-rut";
console.log(getCheckDigit("96.591.760")); // "8"
console.log(getCheckDigit(96591760)); // "8"
Receives either a number or string rut and returns a formatted rut (string) with dots and dash.
import { formatRut } from "validate-chilean-rut";
console.log(formatRut("96.591.760-8")); // "96.591.760-8"
console.log(formatRut("96591760-8")); // "96.591.760-8"
console.log(formatRut(965917608)); // "96.591.760-8"
If the rut is not valid, it will format it anyway.
Receives a normalized rut and returns the checkDigit and the inverse rut body as an string array
Receives the inverse rut body (string array) and returns the multiplication sum
Receives the multiplication sum and returns the check digit