es6-templates
ES6 template strings compiled to ES5.
Last updated 10 years ago by eventualbuddha .
Apache 2 · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install es6-templates 
SYNC missed versions from official npm registry.

es6-templates

Compiles JavaScript written using template strings to use ES5-compatible syntax. For example, this:

var name = "Nicholas",
    msg = `Hello, ${name}!`;

console.log(msg);    // "Hello, Nicholas!"

compiles to this:

var name = "Nicholas",
    msg = "Hello, " + name + "!";

console.log(msg);    // "Hello, Nicholas!"

For more information about the proposed syntax, see the TC39 wiki page on template strings.

Install

$ npm install es6-templates

Usage

$ node
> var compile = require('es6-templates').compile;
> compile('`Hey, ${name}!`')
{ 'code': ..., 'map': ... }

Without interpolation:

`Hey!`
// becomes
'"Hey!"'

With interpolation:

`Hey, ${name}!`
// becomes
"Hey, " + name + "!"

With a tag expression:

escape `<a href="${href}">${text}</a>`
// becomes
escape(function() {
  var strings = ["\u003Ca href=\"", "\"\u003E", "\u003C/a\u003E"];
  strings.raw = ["\u003Ca href=\"", "\"\u003E", "\u003C/a\u003E"];
  return strings;
}(), href, text);

Or work directly with the AST:

$ node
> var transform = require('es6-templates').transform;
> transform(inputAST)

Transforming ASTs is best done using recast to preserve formatting where possible and for generating source maps.

Browserify

Browserify support is built in.

$ npm install es6-templates  # install local dependency
$ browserify -t es6-templates $file

Contributing

Build Status

Setup

First, install the development dependencies:

$ npm install

Then, try running the tests:

$ npm test

Pull Requests

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Any contributors to the master es6-templates repository must sign the Individual Contributor License Agreement (CLA). It's a short form that covers our bases and makes sure you're eligible to contribute.

When you have a change you'd like to see in the master repository, send a pull request. Before we merge your request, we'll make sure you're in the list of people who have signed a CLA.

Current Tags

  • 0.2.3                                ...           latest (8 years ago)

8 Versions

  • 0.2.3                                ...           8 years ago
  • 0.2.2                                ...           10 years ago
  • 0.2.1                                ...           10 years ago
  • 0.2.0                                ...           10 years ago
  • 0.1.0                                ...           10 years ago
  • 0.0.3                                ...           11 years ago
  • 0.0.2                                ...           11 years ago
  • 0.0.1                                ...           11 years ago
Downloads
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 3
Last Month 0
Dependencies (2)
Dev Dependencies (1)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |