Coder Social home page Coder Social logo

jlobos / rut.js Goto Github PK

View Code? Open in Web Editor NEW
153.0 6.0 20.0 136 KB

:chile: Sencilla y pequeña librería para validar y dar formato al RUT

Home Page: https://npmjs.com/rut.js

License: MIT License

JavaScript 100.00%
rut chile node browser validar limpiar cl

rut.js's Introduction

rut.js 🇨🇱

Sencilla y pequeña libreria para validar y dar formato al RUT. Funciona en Node.js y Navegadores (Webpack, Browserify, etc.)

Utilizada en producción para manejar mas de 13 millones de chilenos en Rutify – Rutificador

// AMD
const { validate, clean, format, getCheckDigit } = require('rut.js')

// ES2015 Modules
import {  validate, clean, format, getCheckDigit } from 'rut.js'

// true
validate('18.972.631-7')
validate('18972631-7')
validate('189726317')
validate('9.068.826-k')
validate('9068826-k')
validate('9068826k')

// false
validate('18.972.631-0')
validate('18,972,631-7')
validate('18*972*631-7')
validate('18-972-631-7')
validate('error18.972.631-7')
validate('9068826-1')
validate('')
validate(189726317)
validate('0')
validate(0)

/**
 * Limpiar un RUT
 */

clean('189726317')      // '189726317'
clean('18.972.631-7')   // '189726317'
clean('12.345.678-k')   // '12345678K'
clean('12*345*678*k')   // '12345678K'
clean('000189726317')   // '189726317'

/**
 * Dar formato a un RUT
 */

format('18.972.631-7')  // '18.972.631-7'
format('189726317')     // '18.972.631-7'
format('18*972*631*7')  // '18.972.631-7'
format('9068826-k')     // '9.068.826-K'

// Dots es true por default
format('18.972.631-7', { dots: false })  // '18972631-7'
format('189726317', { dots: false })     // '18972631-7'
format('18*972*631*7', { dots: false })  // '18972631-7'
format('9068826-k', { dots: false })     // '9068826-K'

/**
 * Obtener el dígito verificador
 */
getCheckDigit('18.972.631')  // '7'
getCheckDigit('9068826')     // 'K'

Instalación

npm install --save rut.js
yarn add rut.js

Testing

npm install
npm test

rut.js's People

Contributors

azuky avatar ednjv avatar greenkeeperio-bot avatar jhonnattan123 avatar jlobos avatar juanbrujo avatar ukarus avatar yerkopalma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rut.js's Issues

Mail appears as valid

Hey! I think i've found a bug.

A strange behaviour occurs when you clean a string with numbers and then validate, code example.

const { validate, clean, format } = require('rut.js')
var mail = clean('[email protected]')
validate(mail)

when you run it it pass as a valid rut.

Thanks!

Compiler error when trying to use import with typescript

I'm currently trying to use this library doing an import like this:

import { format } from 'rut.js'

The compiler complains with the following:

Could not find a declaration file for module 'rut.js

Try `npm install @types/rut.js` if it exists or add a new declaration (.d.ts) file containing `declare module 'rut.js';`

Validacion erronea rut

Tengo un codigo que llama a la funcion validate a medida que se teclean los numeros, es decir:

1 -> validate(1)
17 -> validate(17)
173 -> validate(173)
1735 -> validate(1735)

Cuando llega al valor 17353, lo toma con un rut valido y me esta dando errores en mi pagina.

rut con 0 inicial

Hola @jlobos, gracias por compartir esta librería!

El comportamiento actual de un rut con cero inicial en la función clean es simplemente dejarlo

clean('018.972.631-7') //  '0189726317'

Es ese el comportamiento esperado?

ReDoS vulnerability

Hi! The regex patterns you use it for test RUT is vulnerable to ReDoS attack in Node.

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.