MCPcopy Create free account
hub / github.com/browserify/crypto-browserify / normalizeArray

Function normalizeArray

example/bundle.js:218–242  ·  view source on GitHub ↗
(parts, allowAboveRoot)

Source from the content-addressed store, hash-verified

216 // (so also no leading and trailing slashes - it does not distinguish
217 // relative and absolute paths)
218 function normalizeArray(parts, allowAboveRoot) {
219 // if the path tries to go above the root, `up` ends up > 0
220 var up = 0;
221 for (var i = parts.length; i >= 0; i--) {
222 var last = parts[i];
223 if (last == '.') {
224 parts.splice(i, 1);
225 } else if (last === '..') {
226 parts.splice(i, 1);
227 up++;
228 } else if (up) {
229 parts.splice(i, 1);
230 up--;
231 }
232 }
233
234 // if the path is allowed to go above the root, restore leading ..s
235 if (allowAboveRoot) {
236 for (; up--; up) {
237 parts.unshift('..');
238 }
239 }
240
241 return parts;
242 }
243
244 // Regex to split a filename into [*, dir, basename, ext]
245 // posix version

Callers 1

bundle.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…