MCPcopy Create free account
hub / github.com/angular/angular / computeNavigation

Function computeNavigation

packages/router/src/create_url_tree.ts:273–322  ·  view source on GitHub ↗

Transforms commands to a normalized `Navigation`

(commands: readonly any[])

Source from the content-addressed store, hash-verified

271
272/** Transforms commands to a normalized `Navigation` */
273function computeNavigation(commands: readonly any[]): Navigation {
274 if (typeof commands[0] === 'string' && commands.length === 1 && commands[0] === '/') {
275 return new Navigation(true, 0, commands);
276 }
277
278 let numberOfDoubleDots = 0;
279 let isAbsolute = false;
280
281 const res: any[] = commands.reduce((res, cmd, cmdIdx) => {
282 if (typeof cmd === 'object' && cmd != null) {
283 if (cmd.outlets) {
284 const outlets: {[k: string]: any} = {};
285 Object.entries(cmd.outlets).forEach(([name, commands]) => {
286 outlets[name] = typeof commands === 'string' ? commands.split('/') : commands;
287 });
288 return [...res, {outlets}];
289 }
290
291 if (cmd.segmentPath) {
292 return [...res, cmd.segmentPath];
293 }
294 }
295
296 if (!(typeof cmd === 'string')) {
297 return [...res, cmd];
298 }
299
300 if (cmdIdx === 0) {
301 cmd.split('/').forEach((urlPart, partIndex) => {
302 if (partIndex == 0 && urlPart === '.') {
303 // skip './a'
304 } else if (partIndex == 0 && urlPart === '') {
305 // '/a'
306 isAbsolute = true;
307 } else if (urlPart === '..') {
308 // '../a'
309 numberOfDoubleDots++;
310 } else if (urlPart != '') {
311 res.push(urlPart);
312 }
313 });
314
315 return res;
316 }
317
318 return [...res, cmd];
319 }, []);
320
321 return new Navigation(isAbsolute, numberOfDoubleDots, res);
322}
323
324class Position {
325 constructor(

Callers 1

Calls 4

reduceMethod · 0.80
forEachMethod · 0.45
entriesMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected