Wraps a string with parentheses if not already wrapped. Avoids adding redundant parentheses when the expression is already fully wrapped with balanced parentheses.
wrapWithParentheses('A') // '(A)'wrapWithParentheses('(A)') // '(A)' (not '((A))')wrapWithParentheses('A | B') // '(A | B)'wrapWithParentheses('(A | B)') // '(A | B)' (not '((A | B))')wrapWithParentheses('(A) | (B)') // '((A) | (B))' (needs outer parens) Copy
wrapWithParentheses('A') // '(A)'wrapWithParentheses('(A)') // '(A)' (not '((A))')wrapWithParentheses('A | B') // '(A | B)'wrapWithParentheses('(A | B)') // '(A | B)' (not '((A | B))')wrapWithParentheses('(A) | (B)') // '((A) | (B))' (needs outer parens)
Wraps a string with parentheses if not already wrapped. Avoids adding redundant parentheses when the expression is already fully wrapped with balanced parentheses.