MCPcopy Index your code
hub / github.com/deployd/deployd / normalizeArray

Function normalizeArray

lib/internal-client.js:4–28  ·  view source on GitHub ↗
(parts, allowAboveRoot)

Source from the content-addressed store, hash-verified

2 , Promise = require('bluebird');
3
4function normalizeArray(parts, allowAboveRoot) {
5 // if the path tries to go above the root, `up` ends up > 0
6 var up = 0;
7 for (var i = parts.length - 1; i >= 0; i--) {
8 var last = parts[i];
9 if (last == '.') {
10 parts.splice(i, 1);
11 } else if (last === '..') {
12 parts.splice(i, 1);
13 up++;
14 } else if (up) {
15 parts.splice(i, 1);
16 up--;
17 }
18 }
19
20 // if the path is allowed to go above the root, restore leading ..s
21 if (allowAboveRoot) {
22 for (; up--; up) {
23 parts.unshift('..');
24 }
25 }
26
27 return parts;
28}
29
30var normalizePath = function(path) {
31 var isAbsolute = path.charAt(0) === '/',

Callers 1

normalizePathFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected