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 | 42x 42x 42x 40x 19x 40x 40x 39x 43x 43x 42x | const Evaluator = require('./evaluator'); const evaluator = new Evaluator(); const dictionary = {}; function compile(str) { if (dictionary[str] === undefined) { dictionary[str] = str.match(/{{\s*([^}]+)\s*}}/g) || []; } const matches = dictionary[str]; return (context = {}) => { return matches.reduce((p, c) => { const solution = evaluator.evaluate(c.substr(2, c.length - 4), context); return solution ? p.replace(c, solution) : p; }, str); }; } module.exports = { compile }; |