MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / pathSegments

Function pathSegments

src/resolution/frameworks/angular-router.ts:168–200  ·  view source on GitHub ↗

A route's own path segment(s): a string, a `$localize` default, or a constant kept as `{expr}`; null when it cannot be named.

(text: string)

Source from the content-addressed store, hash-verified

166
167/** A route's own path segment(s): a string, a `$localize` default, or a constant kept as `{expr}`; null when it cannot be named. */
168function pathSegments(text: string): string[] | null {
169 const trimmed = text.trim();
170 const value = staticString(trimmed);
171 if (value !== null) {
172 if (value.includes('**')) return null;
173 return value.split('/').filter((s) => s.length > 0);
174 }
175 if (CONSTANT_PATH.test(trimmed)) return [`{${trimmed.replace(/\s+/g, '')}}`];
176 // `` `issue/:${ProjectConst.IssueId}` ``: a template whose holes are constants.
177 if (trimmed.startsWith('`') && skipString(trimmed, 0) === trimmed.length - 1) {
178 let ok = true;
179 const body = trimmed.slice(1, -1).replace(/\$\{([^}]*)\}/g, (_all, hole: string) => {
180 if (!CONSTANT_PATH.test(hole.trim())) ok = false;
181 return `{${hole.replace(/\s+/g, '')}}`;
182 });
183 if (ok && !body.includes('**')) return body.split('/').filter((seg) => seg.length > 0);
184 return null;
185 }
186 // `internalRoutes.account.subRoutes.access.path + '/:id'`: each part a
187 // string or a constant, the constant a whole segment of its own.
188 if (trimmed.includes('+')) {
189 const joined: string[] = [];
190 for (const part of splitPlus(trimmed)) {
191 const literal = staticString(part);
192 if (literal !== null) joined.push(literal);
193 else if (CONSTANT_PATH.test(part.trim())) joined.push(`{${part.trim().replace(/\s+/g, '')}}`);
194 else return null;
195 }
196 const value = joined.join('');
197 return value.includes('**') ? null : value.split('/').filter((seg) => seg.length > 0);
198 }
199 return null;
200}
201
202/** An expression's `+` operands at depth 0, strings and brackets stepped over. */
203function splitPlus(text: string): string[] {

Callers 1

walkFunction · 0.85

Calls 5

skipStringFunction · 0.90
staticStringFunction · 0.85
splitPlusFunction · 0.85
pushMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected