MCPcopy Create free account
hub / github.com/Marus/cortex-debug / valueOf

Method valueOf

src/backend/mi_parse.ts:63–122  ·  view source on GitHub ↗
(start: any, path: string)

Source from the content-addressed store, hash-verified

61 public output: string = '';
62
63 public static valueOf(start: any, path: string): any {
64 if (!start) {
65 return undefined;
66 }
67 const pathRegex = /^\.?([a-zA-Z_\-][a-zA-Z0-9_\-]*)/;
68 const indexRegex = /^\[(\d+)\](?:$|\.)/;
69 path = path.trim();
70 if (!path) { return start; }
71 let current = start;
72 do {
73 let target = pathRegex.exec(path);
74 if (target) {
75 path = path.substr(target[0].length);
76 if (current.length && typeof current !== 'string') {
77 const found = [];
78 for (const element of current) {
79 if (element[0] === target[1]) {
80 found.push(element[1]);
81 }
82 }
83 if (found.length > 1) {
84 current = found;
85 }
86 else if (found.length === 1) {
87 current = found[0];
88 }
89 else {
90 return undefined;
91 }
92 }
93 else {
94 return undefined;
95 }
96 }
97 else if (path[0] === '@') {
98 current = [current];
99 path = path.substr(1);
100 }
101 else {
102 target = indexRegex.exec(path);
103 if (target) {
104 path = path.substr(target[0].length);
105 const i = parseInt(target[1]);
106 if (current.length && typeof current !== 'string' && i >= 0 && i < current.length) {
107 current = current[i];
108 }
109 else if (i === 0) {
110 }
111 else {
112 return undefined;
113 }
114 }
115 else {
116 return undefined;
117 }
118 }
119 path = path.trim();
120 } while (path);

Callers 15

mi_parse.test.tsFile · 0.80
threadsRequestMethod · 0.80
doitMethod · 0.80
doitMethod · 0.80
parseIntructionMethod · 0.80
recordMethod · 0.80
resultMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected