Home

Awesome

Transpiles JavaScript modules from one format to another.

It supports from:

to

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:

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

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