{"id":14155426,"url":"https://github.com/un-ts/sh-syntax","last_synced_at":"2025-04-15T09:40:21.088Z","repository":{"id":37006635,"uuid":"476532247","full_name":"un-ts/sh-syntax","owner":"un-ts","description":"A WASM shell parser and formatter with bash support, based on `mvdan/sh`","archived":false,"fork":false,"pushed_at":"2025-04-08T03:07:08.000Z","size":6656,"stargazers_count":16,"open_issues_count":4,"forks_count":4,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-10T06:28:03.909Z","etag":null,"topics":["go","golang","shell","shell-script","shellscript","tinygo","wasm"],"latest_commit_sha":null,"homepage":"https://npm.im/sh-syntax","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/un-ts.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["JounQin","1stG","rx-ts","un-ts"],"patreon":"1stG","open_collective":"unts","custom":["https://opencollective.com/1stG","https://opencollective.com/rxts","https://afdian.net/@JounQin"]}},"created_at":"2022-04-01T01:23:01.000Z","updated_at":"2025-04-09T10:21:11.000Z","dependencies_parsed_at":"2023-02-18T15:45:53.212Z","dependency_job_id":"b192024a-55ca-49f8-b03d-13276b6677ba","html_url":"https://github.com/un-ts/sh-syntax","commit_stats":{"total_commits":74,"total_committers":3,"mean_commits":"24.666666666666668","dds":"0.28378378378378377","last_synced_commit":"102e2459f546700fcad27ad4437c291a158a83ac"},"previous_names":["rx-ts/sh-syntax"],"tags_count":25,"template":false,"template_full_name":"un-ts/lib-boilerplate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/un-ts%2Fsh-syntax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/un-ts%2Fsh-syntax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/un-ts%2Fsh-syntax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/un-ts%2Fsh-syntax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/un-ts","download_url":"https://codeload.github.com/un-ts/sh-syntax/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248905024,"owners_count":21180907,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","shell","shell-script","shellscript","tinygo","wasm"],"created_at":"2024-08-17T08:03:07.163Z","updated_at":"2025-04-15T09:40:21.046Z","avatar_url":"https://github.com/un-ts.png","language":"TypeScript","funding_links":["https://github.com/sponsors/JounQin","https://github.com/sponsors/1stG","https://github.com/sponsors/rx-ts","https://github.com/sponsors/un-ts","https://patreon.com/1stG","https://opencollective.com/unts","https://opencollective.com/1stG","https://opencollective.com/rxts","https://afdian.net/@JounQin"],"categories":["wasm"],"sub_categories":[],"readme":"# sh-syntax\n\n[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/un-ts/sh-syntax/ci.yml?branch=main)](https://github.com/un-ts/sh-syntax/actions/workflows/ci.yml?query=branch%3Amain)\n[![Codecov](https://img.shields.io/codecov/c/github/un-ts/sh-syntax.svg)](https://codecov.io/gh/un-ts/sh-syntax)\n[![type-coverage](https://img.shields.io/badge/dynamic/json.svg?label=type-coverage\u0026prefix=%E2%89%A5\u0026suffix=%\u0026query=$.typeCoverage.atLeast\u0026uri=https%3A%2F%2Fraw.githubusercontent.com%2Fun-ts%2Fsh-syntax%2Fmain%2Fpackage.json)](https://github.com/plantain-00/type-coverage)\n[![CodeRabbit Pull Request Reviews](https://img.shields.io/coderabbit/prs/github/un-ts/sh-syntax)](https://coderabbit.ai)\n[![npm](https://img.shields.io/npm/v/sh-syntax.svg)](https://www.npmjs.com/package/sh-syntax)\n[![GitHub Release](https://img.shields.io/github/release/un-ts/sh-syntax)](https://github.com/un-ts/sh-syntax/releases)\n\n[![Conventional Commits](https://img.shields.io/badge/conventional%20commits-1.0.0-yellow.svg)](https://conventionalcommits.org)\n[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n[![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![changesets](https://img.shields.io/badge/maintained%20with-changesets-176de3.svg)](https://github.com/changesets/changesets)\n\nA WASM shell parser and formatter with bash support, based on [mvdan/sh](https://github.com/mvdan/sh)\n\n## TOC \u003c!-- omit in toc --\u003e\n\n- [Usage](#usage)\n  - [Install](#install)\n  - [API](#api)\n    - [node](#node)\n    - [browser](#browser)\n- [Benchmark](#benchmark)\n- [Sponsors](#sponsors)\n- [Backers](#backers)\n- [Changelog](#changelog)\n- [License](#license)\n\n## Usage\n\n### Install\n\n```sh\n# yarn\nyarn add sh-syntax\n\n# npm\nnpm i sh-syntax\n```\n\n### API\n\n#### node\n\n```js\nimport { parse, print } from 'sh-syntax'\n\nconst text = \"echo 'Hello World!'\"\nconst ast = await parse(text)\nconst newText = await print(ast, {\n  // `originalText` is required for now, hope we will find better solution later\n  originalText: text,\n})\n```\n\n#### browser\n\n```js\nimport { getProcessor } from 'sh-syntax'\n\n// choose your own way to load the WASM file\n\n// with `fetch`\nconst processor = getProcessor(() =\u003e\n  fetch('http://cdn.jsdelivr.net/npm/sh-syntax@latest/main.wasm'),\n)\n\n// with `wasm?init` via `vite`\nimport initWasm from 'sh-syntax/wasm?init'\nconst processor = getProcessor(initWasm)\n\nconst parse = (text, options) =\u003e processor(text, options)\n\nconst print = (textOrAst, options) =\u003e {\n  if (typeof textOrAst === 'string') {\n    return processor(textOrAst, {\n      ...options,\n      print: true,\n    })\n  }\n  return processor(textOrAst, options)\n}\n\n// just like node again\nconst text = \"echo 'Hello World!'\"\nconst ast = await parse(text)\nconst newText = await print(ast, { originalText: text })\n```\n\n## Benchmark\n\n```console\nclk: ~2.81 GHz\ncpu: Apple M1 Max\nruntime: node 18.20.8 (arm64-darwin)\n\nbenchmark                   avg (min … max) p75 / p99    (min … top 1%)\n------------------------------------------- -------------------------------\nsh-syntax                     18.33 ms/iter  18.56 ms   ▃        ▃█\n                      (17.48 ms … 20.83 ms)  19.09 ms ▂▂█    ▂   ██▂  ▂ ▂\n                    ( 28.52 kb …   9.82 mb) 890.46 kb ███▆▆▁▁█▁▁▆███▁▆█▁█▆▆\n                  5.07 ipc (  1.22% stalls)  99.36% L1 data cache\n         56.96M cycles 288.57M instructions  39.27% retired LD/ST (113.32M)\n\nsh-syntax (synckit)           18.38 ms/iter  18.82 ms ▂▂▂           ▂▂ █▂\n                      (17.63 ms … 19.06 ms)  19.04 ms ███▅          ██ ██▅▅\n                    (291.31 kb … 312.45 kb) 292.09 kb ████▇▇▇▇▁▁▁▁▇▁██▇████\n                  1.11 ipc ( 11.51% stalls)  40.34% L1 data cache\n        434.86k cycles 484.78k instructions  19.58% retired LD/ST ( 94.92k)\n\nmvdan-sh                      79.47 ms/iter  78.95 ms  █\n                     (71.22 ms … 126.09 ms)  80.84 ms ▅█ ▅▅▅    ▅    ▅▅▅  ▅\n                    (  8.18 mb …   9.70 mb)   8.83 mb ██▁███▁▁▁▁█▁▁▁▁███▁▁█\n                  5.18 ipc (  1.05% stalls)  99.04% L1 data cache\n        249.41M cycles   1.29G instructions  34.41% retired LD/ST (444.42M)\n\nsummary\n  sh-syntax\n   1x faster than sh-syntax (synckit)\n   4.34x faster than mvdan-sh\n```\n\nSee [benchmark](./benchmark/benchmark.txt) for more details.\n\nYou can try it with running `node benchmark` by yourself. [Here](./benchmark/index.js) is the benchmark source code.\n\n[![Sponsors](https://raw.githubusercontent.com/1stG/static/master/sponsors.svg)](https://github.com/sponsors/JounQin)\n\n## Sponsors\n\n| 1stG                                                                                                                   | RxTS                                                                                                                   | UnTS                                                                                                                   |\n| ---------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |\n| [![1stG Open Collective sponsors](https://opencollective.com/1stG/organizations.svg)](https://opencollective.com/1stG) | [![RxTS Open Collective sponsors](https://opencollective.com/rxts/organizations.svg)](https://opencollective.com/rxts) | [![UnTS Open Collective sponsors](https://opencollective.com/unts/organizations.svg)](https://opencollective.com/unts) |\n\n## Backers\n\n| 1stG                                                                                                                | RxTS                                                                                                                | UnTS                                                                                                                |\n| ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |\n| [![1stG Open Collective backers](https://opencollective.com/1stG/individuals.svg)](https://opencollective.com/1stG) | [![RxTS Open Collective backers](https://opencollective.com/rxts/individuals.svg)](https://opencollective.com/rxts) | [![UnTS Open Collective backers](https://opencollective.com/unts/individuals.svg)](https://opencollective.com/unts) |\n\n## Changelog\n\nDetailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).\n\n## License\n\n[MIT][] © [JounQin][]@[1stG.me][]\n\n[1stG.me]: https://www.1stg.me\n[JounQin]: https://GitHub.com/JounQin\n[MIT]: http://opensource.org/licenses/MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fun-ts%2Fsh-syntax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fun-ts%2Fsh-syntax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fun-ts%2Fsh-syntax/lists"}