Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

validate-chilean-rut

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

validate-chilean-rut

Validate chilean ruts as easy as abc. A zero dependencies, lightweight library that normalized and validates chilean ruts. Written in typescript.

latest
Source
npmnpm
Version
1.2.1
Version published
Maintainers
1
Created
Source

validate-chilean-rut

Validate chilean ruts as easy as abc. A zero dependencies, lightweight library that normalized and validates chilean ruts. Written in typescript.

validate-chilean-rut CI status Created by Garox License npm Codacy Badge installed size stars

Getting started

Just install

with npm:

npm install validate-chilean-rut

yarn

yarn add validate-chilean-rut

or in a html environment with unpkg

<script crossorigin src="https://unpkg.com/validate-chilean-rut"><script/>

Documentation

validateRut: (rut: number | string) => boolean

Receives either a number or string rut and returns whether it is a valid rut or not

import { validateRut } from "validate-chilean-rut";

console.log(validateRut("96.591.760-8")); // true
console.log(validateRut("96591760-8")); // true
console.log(validateRut("965917608")); // true
console.log(validateRut(965917608)); // true
console.log(validateRut("96.591.760-7")); // false

clearRut: (rut: number | string) => string

Receives either a number or string rut and returns a normalized rut (string)

import { clearRut } from "validate-chilean-rut";

console.log(clearRut("96.591.760-8")); // "965917608"
console.log(clearRut("96591760-8")); // "965917608"
console.log(clearRut(965917608)); // "965917608"

getCheckDigit: (rutWithoutCheckDigit: number | string) => string

Receives rut body (everything but the "- checkDigit") either as a number or string rut and returns the check digit as string

import { getCheckDigit } from "validate-chilean-rut";

console.log(getCheckDigit("96.591.760")); // "8"
console.log(getCheckDigit(96591760)); // "8"

formatRut: (rut: number | string) => string

Receives either a number or string rut and returns a formatted rut (string) with dots and dash.

import { formatRut } from "validate-chilean-rut";

console.log(formatRut("96.591.760-8")); // "96.591.760-8"
console.log(formatRut("96591760-8")); // "96.591.760-8"
console.log(formatRut(965917608)); // "96.591.760-8"

If the rut is not valid, it will format it anyway.

Internal functions (you probably won't use them)

splitRut: (cleanRut: string) => { checkDigit: string; inverseRut: string[];}

Receives a normalized rut and returns the checkDigit and the inverse rut body as an string array

getRutSum: (stringDigitArray: string[]) => number

Receives the inverse rut body (string array) and returns the multiplication sum

getCheckDigitFromSum: (sum: number) => string

Receives the multiplication sum and returns the check digit

FAQs

Package last updated on 28 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts