UNPKG

861 BJavaScriptView Raw
1// tooling
2import { list } from 'postcss';
3
4// return '(hello), (goodbye)' as [[hello], [goodbye]]
5export default function getArrayedString(string, useSingleValue) {
6 // the string as an array
7 const stringArray = getCommaSplitString(string).map(
8 substring => matchWrappingParens.test(substring) ? getArrayedString(getStringWithoutWrappingParentheses(substring), false) : substring
9 );
10
11 // the string array or its first item
12 const returnValue = useSingleValue && 1 === stringArray.length ? stringArray[0] : stringArray;
13
14 return returnValue;
15}
16
17// return string split by commas
18const getCommaSplitString = string => list.comma(string);
19
20// return string without wrapping parentheses
21const getStringWithoutWrappingParentheses = string => string.replace(matchWrappingParens, '$1');
22
23// matching wrapping parentheses
24const matchWrappingParens = /^\((.*)\)$/g;