Created
April 22, 2013 23:52
-
-
Save fabioyamate/5439613 to your computer and use it in GitHub Desktop.
transliterate string given a table conversion
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
// transliterate (Char a) :: [a] -> [a] -> [a] -> [a] | |
var transliterate = function(from, to) { | |
var approximations = {}; | |
for (var i = 0, len = from.length; i < len; ++i) { | |
approximations[from.charAt(i)] = to.charAt(i); | |
} | |
return function(input) { | |
return input.replace(/[^\x00-\x7f]/g, function(char) { | |
return approximations[char]; | |
}); | |
}; | |
}; | |
var tr = transliterate; | |
var characteresToReplace = "ãàáäâèéëêìíïîòóöôùúüûñç" | |
, replacements = "aaaaaeeeeiiiioooouuuunc"; | |
var removeAccents = tr(characteresToReplace, replacements); | |
removeAccents("ãàáäâèéëêìíïîòóöôùúüûñç"); // => aaaaaeeeeiiiioooouuuunc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment