Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

es6-template-strings

medikoo180.6kMIT2.0.1

Compile and resolve template strings notation as specified in ES6

es6, template, string, literal, literals, format, i18n, quasiliterals, multiline, localization, escape

readme

es6-template-strings

Compile and resolve template strings notation as specified in ES6

Usage


var template = require('es6-template-strings');

// Hello WORLD!
console.log(template('Hello ${place.toUpperCase()}!', { place: "World" }));

// You can reuse same templates:
var compile = require('es6-template-strings/compile')
  , resolveToString = require('es6-template-strings/resolve-to-string')

  , compiled = compile('Welcome to ${siteName}, you are visitor number ${visitorNumber}!');

// Welcome to MySite, you are visitor number 137!
console.log(resolveToString(compiled, { siteName: "MySite", visitorNumber: 137 }));

// Welcome to OtherSite, you are visitor number 777!
console.log(resolveToString(compiled, { siteName: "OtherSite", visitorNumber: 777 }));

// You may prepare custom tag functions
var resolve = require('es6-template-strings/resolve');

var customTag = function (literals/*, …substitutions*/) {
    // Process input and return result string
};

// Output template processed by customTag:
customTag.apply(null, resolve(compiled, {/* context */}));

Installation

NPM

In your project path:

$ npm install es6-template-strings
Browser

You can easily bundle es6-template-strings for browser with modules-webmake

Tests Build Status

$ npm test

changelog

v2.0.1 -- 2016.08.12

  • Fix handling of context with properties named with invalid variable names (#5)

v2.0.0 -- 2015.09.03

  • Fix templates resolution. Since this update, internal string is parsed as valid JavaScript code, therefore any '}' characters used as code continuation (or string inserts) won't break resolution of template. Issue #3
  • Resolve non returning expressions to undefined (instead of '')
  • Improve resolve logic
  • Support 'partial' option

v1.0.0 -- 2015.06.23

  • Fix bug related to '$${' resolution
  • Improve error reporting
  • Fix spelling of LICENSE
  • Configure lint scripts
  • Drop support for v0.8 node ('^' in package.json dependencies)

v0.1.0 -- 2014.04.28

  • Assure strictly npm dependencies
  • Update dependencies to latest versions
  • Introduce resolution to array ('resolve-to-array', 'passthru-array' and 'to-array' modules)
  • Reuse same functions among compilation tasks
  • Do not stringify substitution on resolution

v0.0.0 -- 2013.10.10 Initial (dev version)