All files / helpers/conversion stringToStringLiteral.js

100% Statements 5/5
66.66% Branches 2/3
100% Functions 3/3
100% Lines 5/5

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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47    76x         48x           3x                                                   3x   12x          
// Regex para remover as palavras de execução NODE
const regex =
  /require\(['"].*?['"]\);?|async\s+|await\s+|new\s+Promise|Promise|import\s|import\(|eval|Function|process\.|process\[|Buffer|setTimeout|setInterval|XMLHttpRequest|fetch|WebSocket/gi;
 
// Função para transformar a string em template literal e avaliar as expressões
export default function stringToStringLiteral(template = '', context) {
  // eslint-disable-next-line no-new-func
  return new Function(
    `with(this) { return \`${template.replace(regex, '')}\`;}`
  ).call(context);
}
 
export function replaceAccents(str) {
  const accents = {
    á: 'a',
    à: 'a',
    ã: 'a',
    â: 'a',
    ä: 'a',
    é: 'e',
    è: 'e',
    ê: 'e',
    ë: 'e',
    í: 'i',
    ì: 'i',
    î: 'i',
    ï: 'i',
    ó: 'o',
    ò: 'o',
    õ: 'o',
    ô: 'o',
    ö: 'o',
    ú: 'u',
    ù: 'u',
    û: 'u',
    ü: 'u',
    ç: 'c',
    ñ: 'n',
  };
  return str
    .split('')
    .map((char) => accents[char] || char)
    .join('')
    .normalize('NFD')
    .replace(/[\u0300-\u036f]/g, ''); // Remove os diacríticos
}