Skip to content
Snippets Groups Projects
Select Git revision
  • b53f038fafcb04b06c97ad756ffdc78321068dad
  • master default protected
2 results

expand-template

  • Clone with SSH
  • Clone with HTTPS
  • Neil Gershenfeld's avatar
    Neil Gershenfeld authored
    8acf8f08
    History

    expand-template

    Expand placeholders in a template string.

    npm Build Status dependencies 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.