MCPcopy
hub / github.com/stenciljs/core / normalizePath

Function normalizePath

src/utils/path.ts:12–38  ·  view source on GitHub ↗
(path: string, relativize = true)

Source from the content-addressed store, hash-verified

10 * @returns the converted path
11 */
12export const normalizePath = (path: string, relativize = true): string => {
13 if (typeof path !== 'string') {
14 throw new Error(`invalid path to normalize`);
15 }
16 path = normalizeSlashes(path.trim());
17
18 const components = pathComponents(path, getRootLength(path));
19 const reducedComponents = reducePathComponents(components);
20 const rootPart = reducedComponents[0];
21 const secondPart = reducedComponents[1];
22 const normalized = rootPart + reducedComponents.slice(1).join('/');
23
24 if (normalized === '') {
25 return '.';
26 }
27 if (
28 rootPart === '' &&
29 secondPart &&
30 path.includes('/') &&
31 !secondPart.startsWith('.') &&
32 !secondPart.startsWith('@') &&
33 relativize
34 ) {
35 return './' + normalized;
36 }
37 return normalized;
38};
39
40const normalizeSlashes = (path: string) => path.replace(backslashRegExp, '/');
41

Callers 15

path.spec.tsFile · 0.90
publishBuildMethod · 0.85
compareScreenshotFunction · 0.85
startServerFunction · 0.85
normalizeHttpRequestFunction · 0.85
normalizeFsPathFunction · 0.85
normalizeFsPathQueryFunction · 0.85

Calls 5

normalizeSlashesFunction · 0.85
pathComponentsFunction · 0.85
getRootLengthFunction · 0.85
reducePathComponentsFunction · 0.85
joinMethod · 0.80

Tested by 2

setupFunction · 0.68
pathTransformTranspileFunction · 0.68