qmwts 1.2.2 → 1.2.3
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/index.d.ts +3 -0
- package/dist/index.js +7 -1
- package/dist/utils/array-utils2.d.ts +9 -0
- package/dist/utils/array-utils2.js +61 -0
- package/dist/utils/file-utils2.d.ts +1 -0
- package/dist/utils/file-utils2.js +51 -0
- package/dist/utils/prototype-utils2.d.ts +3 -0
- package/dist/utils/prototype-utils2.js +7 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -17,3 +17,6 @@ export { default as LocalDateTime } from './class/local-date-time';
|
|
|
17
17
|
export { default as YearMonth } from './class/year-month';
|
|
18
18
|
export { sha256Hex } from './utils/digest-utils';
|
|
19
19
|
export { isNumber, thousandths, summation } from './utils/number-utils2';
|
|
20
|
+
export { findTreeNodes } from './utils/array-utils2';
|
|
21
|
+
export { prototype } from './utils/prototype-utils2';
|
|
22
|
+
export { fileType } from './utils/file-utils2';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.summation = exports.thousandths = exports.isNumber = exports.sha256Hex = exports.YearMonth = exports.LocalDateTime = exports.LocalDate = exports.StringUtils = exports.FileUtils = exports.ParamBuilder = exports.PrototypeUtils = exports.ObjectUtils = exports.JsonUtils = exports.NumberUtils = exports.Encryptor = exports.Downloader = exports.AxiosInstance = exports.FinanceUtils = exports.ArrayUtils = void 0;
|
|
3
|
+
exports.fileType = exports.prototype = exports.findTreeNodes = exports.summation = exports.thousandths = exports.isNumber = exports.sha256Hex = exports.YearMonth = exports.LocalDateTime = exports.LocalDate = exports.StringUtils = exports.FileUtils = exports.ParamBuilder = exports.PrototypeUtils = exports.ObjectUtils = exports.JsonUtils = exports.NumberUtils = exports.Encryptor = exports.Downloader = exports.AxiosInstance = exports.FinanceUtils = exports.ArrayUtils = void 0;
|
|
4
4
|
var array_utils_1 = require("./utils/array-utils");
|
|
5
5
|
Object.defineProperty(exports, "ArrayUtils", { enumerable: true, get: function () { return array_utils_1.default; } });
|
|
6
6
|
var finance_utils_1 = require("./utils/finance-utils");
|
|
@@ -37,3 +37,9 @@ var number_utils2_1 = require("./utils/number-utils2");
|
|
|
37
37
|
Object.defineProperty(exports, "isNumber", { enumerable: true, get: function () { return number_utils2_1.isNumber; } });
|
|
38
38
|
Object.defineProperty(exports, "thousandths", { enumerable: true, get: function () { return number_utils2_1.thousandths; } });
|
|
39
39
|
Object.defineProperty(exports, "summation", { enumerable: true, get: function () { return number_utils2_1.summation; } });
|
|
40
|
+
var array_utils2_1 = require("./utils/array-utils2");
|
|
41
|
+
Object.defineProperty(exports, "findTreeNodes", { enumerable: true, get: function () { return array_utils2_1.findTreeNodes; } });
|
|
42
|
+
var prototype_utils2_1 = require("./utils/prototype-utils2");
|
|
43
|
+
Object.defineProperty(exports, "prototype", { enumerable: true, get: function () { return prototype_utils2_1.prototype; } });
|
|
44
|
+
var file_utils2_1 = require("./utils/file-utils2");
|
|
45
|
+
Object.defineProperty(exports, "fileType", { enumerable: true, get: function () { return file_utils2_1.fileType; } });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 树形结构节点查找(返回所有满足条件的最上级节点)
|
|
3
|
+
* @param tree 树形结构数据
|
|
4
|
+
* @param condition 节点匹配条件(返回true表示匹配)
|
|
5
|
+
* @param algorithm 遍历算法:dfs(深度优先)/bfs(广度优先),默认dfs
|
|
6
|
+
* @param childrenKey 子节点的key名,默认 'children'
|
|
7
|
+
* @returns 所有满足条件的最上级节点数组
|
|
8
|
+
*/
|
|
9
|
+
export declare const findTreeNodes: (tree: any[], condition: (node: any) => boolean, algorithm?: "DFS" | "BFS", childrenKey?: string) => any[];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findTreeNodes = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 树形结构节点查找(返回所有满足条件的最上级节点)
|
|
6
|
+
* @param tree 树形结构数据
|
|
7
|
+
* @param condition 节点匹配条件(返回true表示匹配)
|
|
8
|
+
* @param algorithm 遍历算法:dfs(深度优先)/bfs(广度优先),默认dfs
|
|
9
|
+
* @param childrenKey 子节点的key名,默认 'children'
|
|
10
|
+
* @returns 所有满足条件的最上级节点数组
|
|
11
|
+
*/
|
|
12
|
+
const findTreeNodes = (tree, condition, algorithm = 'DFS', childrenKey = 'children') => {
|
|
13
|
+
// 存储最终匹配的节点
|
|
14
|
+
const result = [];
|
|
15
|
+
// 深度优先遍历(递归版)
|
|
16
|
+
const dfs = (nodes) => {
|
|
17
|
+
for (const node of nodes) {
|
|
18
|
+
// 深拷贝节点(避免修改原数据),并保留子节点结构
|
|
19
|
+
const nodeCopy = Object.assign({}, node);
|
|
20
|
+
// 满足条件:直接加入结果(保留所有子节点)
|
|
21
|
+
if (condition(node)) {
|
|
22
|
+
result.push(nodeCopy);
|
|
23
|
+
continue; // 无需遍历该节点的子节点,因为已完整保留
|
|
24
|
+
}
|
|
25
|
+
// 不满足条件:递归遍历子节点
|
|
26
|
+
const children = node[childrenKey];
|
|
27
|
+
if (Array.isArray(children) && children.length > 0) {
|
|
28
|
+
dfs(children);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
// 广度优先遍历(迭代版,队列实现)
|
|
33
|
+
const bfs = (nodes) => {
|
|
34
|
+
// 初始化队列,浅拷贝避免修改原数组
|
|
35
|
+
const queue = [...nodes];
|
|
36
|
+
while (queue.length > 0) {
|
|
37
|
+
const currentNode = queue.shift();
|
|
38
|
+
// 深拷贝节点
|
|
39
|
+
const nodeCopy = Object.assign({}, currentNode);
|
|
40
|
+
// 满足条件:加入结果(保留所有子节点)
|
|
41
|
+
if (condition(currentNode)) {
|
|
42
|
+
result.push(nodeCopy);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
// 不满足条件:子节点入队继续遍历
|
|
46
|
+
const children = currentNode[childrenKey];
|
|
47
|
+
if (Array.isArray(children) && children.length > 0) {
|
|
48
|
+
queue.push(...children);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
// 根据指定算法执行遍历
|
|
53
|
+
if (algorithm === 'DFS') {
|
|
54
|
+
dfs(tree);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
bfs(tree);
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
};
|
|
61
|
+
exports.findTreeNodes = findTreeNodes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const fileType: (o: File | string) => string;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fileType = void 0;
|
|
4
|
+
const prototype_utils2_1 = require("./prototype-utils2");
|
|
5
|
+
const mimeTypeMap = {
|
|
6
|
+
// 基础文件
|
|
7
|
+
'application/pdf': 'pdf',
|
|
8
|
+
'text/plain': 'txt',
|
|
9
|
+
'text/csv': 'csv',
|
|
10
|
+
'application/json': 'json',
|
|
11
|
+
// 图片
|
|
12
|
+
'image/jpeg': 'jpg',
|
|
13
|
+
'image/png': 'png',
|
|
14
|
+
'image/gif': 'gif',
|
|
15
|
+
'image/webp': 'webp',
|
|
16
|
+
// Office 文件(关键解决你的问题)
|
|
17
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'docx',
|
|
18
|
+
'application/msword': 'doc',
|
|
19
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'xlsx',
|
|
20
|
+
'application/vnd.ms-excel': 'xls',
|
|
21
|
+
'application/vnd.openxmlformats-officedocument.presentationml.presentation': 'pptx',
|
|
22
|
+
'application/vnd.ms-powerpoint': 'ppt',
|
|
23
|
+
// 压缩包
|
|
24
|
+
'application/zip': 'zip',
|
|
25
|
+
'application/x-rar-compressed': 'rar',
|
|
26
|
+
'application/x-7z-compressed': '7z',
|
|
27
|
+
// 音频/视频类型
|
|
28
|
+
'audio/mpeg': 'mp3',
|
|
29
|
+
'audio/wav': 'wav',
|
|
30
|
+
'audio/ogg': 'ogg',
|
|
31
|
+
'audio/mp4': 'm4a',
|
|
32
|
+
'audio/flac': 'flac',
|
|
33
|
+
// CAD文件
|
|
34
|
+
'application/vnd.dxf': 'dxf'
|
|
35
|
+
};
|
|
36
|
+
const fileType = (o) => {
|
|
37
|
+
if ((0, prototype_utils2_1.prototype)(o) === 'File') {
|
|
38
|
+
const file = o;
|
|
39
|
+
const type = mimeTypeMap[file.type];
|
|
40
|
+
if (!type)
|
|
41
|
+
return (0, exports.fileType)(file.name);
|
|
42
|
+
return type;
|
|
43
|
+
}
|
|
44
|
+
else if ((0, prototype_utils2_1.prototype)(o) === 'String') {
|
|
45
|
+
const name = o;
|
|
46
|
+
if (name.includes('.'))
|
|
47
|
+
return name.split('.').pop() || '';
|
|
48
|
+
}
|
|
49
|
+
return '';
|
|
50
|
+
};
|
|
51
|
+
exports.fileType = fileType;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
type Type = 'Array' | 'Blob' | 'Boolean' | 'Date' | 'File' | 'FormData' | 'Function' | 'HTMLDocument' | 'Map' | 'Null' | 'Number' | 'Object' | 'RegExp' | 'Set' | 'String' | 'Symbol' | 'Undefined' | 'URLSearchParams' | 'Window';
|
|
2
|
+
export declare const prototype: (o: any) => Type;
|
|
3
|
+
export {};
|