Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

parenthesis

Package Overview
Dependencies
Maintainers
2
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parenthesis

Parse parentheses from a string

  • 3.1.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

parenthesis Build Status

Parse parentheses from a string, return folded arrays.

npm install parenthesis

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.

OptionDefaultMeaning
brackets['{}', '[]', '()']Single brackets string or list of strings to detect brackets. Can be repeating brackets eg. "" or ''.
escape'___'Escape prefix for flat references.
flatfalseReturn flat array instead of nested arrays.

str = paren.stringify(tokens, {flat}?)

Stringify tokens back. Pass {flat: true} flag for flat tokens array.

License

© 2018 Dmitry Yv. MIT License

Keywords

FAQs

Package last updated on 20 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc