# transpiler

> AST-based transpiler wrapper

Latest version **1.2.1** (published 2026-07-10) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 45/100 (D)** — status: active.

Positive: no vulnerabilities.

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

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2026-07-10 |
| First published | 2015-07-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.6 |
| Dependencies | 2 |
| Unpacked size | 23 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Dan Phillimore |
| Maintainers | asmblah |
| Keywords | ast, transpile |

## Links

- npm: https://www.npmjs.com/package/transpiler
- Repository: https://github.com/asmblah/transpiler
- Issues: http://github.com/asmblah/transpiler/issues
- npm.io page: https://npm.io/package/transpiler

## Dependencies (2)

- [microdash](https://npm.io/package/microdash.md) ~1
- [template-string](https://npm.io/package/template-string.md) ~1

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 1.2.1 (latest) — 2026-07-10
- 1.2.0 — 2015-12-01
- 1.1.0 — 2015-10-26
- 1.0.0 — 2015-07-28

## README

Transpiler
==========

[![Build Status](https://secure.travis-ci.org/asmblah/transpiler.png?branch=master)](http://travis-ci.org/asmblah/transpiler)

AST-based transpiler wrapper.

Usage
-----
```javascript
var myTranspiler = require('transpiler').create(<spec>);

var myResult = myTranspiler.transpile(<AST>, <DATA|null>, [<OPTIONS>]);
```

Here's a transpiler for a very simple AST spec that represents expressions:

```javascript
var transpilerSpec = {
    nodes: {
        'EXPR': function (node, transpile) {
            return transpile(node.left) + ' ' + node.operator + ' ' + transpile(node.right);
        },
        'OPERAND': function (node) {
            return node.value;
        }
    }
};
```
We can create a transpiler that uses this spec like so:

```javascript
var expressionTranspiler = require('transpiler').create(transpilerSpec);
```
Now we're ready to perform a transpile. Let's start with a simple example, here's my AST:

```javascript
var myAST = {
    name: 'EXPR',
    left: {
        name: 'OPERAND',
        value: 21
    },
    operator: '+',
    right: {
        name: 'OPERAND',
        value: 27
    }
};
```

And let's transpile:

```javascript
console.log(expressionTranspiler.transpile(myAST)); // Logs '21 + 27'
```

Overrides
---------

It's possible to override or customise the way certain nodes are transpiled.
As an example, let's change it so that operands with the value 27 are wrapped in `yes(...)`.
Here's my AST again:

```javascript
var myAST = {
    name: 'EXPR',
    left: {
        name: 'OPERAND',
        value: 21
    },
    operator: '+',
    right: {
        name: 'OPERAND',
        value: 27
    }
};
```
Now let's transpile, but this time we'll specify a custom way to transpile `OPERAND` nodes:

```javascript
console.log(expressionTranspiler.transpile(myAST, null, {
    nodes: {
        'OPERAND': function (node, transpile, context, original) {
            if (node.value === 27) {
                return 'yes(' + original(node) + ')';
            }

            return original(node);
        }
    }
})); // Logs '21 + yes(27)'
```

Keeping up to date
------------------
- [Follow me on Twitter](https://twitter.com/@asmblah) for updates: [https://twitter.com/@asmblah](https://twitter.com/@asmblah)

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