* Normalizes the given path, resolving '..' and '.' segments. * @param {string} path
(path)
| 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 | * |
nothing calls this directly
no outgoing calls
no test coverage detected