MCPcopy
hub / github.com/react/create-react-app / normalizeArray

Function normalizeArray

packages/react-error-overlay/fixtures/bundle_u.mjs:26931–26955  ·  view source on GitHub ↗
(parts, allowAboveRoot)

Source from the content-addressed store, hash-verified

26929// (so also no leading and trailing slashes - it does not distinguish
26930// relative and absolute paths)
26931function normalizeArray(parts, allowAboveRoot) {
26932 // if the path tries to go above the root, `up` ends up > 0
26933 var up = 0;
26934 for (var i = parts.length - 1; i >= 0; i--) {
26935 var last = parts[i];
26936 if (last === '.') {
26937 parts.splice(i, 1);
26938 } else if (last === '..') {
26939 parts.splice(i, 1);
26940 up++;
26941 } else if (up) {
26942 parts.splice(i, 1);
26943 up--;
26944 }
26945 }
26946
26947 // if the path is allowed to go above the root, restore leading ..s
26948 if (allowAboveRoot) {
26949 for (; up--; up) {
26950 parts.unshift('..');
26951 }
26952 }
26953
26954 return parts;
26955}
26956
26957// Split a filename into [root, dir, basename, ext], unix version
26958// 'root' is just a slash, or nothing.

Callers 1

bundle_u.mjsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected