# parenthesis

> Parse parentheses from a string

Latest version **3.1.8** (published 2021-11-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install parenthesis
pnpm add parenthesis
yarn add parenthesis
bun add parenthesis
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.8 |
| Published | 2021-11-20 |
| First published | 2014-12-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Dmitry Yv |
| Maintainers | dfcreative, dy |
| Keywords | paren, parenthesis, parse, brackets, parser, regexp, stringify, tokenizer, replace, csv, string |

## Links

- npm: https://www.npmjs.com/package/parenthesis
- Repository: https://github.com/dy/parenthesis
- Issues: https://github.com/dy/parenthesis/issues
- npm.io page: https://npm.io/package/parenthesis

## Alternatives

- [csv-to-markdown-table](https://npm.io/package/csv-to-markdown-table.md) — 47.0K weekly downloads
- [@sapphire/ratelimits](https://npm.io/package/@sapphire/ratelimits.md) — 4.4K weekly downloads
- [js-csvparser](https://npm.io/package/js-csvparser.md) — 2.0K weekly downloads
- [@adadapted/js-sdk](https://npm.io/package/@adadapted/js-sdk.md) — 251 weekly downloads
- [@grapecity/spread-sheets-sparklines](https://npm.io/package/@grapecity/spread-sheets-sparklines.md) — 103 weekly downloads

## Recent versions

- 3.1.8 (latest) — 2021-11-20
- 3.1.7 — 2019-07-25
- 3.1.6 — 2019-03-24
- 3.1.5 — 2018-05-28
- 3.1.4 — 2018-05-28
- 3.1.3 — 2016-03-27
- 3.1.2 — 2016-03-27
- 3.1.1 — 2016-03-27
- 3.1.0 — 2016-03-27
- 3.0.0 — 2016-03-27
- 2.0.0 — 2016-03-27
- 1.3.0 — 2016-03-26
- 1.2.4 — 2016-01-13
- 1.2.3 — 2014-12-14
- 1.2.2 — 2014-12-11
- … 4 more at https://npm.io/package/parenthesis/versions

## README

# parenthesis [![Build Status](https://travis-ci.org/dy/parenthesis.svg?branch=master)](https://travis-ci.org/dy/parenthesis)

Parse parentheses from a string, return folded arrays.

[![npm install parenthesis](https://nodei.co/npm/parenthesis.png?mini=true)](https://npmjs.org/package/parenthesis/)


```js
var parse = require('parenthesis')

// Parse into nested format
parse('a(b[c{d}])')
// ['a(', ['b[', ['c{', ['d'], '}'], ']'], ')']

// Parse into flat format with cross-references
parse('a(b[c{d}])', {
	brackets: ['()'],
	escape: '\\',
	flat: true
})
// ['a(\\1)', 'b[c{d}]']


// Stringify nested format
parse.stringify(['a(', ['b[', ['c{', ['d'], '}'], ']'], ')'])
// 'a(b[c{d}])'

// Stringify flat format with cross-references
parse.stringify(['a(\\1)', 'b[c{d}]'], {flat: true, escape: '\\'})
// 'a(b[c{d}])'
```

## API

### tokens = paren.parse(string, brackets|opts?)

Return array with tokens.

Option | Default | Meaning
---|---|---
`brackets` | `['{}', '[]', '()']` | Single brackets string or list of strings to detect brackets. Can be repeating brackets eg. `"" or ''`.
`escape` | `'___'` | Escape prefix for flat references.
`flat` | `false` | Return flat array instead of nested arrays.

### str = paren.stringify(tokens, {flat}?)

Stringify tokens back. Pass `{flat: true}` flag for flat tokens array.

## Related

* [balanced-match](http://npmjs.org/package/balanced-match)


## License

© 2018 Dmitry Yv. MIT License

---
_Source: https://npm.io/package/parenthesis · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
