UNPKG

rutility

Version:

A JavaScript library for validating and formatting Chilean RUTs (Rol Único Tributario). It provides functions to add/remove dots and dashes, validate formats, and calculate check digits

44 lines 2 kB
/** * Calculates the verification digit of a Chilean RUT (Rol Único Tributario). * @param {string | number} rut - The RUT in one of the following formats: * - '12.345.678' * - '12345678' * - 12345678 (as a number) * @returns {string} The calculated verification digit or '0' if it's 11, 'K' if it's 10. * @throws {Error} If the RUT format is invalid. Acceptable formats are '26270086' or '26.270.086'. * @example * calculateDv('12.345.678'); // returns '5' * calculateDv('12345678'); // returns '5' * calculateDv(12345678); // returns '5' */ export declare const calculateDv: (rut: string | number) => string; /** * Validates if a Chilean RUT (Rol Único Tributario) is valid. * @param {string} rut - The RUT in one of the following formats: * - '12.345.678-9' * - '12345678-9' * @returns {boolean} true if the RUT is valid, false otherwise. * @throws {Error} If the RUT format is invalid. */ export declare const isValidRut: (rut: string) => boolean; export declare const isFormat: { /** * Checks if a Chilean RUT has the correct format with dots and optional dash. * @param {string} rut - The RUT to be checked. Example: "12.345.678-9". * @returns {boolean} true if the RUT has the correct format, false otherwise. Example: true. */ dot: (rut: string) => boolean; /** * Checks if a Chilean RUT has the correct format with dash at the end. * @param {string} rut - The RUT to be checked. Example: "12.345.678-9". * @returns {boolean} true if the RUT has the correct format, false otherwise. Example: true. */ dash: (rut: string) => boolean; /** * Checks if a Chilean RUT has the correct format with dots and dash, regardless of their order. * @param {string} rut - The RUT to be checked. Example: "12.345.678-9". * @returns {boolean} true if the RUT has the correct format, false otherwise. Example: true. */ dotDash: (rut: string) => boolean; }; //# sourceMappingURL=validations.d.ts.map