MCPcopy
hub / github.com/QwikDev/qwik / createPath

Function createPath

packages/qwik/src/optimizer/src/path.ts:24–629  ·  view source on GitHub ↗
(opts: { cwd?: () => string } = {})

Source from the content-addressed store, hash-verified

22// USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24export function createPath(opts: { cwd?: () => string } = {}): Path {
25 function assertPath(path: any) {
26 if (typeof path !== 'string') {
27 throw new TypeError('Path must be a string. Received ' + JSON.stringify(path));
28 }
29 }
30
31 // Resolves . and .. elements in a path with directory names
32 function normalizeStringPosix(path: string, allowAboveRoot: boolean): string {
33 let res = '';
34 let lastSegmentLength = 0;
35 let lastSlash = -1;
36 let dots = 0;
37 let code;
38 for (let i = 0; i <= path.length; ++i) {
39 if (i < path.length) {
40 code = path.charCodeAt(i);
41 } else if (code === 47 /*/*/) {
42 break;
43 } else {
44 code = 47 /*/*/;
45 }
46 if (code === 47 /*/*/) {
47 if (lastSlash === i - 1 || dots === 1) {
48 // NOOP
49 } else if (lastSlash !== i - 1 && dots === 2) {
50 if (
51 res.length < 2 ||
52 lastSegmentLength !== 2 ||
53 res.charCodeAt(res.length - 1) !== 46 /*.*/ ||
54 res.charCodeAt(res.length - 2) !== 46 /*.*/
55 ) {
56 if (res.length > 2) {
57 const lastSlashIndex = res.lastIndexOf('/');
58 if (lastSlashIndex !== res.length - 1) {
59 if (lastSlashIndex === -1) {
60 res = '';
61 lastSegmentLength = 0;
62 } else {
63 res = res.slice(0, lastSlashIndex);
64 lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
65 }
66 lastSlash = i;
67 dots = 0;
68 continue;
69 }
70 } else if (res.length === 2 || res.length === 1) {
71 res = '';
72 lastSegmentLength = 0;
73 lastSlash = i;
74 dots = 0;
75 continue;
76 }
77 }
78 if (allowAboveRoot) {
79 if (res.length > 0) {
80 res += '/..';
81 } else {

Callers 1

getSystemFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…