# equivalent-exchange

> Transmute one JavaScript string into another by way of mutating its AST. Powered by [babel](https://babeljs.io/) and [recast](https://www.npmjs.com/package/recast).

Latest version **8.0.0** (published 2026-08-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install equivalent-exchange
pnpm add equivalent-exchange
yarn add equivalent-exchange
bun add equivalent-exchange
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 8.0.0 |
| Published | 2026-08-04 |
| First published | 2022-02-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 42.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 57 |
| Author | Lily Skye |
| Maintainers | suchipi |
| Keywords | ast, transform, codemod, babel, recast, transmute, transmutation |

## Links

- npm: https://www.npmjs.com/package/equivalent-exchange
- Repository: https://github.com/suchipi/equivalent-exchange
- Homepage: https://github.com/suchipi/equivalent-exchange#readme
- Issues: https://github.com/suchipi/equivalent-exchange/issues
- npm.io page: https://npm.io/package/equivalent-exchange

## Dependencies (10)

- [debug](https://npm.io/package/debug.md) ^4.4.3
- [recast](https://npm.io/package/recast.md) ^0.23.19
- [tinyglobby](https://npm.io/package/tinyglobby.md) ^0.2.17
- [@babel/core](https://npm.io/package/@babel/core.md) ^8.0.1
- [@babel/types](https://npm.io/package/@babel/types.md) ^8.0.4
- [@babel/parser](https://npm.io/package/@babel/parser.md) ^8.0.4
- [parallel-park](https://npm.io/package/parallel-park.md) ^0.3.1
- [@babel/template](https://npm.io/package/@babel/template.md) ^8.0.0
- [@babel/traverse](https://npm.io/package/@babel/traverse.md) ^8.0.4
- [@babel/generator](https://npm.io/package/@babel/generator.md) ^8.0.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

- 8.0.0 (latest) — 2026-08-04
- 7.0.0 — 2026-08-04
- 3.2.0 — 2025-11-18
- 3.1.1 — 2025-08-25
- 3.1.0 — 2025-08-25
- 3.0.0 — 2025-05-25
- 2.1.0 — 2025-01-31
- 2.0.0 — 2025-01-31
- 1.13.1 — 2024-11-12
- 1.13.0 — 2024-05-15
- 1.12.0 — 2024-05-14
- 1.11.0 — 2024-04-05
- 1.10.0 — 2023-09-29
- 1.9.0 — 2023-02-23
- 1.8.0 — 2022-11-30
- … 12 more at https://npm.io/package/equivalent-exchange/versions

## README

# equivalent-exchange

Suchipi's flexible JS/TS codemodding/refactoring toolkit, powered by [Babel](https://babeljs.io/) and [Recast](https://www.npmjs.com/package/recast).

> equivalent-exchange@8 uses Babel 8. If you need Babel 7, use equivalent-exchange@7.

## Features

- Can parse code using modern ES20XX syntax, as well as JSX/TSX and TypeScript/Flow syntax.
- Maintains the source formatting of the original source, where possible; only modified parts of the code will be touched.
- Can generate a source map that maps your input file into your transformed output.

## Usage Example

"Transmute" one string of code into another by using the `transmute` function:

```ts
import { transmute } from "equivalent-exchange";

const someJs = "console.log('hi!');";

const result = transmute(someJs, (ast) => {
  // Within this callback, we mutate the AST as desired for the
  // codemod/refactor.
  // Use https://astexplorer.net/ to see what this tree
  // structure looks like!
  ast.program.body[0].expression.callee.arguments[0].value = "goodbye!";
});

console.log(result.code); // console.log("goodbye!");
```

For more flexible codemods, use the included utilities:

```ts
import { transmute, traverse, types } from "equivalent-exchange";

// `traverse` and `types` come from Babel!

const someJs = "console.log('hi!', 'hi again!');";

const result = transmute(someJs, (ast) => {
  // Walk the tree...
  traverse(ast, {
    // And for every StringLiteral node we find...
    StringLiteral(path) {
      const { node } = path;
      // If it starts with 'hi'...
      if (node.value.startsWith("hi")) {
        const newValue = node.value.replace(/^hi/, "bye");
        const newNode = types.stringLiteral(newValue);
        // Change 'hi' to 'bye'
        path.replaceWith(newNode);
      }
    },
  });
});

console.log(result.code); // "console.log('bye!', 'bye again!');"
```

To transform files in bulk, use the "mapFiles" API:

```ts
import { transmute, traverse, types, mapFiles } from "equivalent-exchange";

const results = await mapFiles.fromGlob("src/*.ts", (content, path) => {
  if (path === "src/build-docs.ts") {
    // Skip this file
    return;
  }

  return transmute(content, (ast) => {
    // Walk the tree...
    traverse(ast, {
      // And for every StringLiteral node we find...
      StringLiteral(path) {
        const { node } = path;
        // If it starts with 'hi'...
        if (node.value.startsWith("hi")) {
          const newValue = node.value.replace(/^hi/, "bye");
          const newNode = types.stringLiteral(newValue);
          // Change 'hi' to 'bye'
          path.replaceWith(newNode);
        }
      },
    });
  });
});
```

## API Documentation

See [api/index.md](/api/index.md).

## License

MIT

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