Code coverage report for lib/map.js

Statements: 100% (17 / 17)      Branches: 100% (6 / 6)      Functions: 100% (2 / 2)      Lines: 100% (17 / 17)      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 43 44 45 46    1   1 5 5   5 4     5 5 5 44     5     1 5 5     44   5     1                            
'use strict';
 
var utils = require('./utils');
 
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 `>`) or entities (between '&' and ';')
    regexs[dictionary[entry]] = new RegExp('(?![^<]*>)(?![^&]*;)' + utils.escapeRegExpSpecialChars(entry), 'g');
  }
  return regexs;
}
 
var dictionaries = {
  'accents': {
    'a': 'á',
    'e': 'é',
    'i': 'í',
    'o': 'ó',
    'u': 'ú',
    'A': 'Á',
    'E': 'É',
    'I': 'Í',
    'O': 'Ó',
    'U': 'Ú'
  }
};