Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/un-ts/sh-syntax
A WASM shell parser and formatter with bash support, based on `mvdan/sh`
https://github.com/un-ts/sh-syntax
go golang shell shell-script shellscript tinygo wasm
Last synced: 4 months ago
JSON representation
A WASM shell parser and formatter with bash support, based on `mvdan/sh`
- Host: GitHub
- URL: https://github.com/un-ts/sh-syntax
- Owner: un-ts
- License: mit
- Created: 2022-04-01T01:23:01.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-27T06:21:00.000Z (4 months ago)
- Last Synced: 2024-10-29T22:34:15.192Z (4 months ago)
- Topics: go, golang, shell, shell-script, shellscript, tinygo, wasm
- Language: TypeScript
- Homepage:
- Size: 4.29 MB
- Stars: 15
- Watchers: 1
- Forks: 4
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# sh-syntax
[](https://github.com/un-ts/sh-syntax/actions/workflows/ci.yml)
[](https://codecov.io/gh/un-ts/sh-syntax)
[](https://lgtm.com/projects/g/un-ts/sh-syntax/context:javascript)
[](https://github.com/plantain-00/type-coverage)
[](https://www.npmjs.com/package/sh-syntax)
[](https://github.com/un-ts/sh-syntax/releases)[](https://conventionalcommits.org)
[](https://renovatebot.com)
[](https://standardjs.com)
[](https://github.com/prettier/prettier)
[](https://github.com/changesets/changesets)A WASM shell parser and formatter with bash support, based on [mvdan/sh](https://github.com/mvdan/sh)
## TOC
- [Usage](#usage)
- [Install](#install)
- [API](#api)
- [Sponsors](#sponsors)
- [Backers](#backers)
- [Changelog](#changelog)
- [License](#license)## Usage
### Install
```sh
# yarn
yarn add sh-syntax# npm
npm i sh-syntax
```### API
```js
// node
import { parse, print } from 'sh-syntax'const text = "echo 'Hello World!'"
const ast = await parse(text)
const newText = await print(ast, {
// `originalText` is required for now, hope we will find better solution later
originalText: text,
})
``````js
// browser
import { getProcessor } from 'sh-syntax'const processor = getProcessor(() =>
fetch('sh-syntax/main.wasm').then(res => res.arrayBuffer()),
)const parse = (text, options) => processor(text, options)
const print = (textOrAst, options) => {
if (typeof textOrAst === 'string') {
return processor(textOrAst, {
...options,
print: true,
})
}
return processor(textOrAst, options)
}// just like node again
const text = "echo 'Hello World!'"
const ast = await parse(text)
const newText = await print(ast, { originalText: text })
```## Sponsors
| 1stG | RxTS | UnTS |
| ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| [](https://opencollective.com/1stG) | [](https://opencollective.com/rxts) | [](https://opencollective.com/unts) |## Backers
| 1stG | RxTS | UnTS |
| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| [](https://opencollective.com/1stG) | [](https://opencollective.com/rxts) | [](https://opencollective.com/unts) |## Changelog
Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).
## License
[MIT][] © [JounQin][]@[1stG.me][]
[1stg.me]: https://www.1stg.me
[jounqin]: https://GitHub.com/JounQin
[mit]: http://opensource.org/licenses/MIT