interpolate.js 496 B

12345678910111213141516171819
  1. var toString = require('../lang/toString');
  2. var get = require('../object/get');
  3. var stache = /\{\{([^\}]+)\}\}/g; //mustache-like
  4. /**
  5. * String interpolation
  6. */
  7. function interpolate(template, replacements, syntax){
  8. template = toString(template);
  9. var replaceFn = function(match, prop){
  10. return toString( get(replacements, prop) );
  11. };
  12. return template.replace(syntax || stache, replaceFn);
  13. }
  14. module.exports = interpolate;