UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

72 lines (71 loc) 2.17 kB
/** * DevExtreme (esm/__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/ */ import { each } from "../../core/utils/iterator"; export const PATH_SEPARATOR = "/"; export const getFileExtension = path => { const index = path.lastIndexOf("."); return -1 !== index ? path.substring(index) : "" }; export const getName = path => { const index = path.lastIndexOf("/"); return -1 !== index ? path.substring(index + 1) : path }; export const getParentPath = path => { const index = path.lastIndexOf("/"); return -1 !== index ? path.substring(0, index) : "" }; export const getEscapedFileName = fileName => fileName.replace(/\/{1,1}/g, "//"); export const pathCombine = function() { let result = ""; for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key] } each(args, ((_, arg) => { if (arg) { if (result) { result += "/" } result += arg } })); return result }; export 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) { const nextChar = path.charAt(i + 1); if ("/" !== nextChar) { 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 };