# transpile

> Transpiles JavaScript modules from one format to another.

Latest version **2.8.0** (published 2022-06-01) · 0 weekly downloads

## Install

```sh
npm install transpile
pnpm add transpile
yarn add transpile
bun add transpile
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.8.0 |
| Published | 2022-06-01 |
| First published | 2014-04-18 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 13 |
| Unpacked size | 127.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 25 |
| Author | Bitovi |
| Maintainers | justinbmeyer, matthewp, m-mujica, bmomberger-bitovi |

## Links

- npm: https://www.npmjs.com/package/transpile
- Repository: https://github.com/stealjs/transpile
- Homepage: https://github.com/stealjs/transpile#readme
- Issues: https://github.com/stealjs/transpile/issues
- npm.io page: https://npm.io/package/transpile

## Dependencies (13)

- [urix](https://npm.io/package/urix.md) ^0.1.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [traceur](https://npm.io/package/traceur.md) 0.0.111
- [ast-types](https://npm.io/package/ast-types.md) ^0.15.2
- [comparify](https://npm.io/package/comparify.md) 0.2.0
- [escodegen](https://npm.io/package/escodegen.md) ^2.0.0
- [estemplate](https://npm.io/package/estemplate.md) ^0.5.1
- [estraverse](https://npm.io/package/estraverse.md) ^5.3.0
- [source-map](https://npm.io/package/source-map.md) ~0.1.43
- [esprima-next](https://npm.io/package/esprima-next.md) ^5.8.2
- [babel-standalone](https://npm.io/package/babel-standalone.md) ^6.26.0
- [js-string-escape](https://npm.io/package/js-string-escape.md) 1.0.1
- [js-module-formats](https://npm.io/package/js-module-formats.md) ~0.1.2

## Recent versions

- 2.8.0 (latest) — 2022-06-01
- 2.4.0-pre.1 (pre) — 2017-07-06
- 2.7.2 — 2019-11-13
- 2.7.1 — 2019-03-06
- 2.7.0 — 2019-03-05
- 2.6.2 — 2018-03-29
- 2.6.1 — 2018-03-20
- 2.6.0 — 2018-01-19
- 2.5.10 — 2018-01-05
- 2.5.9 — 2018-01-05
- 2.5.8 — 2017-12-28
- 2.5.7 — 2017-10-17
- 2.5.6 — 2017-10-04
- 2.5.5 — 2017-09-27
- 2.5.4 — 2017-09-25
- … 47 more at https://npm.io/package/transpile/versions

## README

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](https://github.com/amdjs/amdjs-api/wiki/AMD) 
         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:

```js
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](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-load-records-and-loadrequest-objects) like:

```js
{
  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:

```js
{
  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:

```js
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

---
_Source: https://npm.io/package/transpile · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
