Package detail

rutility

wotanCode111MIT1.0.18

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

rutility, rut, chilean dni, chilean rut

readme

RUTility

Chilean RUT Validation and Formatting Library

Version Downloads

A library for validating and formatting the Chilean RUT (Rol Único Tributario). This library provides functions to format the RUT with dots and dashes, as well as to validate its format and check digit.

Installation

You can install the library using npm:

npm install rutility

Usage

Import in a Node.js Project

const { format, calculateDv, isValidRut, isFormat } = require('rutility');

Import in an ES6 Module

import { format, calculateDv, isValidRut, isFormat } from 'rutility';

Formatting Functions

Function Description Example
format.dot(rut: string): string Formats a RUT by adding dots. console.log(format.dot('12345678')); // '12.345.678'
format.dash(rut: string): string Formats a RUT by adding a dash. console.log(format.dash('123456780')); // '12345678-0'
format.dotDash(rut: string): string Formats a RUT by adding dots and a dash. console.log(format.dotDash('123456780')); // '12.345.678-0'
format.notDot(rut: string): string Removes dots from a RUT. console.log(format.notDot('12.345.678-0')); // '12345678-0'
format.notDash(rut: string): string Removes the dash and check digit from a RUT. console.log(format.notDash('12.345.678-0')); // '12.345.678'
format.notDotDash(rut: string): string Removes dots and the dash from a RUT. console.log(format.notDotDash('12.345.678-9')); // '12345678'

Validation Functions

Function Description Example
calculateDv(rut: string | number): string Calculates the check digit of a Chilean RUT. console.log(calculateDv('12.345.678')); // '5'
isValidRut(rut: string): boolean Validates if a Chilean RUT is valid. console.log(isValidRut('12.345.678-5')); // true

Format Validations

Function Description Example
isFormat.dot(rut: string): boolean Checks if a RUT has the correct format with dots. console.log(isFormat.dot('12.345.678')); // true
isFormat.dash(rut: string): boolean Checks if a RUT has the correct format with a dash. console.log(isFormat.dash('12345678-9')); // true
isFormat.dotDash(rut: string): boolean Checks if a RUT has the correct format with dots and a dash. console.log(isFormat.dotDash('12.345.678-9')); // true

Contributing

If you wish to contribute to this project, please open an issue or submit a pull request.

Main Developer

Contribuidores

License

This project is licensed under the MIT License.

changelog

1.0.18 Add funding

  • Add funding in package.json.
  • Update devDependencies.
  • Format changelog.md.

1.0.17 Better documentation

  • Add public-npm script in package.json.
  • Update .gitignore and npmignore.
  • Update FUNDING.yml.
  • Update README.md.

1.0.16 Fix build compilation

1.0.15 Update Repository and readme

1.0.14 Fix

1.0.13 Fix Error in .npmignore

1.0.12 Update build for global compilation

1.0.11 Add package-lock.json to .npmignore

1.0.10 Fix build for .js files

1.0.9 Updating types builds

1.0.8 Fix imports builds

1.0.7 Add prettier support

  • Adding prettier
  • Update devDependencies

1.0.6 Update tsconfig fixing d.types

  • Update tsconfig.browser.json.
  • Change name tsconfig.json to tsconfig.node.json and update it.
  • Add Keywords in package.json

1.0.5 delete types: lib in package.json

1.0.4 Fix build for browser

  • Fix build for browser.
  • Add package.json to .npmignore.

1.0.3 Add .npmignore

1.0.2 Add MIT licence

1.0.1 Update package.json for npm documentation"

1.0.0 Initial release

  • Add a new file validations.ts to contain functions for validating RUT (Rol Único Tributario):

    • calculateDv: Calculates the verification digit of a Chilean RUT (Rol Único Tributario).
    • isValidRut: Validates if a Chilean RUT (Rol Único Tributario) is valid.
    • Add isFormat object with functions to validate the format of the RUT (Rol Único Tributario):
      • isFormat.dot: Checks if a Chilean RUT has the correct format with dots and optional dash.
      • isFormat.dash: Checks if a Chilean RUT has the correct format with dash at the end.
      • isFormat.dotDash: Checks if a Chilean RUT has the correct format with dots and dash, regardless of their order.
  • Add format object with functions for RUT formatting, located within the format.ts file:

    • format.dot: Function to format a RUT by adding dots.
    • format.dash: Function to format a RUT by adding a dash.
    • format.dotDash: Function to format a RUT by adding dots and a dash.
    • format.notDot: Function to remove dots from a RUT.
    • format.notDash: Function to remove the dash from a RUT.
    • format.notDotDash: Function to remove dots and the dash from a RUT.
  • Add Utils:
    • formatValidations: Basic validations of the format of a Chilean RUT (Rol Único Tributario).
    • isValidFormatWithOutDash: Validates the format of a Chilean RUT (Rol Único Tributario).
  • Add test:
    • Validations:
      • calculateDv
      • isValidRut
      • isFormat:
        • isFormat.dot
        • isFormat.dash
        • isFormat.dotDash
    • format:
      • format.dot
      • format.dash
      • format.dotDash
      • format.notDot
      • format.notDash
      • format.notDotDash
    • Utils:
      • formatValidations
      • isValidFormatWithOutDash
  • Add config files and base files:
    • package.json
    • .gitignore
    • changelog.md
    • jest-config.js
    • tsconfig.json
    • tsconfig.browser
    • README.md
  • Add npm scripts in package.json:
    • test:unit: Runs unit tests using Jest.
    • test:coverage: Runs Jest to generate a test coverage report, collecting coverage from all TypeScript files in the src directory.
    • test:lint: Runs ESLint to automatically fix linting issues in the codebase.
    • test: Runs unit tests, generates a coverage report, and fixes linting issues by running the test:unit, test:coverage, and test:lint scripts in parallel.
    • build-browser: Compiles TypeScript code for the browser, outputting to the dist-browser directory, using ES6 modules and the es2015 and dom libraries.
    • build-node: Compiles TypeScript code for Node.js, outputting to the dist-node directory, using the es2015 library.
    • build: Runs both build-browser and build-node scripts in parallel to compile the TypeScript code for both browser and Node.js environments.
  • Add dev dependencies:
    • typescript: ^5.5.4
    • eslint: ^8.57.0
    • @eslint/js: ^9.7.0
    • typescript-eslint: ^7.17.0
    • jest: ^29.7.0
    • ts-jest: ^29.2.3
    • coverage: ^0.4.1
    • globals: ^15.8.0