MCPcopy Create free account
hub / github.com/Snapchat/Valdi / normalizePath

Function normalizePath

src/valdi_modules/src/valdi/valdi_core/src/ModuleLoader.ts:24–43  ·  view source on GitHub ↗
(pathEntries: string[])

Source from the content-addressed store, hash-verified

22const IS_WEB =
23 (typeof window !== 'undefined' && typeof window.document !== 'undefined') ||
24 typeof (globalThis as { importScripts?: unknown }).importScripts === 'function';
25interface ResolvedPath {
26 absolutePath: string;
27 directoryPaths: string[];
28}
29
30function normalizePath(pathEntries: string[]): string[] {
31 const out: string[] = [];
32 for (const pathEntry of pathEntries) {
33 if (pathEntry === '..') {
34 if (out.length) {
35 // Remove last item
36 out.pop();
37 } else {
38 // Keep the '..' we went outside our root
39 out.push(pathEntry);
40 }
41 } else if (pathEntry === '.' && !IS_WEB) {
42 // Omit '.' from the path on Android (1), iOS (2), MacOS (3). On Web (4) keep '.' in the path.
43 continue;
44 } else {
45 out.push(pathEntry);
46 }

Callers 2

resolvePathFunction · 0.85

Calls 3

popMethod · 0.65
getCurrentPlatformMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected