'use strict';
module.exports = function(locale, options) {
options = options || {};
options.dictionary = options.dictionary || 'accents';
if(typeof options.dictionary === 'string'){
options.dictionary = dictionaries[options.dictionary];
}
var regexs = regexifyDictionary(options.dictionary);
for (var hash in locale) {
for (var replacement in regexs) {
locale[hash] = locale[hash].replace(regexs[replacement], replacement);
}
}
return locale;
};
function regexifyDictionary(dictionary){
var regexs = {};
for (var entry in dictionary) {
//don't replace characters inside html tags (between `<` and `>`)
regexs[dictionary[entry]] = new RegExp('(?![^<]*>)' + escapeRegExp(entry), 'g');
}
return regexs;
}
function escapeRegExp(string) {
return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1');
}
var dictionaries = {
'accents': {
'a': 'á',
'e': 'é',
'i': 'í',
'o': 'ó',
'u': 'ú'
}
};
|