pp-rut
v1.0.3
Published
Validate the Chilean R.U.T. and its verification digit
Maintainers
Readme
pp-rut
For more information Wikipedia Link
Try online
Getting Started
In the web project include pp-rut with:
<!--no dependencies used nd file-->
<script src="https://cdn.jsdelivr.net/npm/pp-rut/dist/pp-rut.nd.min.js" ></script>Or
<script src="https://cdn.jsdelivr.net/npm/pp-is/dist/pp-is.min.js" ></script>
<script src="https://cdn.jsdelivr.net/npm/pp-rut/dist/pp-rut.min.js" ></script>Or
Install
npm i pp-rut --saveHow to use ?
formats that work:
ppRut(30686957) //work
ppRut(30686957,"4") //work
ppRut("30686957","") //work
ppRut("30.686.957") //work
ppRut("30.686.957 4") //work
ppRut("30.686.957-4") //work
ppRut("30 686 957 4") //work
ppRut("30.686 957 5","4") //In this case, number 4 takes priority over number 5.
ppRut("*****30.....686.****957 5","4") //Other very unlikely formats to workconst rut = ppRut(30918041,11)
console.log( rut.checkDigit("0") ) // true
console.log( rut.format() )// 30.918.041-0const rut = ppRut(30918050,10)
console.log( rut.checkDigit("k") ) //true
console.log( rut.format() ) // 30.918.050-kconst rut = ppRut("30686957")
console.log( rut.checkDigit("4") ) //true
console.log( rut.format() ) // 30.686.957-4const rut = ppRut("30686957")
console.log( rut.checkDigit("4") ) //true
console.log( rut.format() ) // 30.686.957-4const rut = ppRut("30686957 5")
console.log( rut.checkDigit() ) //false
console.log( rut.format() ) // 30.686.957-4const rut = ppRut("30686957 4")
console.log( rut.checkDigit("5") ) //false
console.log( rut.format() ) // 30.686.957-4const rut = ppRut("30686957 5")
console.log( rut.checkDigit("4") ) //true
console.log( rut.format() ) // 30.686.957-4Properties
body
R.U.T body clean
digit
R.U.T digit to check
Methods
getDigit
Obtain the check digit
const rut = ppRut("30686957 4")
console.log( rut.getDigit() ) // "4"checkDigit
Check the digit against the given value and if it does not exist, compare it with the value found.
const rut = ppRut("30686957 5")
console.log( rut.checkDigit(4) ) // true
console.log( rut.checkDigit("4") ) // true
console.log( rut.checkDigit() ) // falseformat
Create an output format with two variables, one for the thousands separator and the second for the check digit separator.
const rut = ppRut("30686957 4")
console.log( rut.format(""," ") ) // 30686957 4
console.log( rut.format("."," ") ) // 30.686.957 4
console.log( rut.format("","") ) // 306869574Test
A test with quickjs :
qjsc -o test test.jsimport "./dist/pp-rut.nd.min.js"
const time_begin = Date.now();
let begin = 1000000 , end = 99999999;
while(begin<end){
const rut = ppRut(begin)
console.log( rut.format() )
begin++;
}
const ms = Date.now() - time_begin
console.log("Execute time : "+ms+" ms");
qjsc -o test test.js
./test27.3375 Minutes
99.999.996-4
99.999.997-2
99.999.998-0
Execute time : 1640250 msNeed something faster?
