rutcl
A set of chilean RUT utility functions for Deno
import {
clean,
format
getDigit,
isValid,
validate,
} from "https://deno.land/x/rutcl/mod.ts";
try {
validate("123456789");
} catch (error) {
console.error(error.message); // "RUT is not valid"
}
isValid("123456785"); // => true
getDigit(12345678); // => "5"
clean("12.345.678-5"); // => "123456785"
format("123456785"); // => "12.345.678-5"
Usage
Import functions from https://deno.land/x/rutcl/mod.ts
import { format, validate } from "https://deno.land/x/rutcl/mod.ts";
Or import a single function from /lib/
import clean from "https://deno.land/x/rutcl/lib/clean.ts";
Functions
isValid(dirtyRut: string | number): boolean
Returns a boolean, true
if RUT is valid, false
otherwise.
import isValid from "https://deno.land/x/rutcl/lib/isValid.ts";
isValid(123456789); // => false
isValid("18591404-6"); // => true
validate(dirtyRut: string | number): void
Throws an InvalidRUTException
if RUT is not valid.
import validate from "https://deno.land/x/rutcl/lib/validate.ts";
validate(123456789); // => Throws InvalidRUTException
validate("18591404-6"); // => undefined
getDigit(partialDirtyRut: string | number): string
Returns a valid verification digit for given partial RUT
import getDigit from "https://deno.land/x/rutcl/lib/getDigit.ts";
getDigit("18591404"); // => "6"
format(dirtyRut: string | number): string
Returns a formatted RUT
import format from "https://deno.land/x/rutcl/lib/format.ts";
format("185914046"); // => "18.591.404-6"
clean(dirtyRut: string | number): string
Returns a clean RUT, only digits.
import clean from "https://deno.land/x/rutcl/lib/clean.ts";
clean("0018*591.404*6"); // => "185914046"
CLI
TODO
Install CLI
TODO