1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/path-parse/index.js

76 lines
1.8 KiB
JavaScript
Raw Permalink Normal View History

2023-12-18 13:12:25 +08:00
'use strict';
var isWindows = process.platform === 'win32';
2023-12-28 23:41:32 +08:00
// Regex to split a windows path into into [dir, root, basename, name, ext]
var splitWindowsRe =
/^(((?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?[\\\/]?)(?:[^\\\/]*[\\\/])*)((\.{1,2}|[^\\\/]+?|)(\.[^.\/\\]*|))[\\\/]*$/;
2023-12-18 13:12:25 +08:00
var win32 = {};
function win32SplitPath(filename) {
2023-12-28 23:41:32 +08:00
return splitWindowsRe.exec(filename).slice(1);
2023-12-18 13:12:25 +08:00
}
win32.parse = function(pathString) {
if (typeof pathString !== 'string') {
throw new TypeError(
"Parameter 'pathString' must be a string, not " + typeof pathString
);
}
var allParts = win32SplitPath(pathString);
2023-12-28 23:41:32 +08:00
if (!allParts || allParts.length !== 5) {
2023-12-18 13:12:25 +08:00
throw new TypeError("Invalid path '" + pathString + "'");
}
return {
2023-12-28 23:41:32 +08:00
root: allParts[1],
dir: allParts[0] === allParts[1] ? allParts[0] : allParts[0].slice(0, -1),
2023-12-18 13:12:25 +08:00
base: allParts[2],
2023-12-28 23:41:32 +08:00
ext: allParts[4],
name: allParts[3]
2023-12-18 13:12:25 +08:00
};
};
2023-12-28 23:41:32 +08:00
// Split a filename into [dir, root, basename, name, ext], unix version
2023-12-18 13:12:25 +08:00
// 'root' is just a slash, or nothing.
var splitPathRe =
2023-12-28 23:41:32 +08:00
/^((\/?)(?:[^\/]*\/)*)((\.{1,2}|[^\/]+?|)(\.[^.\/]*|))[\/]*$/;
2023-12-18 13:12:25 +08:00
var posix = {};
function posixSplitPath(filename) {
return splitPathRe.exec(filename).slice(1);
}
posix.parse = function(pathString) {
if (typeof pathString !== 'string') {
throw new TypeError(
"Parameter 'pathString' must be a string, not " + typeof pathString
);
}
var allParts = posixSplitPath(pathString);
2023-12-28 23:41:32 +08:00
if (!allParts || allParts.length !== 5) {
2023-12-18 13:12:25 +08:00
throw new TypeError("Invalid path '" + pathString + "'");
}
2023-12-28 23:41:32 +08:00
2023-12-18 13:12:25 +08:00
return {
2023-12-28 23:41:32 +08:00
root: allParts[1],
dir: allParts[0].slice(0, -1),
2023-12-18 13:12:25 +08:00
base: allParts[2],
2023-12-28 23:41:32 +08:00
ext: allParts[4],
name: allParts[3],
2023-12-18 13:12:25 +08:00
};
};
if (isWindows)
module.exports = win32.parse;
else /* posix */
module.exports = posix.parse;
module.exports.posix = posix.parse;
module.exports.win32 = win32.parse;