Skip to content

A WASM shell parser and formatter with bash support, based on mvdan/sh

License

Notifications You must be signed in to change notification settings

lgtm-migrator/sh-syntax

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sh-syntax

GitHub Actions Codecov Language grade: JavaScript type-coverage npm GitHub Release

Conventional Commits Renovate enabled JavaScript Style Guide Code Style: Prettier changesets

A WASM shell parser and formatter with bash support, based on mvdan/sh

TOC

Usage

Install

# yarn
yarn add sh-syntax

# npm
npm i sh-syntax

API

// 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,
})
// 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
1stG Open Collective backers and sponsors RxTS Open Collective backers and sponsors UnTS Open Collective backers and sponsors

Backers

1stG RxTS UnTS
1stG Open Collective backers and sponsors RxTS Open Collective backers and sponsors UnTS Open Collective backers and sponsors

Changelog

Detailed changes for each release are documented in CHANGELOG.md.

License

MIT © JounQin@1stG.me

About

A WASM shell parser and formatter with bash support, based on mvdan/sh

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 50.9%
  • Go 38.5%
  • JavaScript 10.6%