Skip to content

Instantly share code, notes, and snippets.

@yhau1989
Created November 17, 2022 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yhau1989/685f05395f3762248e8dd2a9c9abd984 to your computer and use it in GitHub Desktop.
Save yhau1989/685f05395f3762248e8dd2a9c9abd984 to your computer and use it in GitHub Desktop.
Text format Rut Chile πŸ‡¨πŸ‡±
// 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