Created
          April 5, 2013 13:32 
        
      - 
      
- 
        Save ourmaninamsterdam/5319295 to your computer and use it in GitHub Desktop. 
    Dustin Diaz object string supplanter
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | function substitute(s, o){ | |
| return s.replace( /{([^{}]*)}/g , | |
| function (a, b) { | |
| var r = o[b]; | |
| return typeof r === 'string' || typeof r === 'number' ? r : a; | |
| } | |
| ); | |
| } | |
| substitute("My name is {name} and I work at {workplace}",{ | |
| name: "Justin Perry", | |
| workplace: "I || X" | |
| }) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment