(string: StringifiedPath, legacyPaths: boolean)
| 11 | .join('.'); |
| 12 | |
| 13 | export const parsePath = (string: StringifiedPath, legacyPaths: boolean) => { |
| 14 | const result: string[] = []; |
| 15 | |
| 16 | let segment = ''; |
| 17 | for (let i = 0; i < string.length; i++) { |
| 18 | let char = string.charAt(i); |
| 19 | |
| 20 | if (!legacyPaths && char === '\\') { |
| 21 | const escaped = string.charAt(i + 1); |
| 22 | if (escaped === '\\') { |
| 23 | segment += '\\'; |
| 24 | i++; |
| 25 | continue; |
| 26 | } else if (escaped !== '.') { |
| 27 | throw Error('invalid path'); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | const isEscapedDot = char === '\\' && string.charAt(i + 1) === '.'; |
| 32 | if (isEscapedDot) { |
| 33 | segment += '.'; |
| 34 | i++; |
| 35 | continue; |
| 36 | } |
| 37 | |
| 38 | const isEndOfSegment = char === '.'; |
| 39 | if (isEndOfSegment) { |
| 40 | result.push(segment); |
| 41 | segment = ''; |
| 42 | continue; |
| 43 | } |
| 44 | |
| 45 | segment += char; |
| 46 | } |
| 47 | |
| 48 | const lastSegment = segment; |
| 49 | result.push(lastSegment); |
| 50 | |
| 51 | return result; |
| 52 | }; |
no outgoing calls
no test coverage detected
searching dependent graphs…