Nodejs String Interpolate interpolate

Here you can find the source of interpolate

Method Source Code

String.prototype.interpolate =
  function interpolate(vars)                                                                            
  {/*from  w  w w  . j  a  v a 2s .c  o  m*/
    return this.replace(/\$([0-9a-z-A-Z_]+)/g,
      function (m, id)
      {   
        return (typeof vars[id] === "undefined") ? m : vars[id]
      }
    )
  }

String.prototype.asHTML =
  function asHTML ()                                                                            
  {
    return this
      .replace(/\&/g, '&')
      .replace(/</g, '&lt;')
      .replace(/>/g, '&gt;')
  }

Related

  1. interpolate(o)
    String.prototype.interpolate = function (o) {
        return this.replace(/{([^{}]*)}/g,
            function (a, b) {
                var r = o[b];
                return typeof r === 'string' || typeof r === 'number' ? r : a;
        );
    };
    exports.String = String;
    ...
    
  2. interpolate(o)
    String.prototype.interpolate = function (o) {
      if(o != undefined){
          return this.replace( /{{([^{{}}]*)}}/g,
              function (a, b) {
                  var r = o[b];
                  return typeof r === 'string' || typeof r === 'number' ? r : a;
          );
      return this.toString();  
    };
    
  3. interpolate(o)
    String.prototype.interpolate = function (o) {
      return this.replace(/%\{([^\{\}]*)\}/g, function (a, b) {
          var r = o[b];
          return typeof r === 'string' || typeof r === 'number' ? r : a;
      );
    };
    
  4. interpolate(o)
    String.prototype.interpolate = function (o) {
      return this.replace(/{([^{}]*)}/g,
        function (a, b) {
          var r = o[b];
          return typeof r === 'string' || typeof r === 'number' ? r : a;
      );
    };