Nodejs Utililty Methods String Interpolate

List of utility methods to do String Interpolate

Description

The list of methods to do String Interpolate are organized into topic(s).

Method

interpolate
String.prototype.interpolate =
  function interpolate(vars)                                                                            
    return this.replace(/\$([0-9a-z-A-Z_]+)/g,
      function (m, id)
        return (typeof vars[id] === "undefined") ? m : vars[id]
    )
...
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;
...
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();  
};
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;
  );
};
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;
  );
};
interpolate(props)
String.prototype.interpolate = function(props) {
  return this.replace(/\{\{(\w+)\}\}/g, function(match, expr) {
      return (props || window)[expr];
  });
};
interpolate(props)
String.prototype.interpolate = function(props) {
  return this.replace(/\{(\w+)\}/g, function(match, expr) {
    return (props || window)[expr];
  });
};
interpolate(replacements)
String.prototype.interpolate = function (replacements) {
    return this.replace(/\{(\w+)\}/g, function (match, capture) {
        if (replacements[capture]) {
            return replacements[capture];
        else {
            return match;
    });
...