MCPcopy
hub / github.com/flightcontrolhq/superjson / parsePath

Function parsePath

src/pathstringifier.ts:13–52  ·  view source on GitHub ↗
(string: StringifiedPath, legacyPaths: boolean)

Source from the content-addressed store, hash-verified

11 .join('.');
12
13export 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};

Callers 4

traverseFunction · 0.85
applyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…