country-to-iso
Version:
Convert inconsistent country names and codes into ISO 3166-1 alpha-2.
24 lines (22 loc) • 727 B
text/typescript
export const normalize = function(str: string): string {
return str.toLocaleUpperCase()
.replace(/[,\.\(\)]/g, " ")
// Remove punctuation
.replace(/["'`‘’“”]/g, "")
// Remove dashes and hyphens
.replace(/[-‐‑‒–—―]/g, "")
// Remove braces, brackets, and parentheses
.replace(/[{}\[\]()]/g, "")
// Remove unimportant words
.replace(/(^|\s)OF(\s|$)/gi, " ")
.replace(/(^|\s)AND(\s|$)/gi, " ")
.replace(/(^|\s)THE(\s|$)/gi, " ")
.replace(/(^|\s)&(\s|$)/gi, " ")
.replace(/(^|\s)&(\s|$)/gi, " ")
// Remove excess
.replace(/\s+/g, " ")
.trim();
}
export const removeSpaces = function(str: string): string {
return str.replace(/\s/g, "");
}