Dependency-free, Chilean RUT utils for Node.js and browsers (transpiled).
This library has been tested with Node.js 12, 14 and NPM 6.
npm i @fiquu/cl-rut
Import it into you projects as '@fiquu/cl-rut'
:
import {
cleanParts,
calculate,
verifier,
validate,
format,
digits,
clean,
} from '@fiquu/cl-rut';
import clRut from '@fiquu/cl-rut';
const value = '22222222';
const calculated = calculate(value);
const verififer = verifier(value);
const isValid = validate(value);
const formatted = format(value);
const parts = cleanParts(value);
const digits = digits(value);
const clean = clean(value);
Please see the documentation page for more details.
Calculates the RUT verifier.
The RUT digits to calculate the verifier from.
The verifier digit or null
if invalid.
// Both return 'k'
calculate('16992239');
calculate('24965101');
Cleans a string out of invalid RUT characters.
The value to clean.
The clean string, or null
if invalid.
// Returns '7237750521'
clean('7237750521');
// Returns '7237750521'
clean('723.775.052-1');
// Returns '7237750521'
clean('723.775.052-1');
// Returns null
clean('7hf237-75lwk.052dgfdm1');
Cleans a string out of invalid RUT characters.
The value to clean.
The clean string array of parts or null
if invalid.
// Returns ['723775052', '1']
cleanParts('7237750521');
// Returns ['723775052', '1']
cleanParts('723.775.052-1');
// Returns ['723775052', '1']
cleanParts('723.775.052-1');
// Returns null
cleanParts('7hf237-75lwk.052dgfdm1');
Obtains the RUT digits only.
The value to obtain the digits from.
The digits or null
if invalid.
// Returns '14602789'
digits('14.602.789-k');
Formats a string as a RUT number.
The value to format.
Whether to use digit grouping. Defaults to true
.
The formatted string or null
if invalid.
// Returns '16.992.239-k'
format('16992239k');
// Returns '16.992.239-k'
format('16992239k', true);
// Returns '16992239-k'
format('16992239k', false);
Checks if a value is a possible CL RUT without validating it.
The value to check.
Whether the value is a possible CL.
// Returns true
clean('723.775.052-1');
// Returns true
clean('7237750521');
// Returns false
clean('qfv23ibjfoz9');
Validates a string for a valid RUT number.
The string to validate.
Whether the string is a valid RUT number.
// Returns true
validate('24965101k');
Get the RUT verifier only.
The value to obtain the verifier from.
The verifier digit or null
if invalid.
// Returns 'k'
verifier('14.602.789-k');
Generated using TypeDoc
Chilean RUT utilities for Node.js and browsers.