Code coverage report for lib/map.js

Statements: 100% (18 / 18)      Branches: 100% (6 / 6)      Functions: 100% (3 / 3)      Lines: 100% (18 / 18)      Ignored: none     

All files » lib/ » map.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42    1 3 3   3 2     3 3 3 14     3     1 3 3   14   3     1 14     1                  
'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': 'ú'
  }
};