UNPKG

1.07 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.joinPath = exports.pathParts = exports.normalizePath = void 0;
4/** @hidden
5 * Removes leading and trailing slashes from a path.
6 *
7 * @param path A path to normalize, in POSIX format.
8 */
9function normalizePath(path) {
10 if (!path) {
11 return "";
12 }
13 return path.replace(/^\//, "").replace(/\/$/, "");
14}
15exports.normalizePath = normalizePath;
16/**
17 * Normalizes a given path and splits it into an array of segments.
18 *
19 * @param path A path to split, in POSIX format.
20 */
21function pathParts(path) {
22 if (!path || path === "" || path === "/") {
23 return [];
24 }
25 return normalizePath(path).split("/");
26}
27exports.pathParts = pathParts;
28/**
29 * Normalizes given paths and joins these together using a POSIX separator.
30 *
31 * @param base A first path segment, in POSIX format.
32 * @param child A second path segment, in POSIX format.
33 */
34function joinPath(base, child) {
35 return pathParts(base).concat(pathParts(child)).join("/");
36}
37exports.joinPath = joinPath;