react-carousel-query
Version:
A infinite carousel component made with react that handles the pagination for you.
14 lines • 692 B
JavaScript
/**
* Return a string corresponding to template filled with bindings using following pattern:
* For each (key, value) of `bindings` replace, in template, `{{key}}` by escaped version of `value`
*
* @param template {String} Template with `{{binding}}`
* @param bindings {Object} key-value object use to fill the template, `{{key}}` will be replaced by `escaped(value)`
* @returns {String} Filled template
*/
export var interpolate = function (template, bindings) {
return Object.entries(bindings).reduce(function (acc, [k, v]) {
var escapedString = v.replace(/\\/g, '/').replace(/\$/g, '$$$');
return acc.replace(new RegExp(`{{${k}}}`, 'g'), escapedString);
}, template);
};