/strip-brackets

Strips unecessary brackets

Primary LanguageJavaScript

strip-brackets

Strips unecessary brackets

Greenkeeper badge

Usage

Pass it some configuration parameters and it will give you a new function that strips all unnecessary brackets.

Function Signature

stripBrackets(openChar = '[', closeChar = ']', joinChars = [',']) => input => output
import stripBrackets from 'strip-brackets';

const stripSquareBrackets = stripBrackets('[', ']', [',']);
stripSquareBrackets('[[a,b],[c],[[d]]]'); // => "[a,b],c,d"

const stripParens = stripBrackets('(', ')', [',']);
stripParens('((a,b),(c),((d)))'); // => "(a,b),c,d"

Parameters

openChar
The opening bracket. Default: `[`
closeChar
The closing bracket. Default: `]`
joinChars
Characters that indicate that the current part of the string should be wrapped in brackets. Default: `[","]`
input
The string you want to strip brackets from
output
The resulting string, with unnecessary brackets removed