0.4.2 • Published 5 months ago

sh-syntax v0.4.2

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

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

1stGRxTSUnTS
1stG Open Collective backers and sponsorsRxTS Open Collective backers and sponsorsUnTS Open Collective backers and sponsors

Backers

1stGRxTSUnTS
1stG Open Collective backers and sponsorsRxTS Open Collective backers and sponsorsUnTS Open Collective backers and sponsors

Changelog

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

License

MIT © JounQin@1stG.me

0.4.2

5 months ago

0.4.1

10 months ago

0.4.0

1 year ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.7

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago