All files filter.js

100% Statements 13/13
90% Branches 9/10
100% Functions 2/2
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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  8x   8x 6x     8x 4x   4x 4x 6x 6x 1x     5x 5x         8x    
export default (key, context) => {
  let translation = key;
 
  if (window.translations !== undefined && window.translations[key] !== undefined) {
    translation = window.translations[key];
  }
 
  if (typeof context === 'object') {
    const matches = translation.match(/(%([^%]|%%)*%)/g);
 
    Eif (matches) {
      matches.forEach((match) => {
        const prop = match.replace(/[%]+/g, '');
        if (!Object.prototype.hasOwnProperty.call(context, prop)) {
          return;
        }
 
        const regex = new RegExp(match, 'g');
        translation = translation.replace(regex, context[prop]);
      });
    }
  }
 
  return translation;
};