UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

78 lines (77 loc) 2.45 kB
/** * DevExtreme (cjs/file_management/utils.js) * Version: 23.2.6 * Build date: Wed May 01 2024 * * Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ "use strict"; 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.substr(index) : "" }; exports.getFileExtension = getFileExtension; const getName = path => { const index = path.lastIndexOf("/"); return -1 !== index ? path.substr(index + "/".length) : path }; exports.getName = getName; const getParentPath = path => { const index = path.lastIndexOf("/"); return -1 !== index ? path.substr(0, index) : "" }; exports.getParentPath = getParentPath; const getPathParts = (path, includeFullPath) => { if (!path || "/" === path) { return [] } const result = []; let pathPart = ""; for (let i = 0; i < path.length; i++) { let char = path.charAt(i); if ("/" === char) { const nextChar = path.charAt(i + 1); if ("/" !== nextChar) { if (pathPart) { result.push(pathPart); pathPart = "" } char = nextChar } i++ } pathPart += char } if (pathPart) { result.push(pathPart) } if (includeFullPath) { for (let i = 0; i < result.length; i++) { result[i] = pathCombine(0 === i ? "" : result[i - 1], getEscapedFileName(result[i])) } } return result }; exports.getPathParts = getPathParts; const getEscapedFileName = function(fileName) { return fileName.replace(/\/{1,1}/g, "//") }; exports.getEscapedFileName = getEscapedFileName; const pathCombine = function() { let result = ""; (0, _iterator.each)(arguments, (_, arg) => { if (arg) { if (result) { result += "/" } result += arg } }); return result }; exports.pathCombine = pathCombine;