2.1.0 • Published 9 months ago

equivalent-exchange v2.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

equivalent-exchange

Transmute one JavaScript string into another by way of mutating its AST. Powered by babel and recast.

Features

  • Can parse code using modern ES20XX syntax, as well as either TypeScript or 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

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

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

const result = transmute(someJs, (ast) => {
  traverse(ast, {
    StringLiteral(path) {
      const { node } = path;
      if (node.value === "hi!") {
        path.replaceWith(types.stringLiteral("goodbye!"));
      }
    },
  });
});

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

Note that you don't have to use the provided traverse or types; you can mutate the ast using whatever traversal method you prefer.

API Documentation

Please see api/index.d.ts for API documentation. There are lots of comments.

License

MIT

2.1.0

9 months ago

2.0.0

9 months ago

1.13.1

11 months ago

1.13.0

1 year ago

1.12.0

1 year ago

1.11.0

2 years ago

1.10.0

2 years ago

1.9.0

3 years ago

1.8.0

3 years ago

1.7.0

3 years ago

1.6.0

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.0

4 years ago