You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openNG/build/core/split-path.js

28 lines
822 B
JavaScript

"use strict";
const path = require("path");
let platformDoubleSlashMatcher;
if (path.sep === "\\") {
/* Special case; even within a regex literal, a backslash still needs to be escaped itself. */
platformDoubleSlashMatcher = /\\+/g;
} else {
/* See: https://stackoverflow.com/questions/4547609/how-do-you-get-a-string-to-a-character-array-in-javascript/34717402#34717402 */
let escapedSeparator = Array.from(path.sep).map((character) => `\\${character}`).join("");
platformDoubleSlashMatcher = new RegExp(`(${escapedSeparator})+`, "g");
}
module.exports = function splitPath(targetPath, normalize = true) {
let normalized;
if (normalize) {
normalized = path.normalize(targetPath);
} else {
normalized = targetPath.replace(platformDoubleSlashMatcher, path.sep);
}
return normalized.split(path.sep);
};