UNPKG

1.1 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports.withBasePath = withBasePath;
5exports.withTrailingSlash = withTrailingSlash;
6exports.getCommonDir = getCommonDir;
7
8const path = require(`path`);
9
10const {
11 joinPath
12} = require(`gatsby-core-utils`);
13
14function withBasePath(basePath) {
15 return (...paths) => joinPath(basePath, ...paths);
16}
17
18function withTrailingSlash(basePath) {
19 return `${basePath}/`;
20}
21
22const posixJoinWithLeadingSlash = paths => path.posix.join(...paths.map((segment, index) => segment === `` && index === 0 ? `/` : segment));
23
24function getCommonDir(path1, path2) {
25 const path1Segments = path1.split(/[/\\]/);
26 const path2Segments = path2.split(/[/\\]/);
27
28 for (let i = 0; i < path1Segments.length; i++) {
29 if (i >= path2Segments.length) {
30 return posixJoinWithLeadingSlash(path2Segments);
31 } else if (path1Segments[i].toLowerCase() !== path2Segments[i].toLowerCase()) {
32 const joined = path1Segments.slice(0, i);
33 return posixJoinWithLeadingSlash(joined);
34 }
35 }
36
37 return posixJoinWithLeadingSlash(path1Segments);
38}
39//# sourceMappingURL=path.js.map
\No newline at end of file