transpile
Transpiles JavaScript modules from one format to another.
Last updated a month ago by m-mujica .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install transpile 
SYNC missed versions from official npm registry.

Transpiles JavaScript modules from one format to another.

It supports from:

  • es6,
  • cjs,
  • amd,
  • steal

to

  • amd,
  • steal,
  • cjs.

Currently, it can not transpile to ES6 module syntax.

Install

> npm install transpile --save-dev

Use

transpile.to transpiles from one format to another format. transpile.able lets you know if a transpile is possible.

Formats

Formats are specified by strings like:

  • "es6" - ES6 Module syntax like import Point from "math";
  • "cjs" - CommonJS syntax like var _ = require('underscore');
  • "amd" - Asynchronous Module Definition syntax like define(['jquery'],function($){});
  • "steal" - steal syntax like steal('jquery', function($){})

transpile.to(load, format, options) -> transpiledResult

Transpiles from the load's format to the specified format. If the load does not specify a format, "es6" modules are assumed. Returns an object containing the transpiled source and sourceMap (if sourceMap option provided).

Example:

var transpile = require('transpile');
var res = transpile.to({
  name: "my/module",
  source: "var foo = require('foo')",
  metadata: {format: "cjs"}
}, "amd")

res.code //-> "define("my/module", function(require, exports, module) { ... "

A load is an object in the shape of an ES6 Load Record like:

{
  name: "moduleName",
  source: "source code",
  metadata: {format: "formatName"}
}

NOTE

Previously transpile.to returned a string containing the transpiled source. To accomodate Source Maps support the API has changed and now returns an object that looks like:

{
  code: "define(...", // The transpiled source,
  map: {}, // A source map, if sourceMaps option is provided.
  ast: {} // A Mozilla Parser API compatible AST, created by Esprima
}

options

  • normalizeMap Object<moduleName,moduleName> - A mapping module names that will be used to replace dependency names in the transpiled result.
  • normalize function(name, currentName, address) -> String - A function that can be used to change moduleNames that are written in the transpiled result.
  • namedDefines Boolean=false - Set to true to insert named defines.
  • transpiler String=traceur - Set which ES6 transpiler to use. Valid options are traceur or 6to5 with traceur being the default.
  • transpile function(source, compileOptions, options) -> Object - If you want to handle tranpiling yourself and not use the built-in options, this is a function that will be given the source and is expected to return an object containing a code string.
  • sourceMaps Boolean=false - Set to true to return a map and ast object along with the result.
  • sourceMapsContent Boolean=false - If sourceMaps is set to true, this option will include the original source contents with the source maps.

transpile.able(fromFormat, toFormat) -> transpiledPath

Returns the path used to transpile from fromFormat to toFormat. If transpiling is not possible, null will be returned.

Example:

var res = transpile.able("steal","cjs");
res //-> ["steal","amd"];

This means that a module will be converted from "steal" to "amd" and then to "cjs".

Test

> npm test

Current Tags

  • 2.7.2                                ...           latest (a month ago)
  • 2.4.0-pre.1                                ...           pre (2 years ago)

61 Versions

  • 2.7.2                                ...           a month ago
  • 2.7.1                                ...           9 months ago
  • 2.7.0                                ...           9 months ago
  • 2.6.2                                ...           2 years ago
  • 2.6.1                                ...           2 years ago
  • 2.6.0                                ...           2 years ago
  • 2.5.10                                ...           2 years ago
  • 2.5.9                                ...           2 years ago
  • 2.5.8                                ...           2 years ago
  • 2.5.7                                ...           2 years ago
  • 2.5.6                                ...           2 years ago
  • 2.5.5                                ...           2 years ago
  • 2.5.4                                ...           2 years ago
  • 2.5.3                                ...           2 years ago
  • 2.5.2                                ...           2 years ago
  • 2.5.1                                ...           2 years ago
  • 2.5.0                                ...           2 years ago
  • 2.4.0                                ...           2 years ago
  • 2.4.0-pre.1                                ...           2 years ago
  • 2.4.0-pre.0                                ...           2 years ago
  • 2.3.0                                ...           3 years ago
  • 2.2.0                                ...           3 years ago
  • 2.1.0                                ...           3 years ago
  • 2.0.0                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
  • 1.0.0-pre.3                                ...           3 years ago
  • 1.0.0-pre.2                                ...           3 years ago
  • 0.9.7                                ...           3 years ago
  • 1.0.0-pre.1                                ...           4 years ago
  • 1.0.0-pre.0                                ...           4 years ago
  • 0.9.6                                ...           4 years ago
  • 0.9.5                                ...           4 years ago
  • 0.9.4                                ...           4 years ago
  • 0.9.3                                ...           4 years ago
  • 0.9.2                                ...           4 years ago
  • 0.9.1                                ...           4 years ago
  • 0.9.0                                ...           4 years ago
  • 0.8.3                                ...           4 years ago
  • 0.8.2                                ...           4 years ago
  • 0.8.1                                ...           4 years ago
  • 0.8.0                                ...           4 years ago
  • 0.8.0-pre.1                                ...           4 years ago
  • 0.7.2                                ...           4 years ago
  • 0.8.0-pre.0                                ...           4 years ago
  • 0.7.1                                ...           5 years ago
  • 0.7.0                                ...           5 years ago
  • 0.6.0                                ...           5 years ago
  • 0.5.1                                ...           5 years ago
  • 0.5.0                                ...           5 years ago
  • 0.4.0                                ...           5 years ago
  • 0.4.0-alpha.1                                ...           5 years ago
  • 0.0.0-post-warning.2                                ...           5 years ago
  • 0.0.0-post-warning.1                                ...           5 years ago
  • 0.0.0-post-warning.0                                ...           5 years ago
  • 0.0.0-post-warning                                ...           5 years ago
  • 0.4.0-alpha.0                                ...           5 years ago
  • 0.3.1                                ...           5 years ago
  • 0.2.1                                ...           5 years ago
  • 0.3.0                                ...           5 years ago
  • 0.2.0                                ...           5 years ago
  • 0.1.0                                ...           6 years ago
Downloads
Today 0
This Week 0
This Month 61
Last Day 0
Last Week 61
Last Month 399
Dependencies (13)
Dev Dependencies (9)

Copyright 2014 - 2016 © taobao.org |