MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / normalize

Function normalize

src/utils/Path.js:94–112  ·  view source on GitHub ↗

* Normalizes the given path, resolving '..' and '.' segments. * @param {string} path

(path)

Source from the content-addressed store, hash-verified

92 * @param {string} path
93 */
94 normalize(path) {
95 path = path.replace(/\.\/+/g, "./");
96 path = path.replace(/\/+/g, "/");
97
98 const resolved = [];
99 const pathAr = path.split("/");
100
101 pathAr.forEach((dir) => {
102 if (dir === "..") {
103 if (resolved.length) resolved.pop();
104 } else if (dir === ".") {
105 return;
106 } else {
107 resolved.push(dir);
108 }
109 });
110
111 return resolved.join("/");
112 },
113
114 /**
115 *

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected