devextreme
Version:
HTML5 JavaScript Component Suite for Responsive Web Development
80 lines (79 loc) • 2.72 kB
JavaScript
/**
* DevExtreme (cjs/__internal/file_management/utils.js)
* Version: 25.2.3
* Build date: Fri Dec 12 2025
*
* Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.pathCombine = exports.getPathParts = exports.getParentPath = exports.getName = exports.getFileExtension = exports.getEscapedFileName = exports.PATH_SEPARATOR = void 0;
var _iterator = require("../../core/utils/iterator");
const PATH_SEPARATOR = exports.PATH_SEPARATOR = "/";
const getFileExtension = path => {
const index = path.lastIndexOf(".");
return -1 !== index ? path.substring(index) : ""
};
exports.getFileExtension = getFileExtension;
const getName = path => {
const index = path.lastIndexOf(PATH_SEPARATOR);
return -1 !== index ? path.substring(index + PATH_SEPARATOR.length) : path
};
exports.getName = getName;
const getParentPath = path => {
const index = path.lastIndexOf(PATH_SEPARATOR);
return -1 !== index ? path.substring(0, index) : ""
};
exports.getParentPath = getParentPath;
const getEscapedFileName = fileName => fileName.replace(/\/{1,1}/g, "//");
exports.getEscapedFileName = getEscapedFileName;
const pathCombine = function() {
let result = "";
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key]
}(0, _iterator.each)(args, ((_, arg) => {
if (arg) {
if (result) {
result += PATH_SEPARATOR
}
result += arg
}
}));
return result
};
exports.pathCombine = pathCombine;
const getPathParts = (path, includeFullPath) => {
if (!path || "/" === path) {
return []
}
const result = [];
let pathPart = "";
for (let i = 0; i < path.length; i += 1) {
let char = path.charAt(i);
if (char === PATH_SEPARATOR) {
const nextChar = path.charAt(i + 1);
if (nextChar !== PATH_SEPARATOR) {
if (pathPart) {
result.push(pathPart);
pathPart = ""
}
char = nextChar
}
i += 1
}
pathPart += char
}
if (pathPart) {
result.push(pathPart)
}
if (includeFullPath) {
for (let i = 0; i < result.length; i += 1) {
result[i] = pathCombine(0 === i ? "" : result[i - 1], getEscapedFileName(result[i]))
}
}
return result
};
exports.getPathParts = getPathParts;