Skip to content

Instantly share code, notes, and snippets.

@spalger
Created October 18, 2016 21:14
Show Gist options
  • Save spalger/dc4533e0c5b855f3c2e197af4bc541af to your computer and use it in GitHub Desktop.
Save spalger/dc4533e0c5b855f3c2e197af4bc541af to your computer and use it in GitHub Desktop.
const get = require('lodash.get')
const vars = { first: 'spencer', last: 'alger', age: 28 }
return 'Mr. { first } {last }, age {age}'.replace(/\{\s*(.+?)\s*\}/g, (_, name) => get(vars, name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment