Skip to content

Instantly share code, notes, and snippets.

@ibolmo
Created July 19, 2011 15:30
Show Gist options
  • Select an option

  • Save ibolmo/1092786 to your computer and use it in GitHub Desktop.

Select an option

Save ibolmo/1092786 to your computer and use it in GitHub Desktop.

Revisions

  1. ibolmo revised this gist Jul 19, 2011. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions String.substitute.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,14 @@
    /*
    ---
    name: String.substitute
    description: Replaces Core/String.substitute with an augmented version that supports More/Object.Extras's getFromPath.
    requires: [Core/String, More/Object.Extras]
    provides: [String.substitute]
    ...
    */

  2. ibolmo created this gist Jul 19, 2011.
    16 changes: 16 additions & 0 deletions String.substitute.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    /*
    ---
    ...
    */

    String.implement({

    substitute: function(object, regexp){
    return this.replace(regexp || (/\\?\{([^{}]+)\}/g), function(match, name){
    if (match.charAt(0) == '\\') return match.slice(1);
    return Object.getFromPath(object, name) || '';
    });
    }

    });