a2bei4-utils 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/a2bei4.utils.cjs.js +7 -4
- package/dist/a2bei4.utils.cjs.js.map +1 -1
- package/dist/a2bei4.utils.cjs.min.js +1 -1
- package/dist/a2bei4.utils.cjs.min.js.map +1 -1
- package/dist/a2bei4.utils.esm.js +7 -4
- package/dist/a2bei4.utils.esm.js.map +1 -1
- package/dist/a2bei4.utils.esm.min.js +1 -1
- package/dist/a2bei4.utils.esm.min.js.map +1 -1
- package/dist/a2bei4.utils.umd.js +7 -4
- package/dist/a2bei4.utils.umd.js.map +1 -1
- package/dist/a2bei4.utils.umd.min.js +1 -1
- package/dist/a2bei4.utils.umd.min.js.map +1 -1
- package/dist/download.cjs +3 -0
- package/dist/download.cjs.map +1 -1
- package/dist/download.js +3 -0
- package/dist/download.js.map +1 -1
- package/dist/tree.cjs +4 -4
- package/dist/tree.cjs.map +1 -1
- package/dist/tree.js +4 -4
- package/dist/tree.js.map +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +11 -1
- package/types/tree.d.ts +11 -1
package/dist/a2bei4.utils.cjs.js
CHANGED
|
@@ -1224,6 +1224,9 @@ async function fetchOrDownloadByUrl(url, fileName) {
|
|
|
1224
1224
|
const urlPathname = new URL(url).pathname;
|
|
1225
1225
|
// 获取路径的最后一部分作为文件名,并移除可能的查询参数
|
|
1226
1226
|
fileName = urlPathname.substring(urlPathname.lastIndexOf("/") + 1).split("?")[0];
|
|
1227
|
+
if (fileName) {
|
|
1228
|
+
fileName = decodeURIComponent(fileName);
|
|
1229
|
+
}
|
|
1227
1230
|
} catch (e) {}
|
|
1228
1231
|
// 如果提取后文件名为空(例如 URL 以 '/' 结尾),也使用时间戳
|
|
1229
1232
|
if (!fileName) {
|
|
@@ -1794,23 +1797,23 @@ function flatCompleteTree2NestedTree(nodes, parentId = 0, { idKey = "id", parent
|
|
|
1794
1797
|
* @param {T[]} arr - 嵌套树森林
|
|
1795
1798
|
* @param {string} [idKey='id'] - 主键字段
|
|
1796
1799
|
* @param {string} [childrenKey='children'] - 子节点字段
|
|
1797
|
-
* @returns {
|
|
1800
|
+
* @returns {T | undefined} 找到的节点;未找到返回 `undefined`
|
|
1798
1801
|
*/
|
|
1799
|
-
|
|
1802
|
+
function findTreeNodeById(id, arr, idKey = "id", childrenKey = "children") {
|
|
1800
1803
|
if (Array.isArray(arr) && arr.length > 0) {
|
|
1801
1804
|
for (let i = 0; i < arr.length; i++) {
|
|
1802
1805
|
const item = arr[i];
|
|
1803
1806
|
if (item[idKey]?.toString() === id?.toString()) {
|
|
1804
1807
|
return item;
|
|
1805
1808
|
} else if (Array.isArray(item[childrenKey]) && item[childrenKey].length > 0) {
|
|
1806
|
-
const result =
|
|
1809
|
+
const result = findTreeNodeById(id, item[childrenKey], idKey, childrenKey);
|
|
1807
1810
|
if (result) {
|
|
1808
1811
|
return result;
|
|
1809
1812
|
}
|
|
1810
1813
|
}
|
|
1811
1814
|
}
|
|
1812
1815
|
}
|
|
1813
|
-
}
|
|
1816
|
+
}
|
|
1814
1817
|
|
|
1815
1818
|
/**
|
|
1816
1819
|
* 在嵌套树中按 `id` 递归查找节点,并返回其指定属性值。
|