substitute.js 311 B

12345678910111213
  1. var substitute = function substitute(str, o) {
  2. if (!str || !o) {
  3. return str;
  4. }
  5. return str.replace(/\\?\{([^{}]+)\}/g, function (match, name) {
  6. if (match.charAt(0) === '\\') {
  7. return match.slice(1);
  8. }
  9. return o[name] === undefined ? '' : o[name];
  10. });
  11. };
  12. module.exports = substitute;