// readme

sh-syntax

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 { init, parse, print } from 'sh-syntax'

// Optional: load and initialize the WASM runtime up front.
await init()

const text = "echo 'Hello World!'"
const ast = await parse(text)

// print() formats source text.
const formatted = await print(text)

// print(ast) prints the current tree, including edits made to its fields.
// print(ast) serializes the tree to Go and decodes it before printing. For
// large files, the originalText path below is much faster.
const printedAst = await print(ast)

// originalText still selects the source-text fast path.
const formattedSource = await print(ast, { originalText: text })

The…