(str: string | Array<string | number>)
| 152 | * @private |
| 153 | */ |
| 154 | export function makePathArray(str: string | Array<string | number>) { |
| 155 | if (Array.isArray(str)) { |
| 156 | return [...str] |
| 157 | } |
| 158 | |
| 159 | if (typeof str !== 'string') { |
| 160 | throw new Error('Path must be a string.') |
| 161 | } |
| 162 | |
| 163 | return ( |
| 164 | str |
| 165 | // Leading `[` may lead to wrong parsing down the line |
| 166 | // (Example: '[0][1]' should be '0.1', not '.0.1') |
| 167 | .replace(/(^\[)|]/gm, '') |
| 168 | .replace(/\[/g, '.') |
| 169 | .replace(reLineOfOnlyDigits, intReplace) |
| 170 | .replace(reDigitsBetweenDots, `.${intReplace}.`) |
| 171 | .replace(reStartWithDigitThenDot, `${intReplace}.`) |
| 172 | .replace(reDotWithDigitsToEnd, `.${intReplace}`) |
| 173 | .replace(reMultipleDots, '.') |
| 174 | .split('.') |
| 175 | .map((d) => { |
| 176 | if (d.startsWith(intPrefix)) { |
| 177 | const numStr = d.substring(intPrefix.length) |
| 178 | const num = parseInt(numStr, 10) |
| 179 | |
| 180 | if (String(num) === numStr) { |
| 181 | return num |
| 182 | } |
| 183 | return numStr |
| 184 | } |
| 185 | return d |
| 186 | }) |
| 187 | ) |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * @private |
no outgoing calls
no test coverage detected