Created
November 17, 2022 15:25
-
-
Save yhau1989/685f05395f3762248e8dd2a9c9abd984 to your computer and use it in GitHub Desktop.
Text format Rut Chile π¨π±
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.bci.cl/corporativo/banco-en-linea/personas | |
// https://www.nombrerutyfirma.com/nombre | |
const formatRut = (text: string) => { | |
let f = text.split("").reverse() | |
const fr1 = f.splice(0, 1).join("") | |
const fr2 = f.splice(0, 3).join("") | |
const fr3 = f.splice(0, 3).join("") | |
const fr4 = f.splice(0, 3).join("") | |
const te = (_text: string, caracter = ".") => | |
_text.length > 0 ? `${_text}${caracter}` : "" | |
return `${te(fr1, "-")}${te(fr2)}${te(fr3)}${te(fr4)}` | |
.split("") | |
.slice(0, -1) | |
.reverse() | |
.join("") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment