Skip to content
Expand placeholders in a template string
JavaScript
Branch: master
Clone or download
Latest commit f0c2ecd Nov 28, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore first commit (bye bye Maribor) Aug 10, 2015
.travis.yml Remove node 9 Aug 29, 2018
LICENSE Add LICENSE file, fixes #10 Nov 20, 2018
README.md Remove david badge, there are no dependencies Jun 21, 2018
index.js #7 the dollar character is not well supported (#8) Jun 21, 2018
package.json 2.0.3 Nov 27, 2018
test.js #7 the dollar character is not well supported (#8) Jun 21, 2018

README.md

expand-template

Expand placeholders in a template string.

npm Node version Build Status JavaScript Style Guide

Install

$ npm i expand-template -S

Usage

Default functionality expands templates using {} as separators for string placeholders.

var expand = require('expand-template')()
var template = '{foo}/{foo}/{bar}/{bar}'
console.log(expand(template, {
  foo: 'BAR',
  bar: 'FOO'
}))
// -> BAR/BAR/FOO/FOO

Custom separators:

var expand = require('expand-template')({ sep: '[]' })
var template = '[foo]/[foo]/[bar]/[bar]'
console.log(expand(template, {
  foo: 'BAR',
  bar: 'FOO'
}))
// -> BAR/BAR/FOO/FOO

License

All code, unless stated otherwise, is dual-licensed under WTFPL and MIT.

You can’t perform that action at this time.