Javascript String template()

Description

Javascript String template()


String.prototype.template = function () {
  var current = this;

  function safeRegexEscape(str) {
    return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
  }/*from  w  ww  .j  av  a2 s . c  om*/

  for (var i = 0; i < arguments.length; i++) {
    var arg = arguments[i];
    current = current.replace(new RegExp(safeRegexEscape("%%")), arg);
  }

  return current;
};

module.exports = {};



PreviousNext

Related