MCPcopy
hub / github.com/louischatriot/nedb / normalizeArray

Function normalizeArray

browser-version/out/nedb.js:211–235  ·  view source on GitHub ↗
(parts, allowAboveRoot)

Source from the content-addressed store, hash-verified

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

Callers 1

nedb.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…