Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sxzz/magic-string-ast
magic-string with Babel AST shortcut.
https://github.com/sxzz/magic-string-ast
ast babel magic-string
Last synced: 7 days ago
JSON representation
magic-string with Babel AST shortcut.
- Host: GitHub
- URL: https://github.com/sxzz/magic-string-ast
- Owner: sxzz
- License: mit
- Created: 2023-03-23T12:08:17.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T18:14:08.000Z (about 2 months ago)
- Last Synced: 2024-10-29T21:26:43.005Z (about 2 months ago)
- Topics: ast, babel, magic-string
- Language: TypeScript
- Homepage: https://jsr.io/@sxzz/magic-string-ast
- Size: 339 KB
- Stars: 17
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# magic-string-ast [![npm](https://img.shields.io/npm/v/magic-string-ast.svg)](https://npmjs.com/package/magic-string-ast) [![JSR](https://jsr.io/badges/@sxzz/magic-string-ast)](https://jsr.io/@sxzz/magic-string-ast)
[![Unit Test](https://github.com/sxzz/magic-string-ast/actions/workflows/unit-test.yml/badge.svg)](https://github.com/sxzz/magic-string-ast/actions/workflows/unit-test.yml)
[magic-string](https://github.com/rich-harris/magic-string) with Babel AST shortcut.
## Install
```bash
# npm
npm i magic-string-ast# jsr
npx jsr add -D @sxzz/magic-string-ast
```## Usage
```ts
import { MagicStringAST } from 'magic-string-ast'const offset = 0
const node = {
// AST node from @babel/parser
start: 6,
end: 7,
// ...
}const s = new MagicStringAST('const a = 1')
s.sliceNode(node, { offset }) // 'a'
s.removeNode(node)
s.moveNode(node, 0)
s.overwriteNode(node, 'foo')
```For more APIs, see [docs](https://jsr.io/@sxzz/magic-string-ast/doc) and [magic-string](https://github.com/rich-harris/magic-string#usage).
## Sponsors
## License
[MIT](./LICENSE) License © 2023-PRESENT [三咲智子](https://github.com/sxzz)