# ast-transform

> Convenience wrapper for performing AST transformations with browserify transform streams

Latest version **0.0.0** (published 2014-02-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install ast-transform
pnpm add ast-transform
yarn add ast-transform
bun add ast-transform
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.0 |
| Published | 2014-02-27 |
| First published | 2014-02-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Hugh Kennedy |
| Maintainers | hughsk |
| Keywords | ast, transform, browserify, stream |

## Links

- npm: https://www.npmjs.com/package/ast-transform
- Repository: https://github.com/hughsk/ast-transform
- Issues: https://github.com/hughsk/ast-transform/issues
- npm.io page: https://npm.io/package/ast-transform

## Dependencies (3)

- [esprima](https://npm.io/package/esprima.md) ~1.0.4
- [through](https://npm.io/package/through.md) ~2.3.4
- [escodegen](https://npm.io/package/escodegen.md) ~1.2.0

## 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

- 0.0.0 (latest) — 2014-02-27

## README

# ast-transform [![Flattr this!](https://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=hughskennedy&url=http://github.com/hughsk/ast-transform&title=ast-transform&description=hughsk/ast-transform%20on%20GitHub&language=en_GB&tags=flattr,github,javascript&category=software)[![experimental](http://hughsk.github.io/stability-badges/dist/experimental.svg)](http://github.com/hughsk/stability-badges) #

Convenience wrapper for performing AST transformations with
[browserify](http://browserify.org/) transform streams. Note that it doesn't
handle source maps nicely, though pull requests are welcome!

## Usage ##

[![ast-transform](https://nodei.co/npm/ast-transform.png?mini=true)](https://nodei.co/npm/ast-transform)

### `ast(transform[, opts])` ###

Where `transform` is a function that takes a filename and returns a function,
e.g.:

``` javascript
var replace = require('replace-method')
var ast = require('ast-transform')
var path = require('path')

module.exports = ast(function (file) {
  if (path.extname(file) !== '.js') return

  return function(ast, done) {
    // replace require calls with
    // strings for some reason
    replace(ast)(['require'], function(node) {
      return { type: 'Literal', value: 'replaced!' }
    })

    done()
  }
})
```

Note that you can return a falsey value instead of a function to bail the
stream early and avoid the parse/deparse overhead. Here's an example of using
the above with browserify:

``` javascript
var browserify = require('browserify')
var example = require('./example')
var fs = require('fs')

browserify('./index.js')
  .transform(example)
  .bundle()
  .pipe(fs.createWriteStream(__filename + '/bundle.js'))
```

## License ##

MIT. See [LICENSE.md](http://github.com/hughsk/ast-transform/blob/master/LICENSE.md) for details.

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