Last active
August 19, 2021 18:36
-
-
Save HenriqueMitsuo/7706bb1023d7a8dc1f8161bec27d17a3 to your computer and use it in GitHub Desktop.
This file contains 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
private generateCityRegex(cityString: string): RegExp { | |
const accents = { | |
A: "[A,À,Á,Â,Ã,Ä,Å]", | |
O: "[O,Ò,Ó,Ô,Õ,Õ,Ö,Ő]", | |
E: "[E,È,É,Ê,Ë]", | |
C: "[C,Ç]", | |
D: "[D,Ð]", | |
I: "[I,Ì,Í,Î,Ï]", | |
U: "[U,Ù,Ú,Û,Ü,Ű]", | |
N: "[N,Ñ]", | |
S: "[S,Š]", | |
Y: "[Y,Ÿ]", | |
Z: "[Z,Ž]", | |
}; | |
// const A = "[A,À,Á,Â,Ã,Ä,Å,a,à,á,â,ã,ä,å]"; | |
// const O = "[O,Ò,Ó,Ô,Õ,Õ,Ö,Ő,o,ò,ó,ô,õ,ö,ő]"; | |
// const E = "[E,È,É,Ê,Ë,e,è,é,ê,ë,ð]"; | |
// const C = "[C,Ç,c,ç]"; | |
// const D = "[D,Ð,d]"; | |
// const I = "[I,Ì,Í,Î,Ï,i,ì,í,î,ï]"; | |
// const U = "[U,Ù,Ú,Û,Ü,Ű,u,ù,ú,û,ü,ű]"; | |
// const N = "[N,Ñ,n,ñ]"; | |
// const S = "[S,Š,s,š]"; | |
// const Y = "[Y,Ÿ,y,ÿ,ý]"; | |
// const Z = "[Z,Ž,z,ž]"; | |
const city = cityString | |
.toUpperCase() | |
.split("") | |
.map((c) => { | |
switch (c) { | |
case "A": | |
return (c = accents["A"]); | |
case "O": | |
return (c = accents["O"]); | |
case "E": | |
return (c = accents["E"]); | |
case "C": | |
return (c = accents["C"]); | |
case "D": | |
return (c = accents["D"]); | |
case "I": | |
return (c = accents["I"]); | |
case "U": | |
return (c = accents["U"]); | |
case "N": | |
return (c = accents["N"]); | |
case "S": | |
return (c = accents["S"]); | |
case "Y": | |
return (c = accents["Y"]); | |
case "Z": | |
return (c = accents["Z"]); | |
default: | |
return c; | |
} | |
}) | |
.join(""); | |
return new RegExp(`^${city}`, "i"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment