Non Productive Monday

    rutlib
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.2 • Public • Published

    RUTlib

    GitHub license

    A JavaScript date library for parsing, validating, manipulating, generating and formatting RUTs (chilean identification).

    Quick Installation

    npm i rutlib

    Usage

    Clean a RUT

    Delete all non-numeric characters from a RUT.

    Function Params Return Description
    cleanRut RUT (String) String RUT without non-numeric characters
    import { cleanRut } from 'rutlib';
    
    cleanRut('1.234-3'); // 12343
    cleanRut('1234-3'); // 12343
    cleanRut('12343'); // 12343

    Validate a RUT

    Verify if a RUT is valid.

    Function Params Return Description
    validateRut RUT (String) Boolean Return true if RUT is valid, false otherwisecharacters
    import { validateRut } from 'rutlib';
    
    validateRut('1.234-3'); // true
    validateRut('1234-3'); // true
    validateRut('12343'); // true
    
    validateRut('1.234-0'); // false
    validateRut('1234-0'); // false
    validateRut('12340'); // false

    Get Verificator Digit of a number

    Get de verificator digit(VD) of a number.

    Function Params Return Description
    getLastDigitOfRut RUT without VD (Number) String Return RUT last verificator digit
    import { getLastDigitOfRut } from 'rutlib';
    
    getLastDigitOfRut(1234); // 3
    getLastDigitOfRut(1235); // 1
    getLastDigitOfRut(1236); // K

    Format RUT

    Format a RUT to a valid format.

    Function Params Return Description
    formatRut rut (String)
    withDots:True (optional) (Bolean)
    String Return RUT formatted
    import { formatRut } from 'rutlib';
    
    formatRut('1.234-3'); // 1.234-3
    formatRut('1234-3'); //  1.234-3
    formatRut('12343'); //  1.234-3
    
    formatRut('1.234-3', false); // 1234-3
    formatRut('1234-3', false); //  1234-3
    formatRut('12343', false); //  1234-3

    Get random RUT

    Generate a RUT with a random number.

    Function Params Return Description
    generateRut length:8 (optional) (Number)
    formated:True (optional) (boolean)
    String Return RUT generated
    import { generateRut } from 'rutlib';
    
    generateRut(); // 12.345.678-5 (random)
    generateRut(); // 87.654.321-4 (random)
    
    generateRut(7); // 1.234.567-4 (random)
    generateRut(7); // 7.654.321-6 (random)
    
    generateRut(9, false); // 123456789-2 (random)
    generateRut(9, false); // 987654321-1 (random)

    Version 1.0.1

    Install

    npm i rutlib

    DownloadsWeekly Downloads

    102

    Version

    1.0.2

    License

    Apache-2.0

    Unpacked Size

    70.6 kB

    Total Files

    21

    Last publish

    Collaborators

    • fvergaracl