MCPcopy Index your code
hub / github.com/nodejs/node / reducePathComponents

Function reducePathComponents

test/fixtures/snapshot/typescript.js:7879–7902  ·  view source on GitHub ↗

* Reduce an array of path components to a more simplified path by navigating any * `"."` or `".."` entries in the path.

(components)

Source from the content-addressed store, hash-verified

7877 * `"."` or `".."` entries in the path.
7878 */
7879 function reducePathComponents(components) {
7880 if (!ts.some(components))
7881 return [];
7882 var reduced = [components[0]];
7883 for (var i = 1; i < components.length; i++) {
7884 var component = components[i];
7885 if (!component)
7886 continue;
7887 if (component === ".")
7888 continue;
7889 if (component === "..") {
7890 if (reduced.length > 1) {
7891 if (reduced[reduced.length - 1] !== "..") {
7892 reduced.pop();
7893 continue;
7894 }
7895 }
7896 else if (reduced[0])
7897 continue;
7898 }
7899 reduced.push(component);
7900 }
7901 return reduced;
7902 }
7903 ts.reducePathComponents = reducePathComponents;
7904 /**
7905 * Combines paths. If a path is absolute, it replaces any previous path. Relative paths are not simplified.

Callers 5

normalizePathFunction · 0.85
comparePathsWorkerFunction · 0.85
containsPathFunction · 0.85

Calls 3

someMethod · 0.80
popMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…