Nodejs String Supplant supplant(o)

Here you can find the source of supplant(o)

Method Source Code

// adapted from http://javascript.crockford.com/remedial.html

// will modify a global object - no need to export anything.

String.prototype.supplant = function (o) {
    return this.replace(
        /\{([^{}]*)\}/g,/*  w w  w.jav a  2s .  com*/
        function (a, b) {
            var r = o[b];
            return typeof r === 'string' || typeof r === 'number' ? r : a;
        }
    );
};

Related

  1. supplant(o)
    String.prototype.supplant = function (o) {
      return this.replace(/{([^{}]*)}/g,
        function (a, b) {
            var r = o[b];
            return typeof r === 'string' || typeof r === 'number' ? r : a;
      );
    };
    
  2. supplant(o)
    String.prototype.supplant = function (o) {
      return this.replace(/{([^{}]*)}/g, function (a, b) {
        var r = o[b];
        return typeof r === "string" || typeof r === "number" ? r : a;
      });
    };
    Array.prototype.flatten = function() {
      return [].concat.apply([], this);
    };
    ...
    
  3. supplant(o)
    String.prototype.supplant = function (o) {
      return this.replace(/{([^{}]*)}/g,
        function (a, b) {
          var r = o[b];
          return (r !== undefined) ? r : a;
      );
    };
    
  4. supplant(obj)
    String.prototype.supplant = function (obj) {
      function replacer(_, name) {
        var value = obj[name]
        var type = (typeof value)
        if (value instanceof Array) return value.toString();
        if (type === 'string')      return value;
        if (type === 'number')      return value;
        return name
      return this.replace(/{([^{}]*)}/g, replacer);
    };
    
  5. supplant(str)
    String.prototype.supplant = function (str) {
      return this.replace(/{([^{}]*)}/g, function (a, b) {
        var r = str[b];
        return typeof r === 'string' || typeof r === 'number' ? r : a;
      });
    var toBase64 = function (image) {
      return image.toDataURL('image/jpeg').replace('data:image/jpeg;base64,', '');
    };
    ...