chilerut
Version:
Una librería con diversas utilidades para el RUN/RUT chileno.
62 lines (60 loc) • 2.86 kB
TypeScript
/**
* The **sanitiseRut()** returns a sanitised RUT string, which leaves only numbers and the char “K/k”.
* @param rut A RUT string.
* @returns A new string of numbers and the char "K/k" if applicable.
*/
declare function sanitiseRut(rut: string): string;
/**
* The **fullySanitiseRut()** returns a sanitised RUT string, which leaves only numbers.
* @param rut A RUT string.
* @returns A new string of numbers.
*/
declare function fullySanitiseRut(rut: string): string;
/**
* The **getCheckDigit()** returns a check digit. A string char calculated on a [modulo 11 based algorithm](https://es.wikipedia.org/wiki/Rol_%C3%9Anico_Tributario#Algoritmo)
* @param rut A RUT string without the check digit, i.s., the last char.
* @returns A valid check digit.
*/
declare function getCheckDigit(rut: string): string;
/**
* The **validateRut()** returns a boolean value based on the rut provided.
*
* It verifies the pattern and its check digit. If it's valid, it returns **true** and if it's not, it returns **false**.
* @param rut The RUT string.
* @returns A boolean value according to the validity of the rut string.
*/
declare function validateRut(rut: string): boolean;
/**
* Object parameter type for **generateMulRun()** options.
*/
interface GenerateMulRutOpts {
count?: number;
dots?: boolean;
hyphen?: boolean;
}
declare type GenerateRutOpts = Omit<GenerateMulRutOpts, "count">;
/**
* The **generateRut()** returns a random, valid RUT.
*
* It takes an optional object, which determines if the string is returned with a thousand separators and/or a hyphen. By default, these options are **true**.
* @param opts An object with predetermined formatting options.
* @returns A random, valid generated RUT.
*/
declare function generateRut(opts?: GenerateRutOpts): string;
/**
* The **generateMulRut()** returns an array of random, valid RUT strings.
*
* It takes an optional object, which determines the number of RUTs to generate, and if they are returned with a thousand separators and/or a hyphen. By default, the amount of RUTs to create is **30**, and the formatting options are **true**.
* @param opts An object with predetermined formatting options.
* @returns An array of strings, which are random, valid generated RUTs.
*/
declare function generateMulRut(opts?: GenerateMulRutOpts): string[];
/**
* The **formatRut()** returns a formatted RUT string.
*
* A RUT with **dots** as a thousand separator and a **hyphen** between the correlative number and the check digit.
* @param rut A RUT string to format.
* @returns A new formatted RUT string.
*/
declare function formatRut(rut: string): string;
export { GenerateMulRutOpts, GenerateRutOpts, formatRut, fullySanitiseRut, generateMulRut, generateRut, getCheckDigit, sanitiseRut, validateRut };