Nodejs String Interpolate interpolate(props)

Here you can find the source of interpolate(props)

Method Source Code

String.prototype.interpolate = function(props) {
   return this.replace(/\{(\w+)\}/g, function(match, expr) {
      return (props || window)[expr];
   });//from   w ww . ja v a 2s.  c om
};

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;
      );
    };
    
  5. interpolate(props)
    String.prototype.interpolate = function(props) {
      return this.replace(/\{\{(\w+)\}\}/g, function(match, expr) {
          return (props || window)[expr];
      });
    };
    
  6. interpolate(replacements)
    String.prototype.interpolate = function (replacements) {
        return this.replace(/\{(\w+)\}/g, function (match, capture) {
            if (replacements[capture]) {
                return replacements[capture];
            else {
                return match;
        });
    ...