const template = require('lodash.template'); const interpolate = /(? { if (!data) { return string; } // We replace any escaped left braces with the unicode character so we can swap it back later let processedString = string.replace(/\\{/g, '\\U+007B'); // Let lodash do its thing processedString = template(processedString, {interpolate})(data); // Replace our swapped out left braces and any escaped right braces return processedString.replace(/\\U\+007B/g, '{').replace(/\\}/g, '}'); };