Options
All
  • Public
  • Public/Protected
  • All
Menu

@fiquu/cl-rut

Build Status GitHub GitHub last commit npm (scoped) npm

Dependency-free, Chilean RUT utils for Node.js and browsers (transpiled).

Requirements

This library has been tested with Node.js 12, 14 and NPM 6.

Installation

npm i @fiquu/cl-rut

Usage

Node.js

Import it into you projects as '@fiquu/cl-rut':

import {
  cleanParts,
  calculate,
  verifier,
  validate,
  format,
  digits,
  clean,
} from '@fiquu/cl-rut';

Examples

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);

Documentation

Please see the documentation page for more details.

description

Chilean RUT utilities for Node.js and browsers.

Index

Functions

Const calculate

  • calculate(digits: string): string
  • Calculates the RUT verifier.

    Parameters

    • digits: string

      The RUT digits to calculate the verifier from.

    Returns string

    The verifier digit or null if invalid.

    // Both return 'k'
    calculate('16992239');
    calculate('24965101');
    

Const clean

  • clean(value: string): string
  • Cleans a string out of invalid RUT characters.

    Parameters

    • value: string

      The value to clean.

    Returns string

    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');
    

Const cleanParts

  • cleanParts(value: string): string[]
  • Cleans a string out of invalid RUT characters.

    Parameters

    • value: string

      The value to clean.

    Returns string[]

    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');
    

Const digits

  • digits(value: string): string
  • Obtains the RUT digits only.

    Parameters

    • value: string

      The value to obtain the digits from.

    Returns string

    The digits or null if invalid.

    // Returns '14602789'
    digits('14.602.789-k');
    

Const format

  • format(value: string, group?: boolean): string
  • Formats a string as a RUT number.

    Parameters

    • value: string

      The value to format.

    • group: boolean = true

      Whether to use digit grouping. Defaults to true.

    Returns string

    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);
    

Const isClRut

  • isClRut(value: string): boolean
  • Checks if a value is a possible CL RUT without validating it.

    Parameters

    • value: string

      The value to check.

    Returns boolean

    Whether the value is a possible CL.

    // Returns true
    clean('723.775.052-1');
    
    // Returns true
    clean('7237750521');
    
    // Returns false
    clean('qfv23ibjfoz9');
    

Const validate

  • validate(value: string): boolean
  • Validates a string for a valid RUT number.

    Parameters

    • value: string

      The string to validate.

    Returns boolean

    Whether the string is a valid RUT number.

    // Returns true
    validate('24965101k');
    

Const verifier

  • verifier(value: string): string
  • Get the RUT verifier only.

    Parameters

    • value: string

      The value to obtain the verifier from.

    Returns string

    The verifier digit or null if invalid.

    // Returns 'k'
    verifier('14.602.789-k');
    

Legend

Generated using TypeDoc