util-helpers 4.15.0 → 4.15.2
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/util-helpers.js +82 -72
- package/dist/util-helpers.js.map +1 -1
- package/dist/util-helpers.min.js +1 -1
- package/dist/util-helpers.min.js.map +1 -1
- package/esm/bytesToSize.js +5 -2
- package/esm/filterTree.js +3 -4
- package/esm/findTreeNode.js +3 -0
- package/esm/findTreeNodes.js +3 -0
- package/esm/findTreeSelect.js +3 -4
- package/esm/formatMoney.js +11 -9
- package/esm/listToTree.js +34 -30
- package/esm/parseIdCard.js +10 -13
- package/esm/randomString.js +3 -5
- package/esm/transformFieldNames.js +1 -2
- package/esm/treeToList.js +4 -1
- package/esm/utils/config.js +1 -1
- package/lib/bytesToSize.js +5 -2
- package/lib/filterTree.js +3 -4
- package/lib/findTreeNode.js +3 -0
- package/lib/findTreeNodes.js +3 -0
- package/lib/findTreeSelect.js +3 -4
- package/lib/formatMoney.js +11 -9
- package/lib/listToTree.js +34 -30
- package/lib/parseIdCard.js +10 -13
- package/lib/randomString.js +3 -5
- package/lib/transformFieldNames.js +1 -2
- package/lib/treeToList.js +4 -1
- package/lib/utils/config.js +1 -1
- package/package.json +2 -1
- package/types/bytesToSize.d.ts +2 -0
- package/types/formatMoney.d.ts +12 -10
- package/types/listToTree.d.ts +2 -2
package/lib/utils/config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "util-helpers",
|
|
3
|
-
"version": "4.15.
|
|
3
|
+
"version": "4.15.2",
|
|
4
4
|
"description": "一个基于业务场景的工具方法库",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "jest --verbose",
|
|
12
12
|
"test:coverage": "jest --coverage",
|
|
13
|
+
"test:coverage:local": "cross-env COVERAGE_LOCAL=1 jest --coverage",
|
|
13
14
|
"test:math": "jest --verbose test/math",
|
|
14
15
|
"test:type": "jest --verbose test/type",
|
|
15
16
|
"test:validator": "jest --verbose test/validator",
|
package/types/bytesToSize.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export default bytesToSize;
|
|
|
8
8
|
* @param {number} bytes 字节大小
|
|
9
9
|
* @param {Object} [options] 配置项
|
|
10
10
|
* @param {string} [options.spaceMark=' '] 间隔字符
|
|
11
|
+
* @param {number} [options.precision=2] 精度
|
|
11
12
|
* @returns {string} 存储单位值
|
|
12
13
|
* @example
|
|
13
14
|
*
|
|
@@ -23,4 +24,5 @@ export default bytesToSize;
|
|
|
23
24
|
*/
|
|
24
25
|
declare function bytesToSize(bytes: number, options?: {
|
|
25
26
|
spaceMark?: string | undefined;
|
|
27
|
+
precision?: number | undefined;
|
|
26
28
|
} | undefined): string;
|
package/types/formatMoney.d.ts
CHANGED
|
@@ -6,25 +6,25 @@ export default formatMoney;
|
|
|
6
6
|
* @alias module:Processor.formatMoney
|
|
7
7
|
* @since 1.1.0
|
|
8
8
|
* @param {string | number} num 需转换金额 (最大:9007199254740991 最小: -9007199254740991)
|
|
9
|
-
* @param {Object} [options]
|
|
10
|
-
* @param {
|
|
11
|
-
* @param {string} [options.symbol]
|
|
12
|
-
* @param {string} [options.thousand=","]
|
|
13
|
-
* @param {string} [options.decimal="."]
|
|
9
|
+
* @param {Object} [options] 金额格式化配置
|
|
10
|
+
* @param {number} [options.precision=2] 保留位数 (最高:10位)
|
|
11
|
+
* @param {string} [options.symbol] 货币符号
|
|
12
|
+
* @param {string} [options.thousand=","] 千分位符号
|
|
13
|
+
* @param {string} [options.decimal="."] 小数位符号
|
|
14
14
|
* @returns {string} 格式化的金额
|
|
15
15
|
* @example
|
|
16
16
|
*
|
|
17
17
|
* // 整数
|
|
18
|
-
* formatMoney(
|
|
18
|
+
* formatMoney(1000); // 1,000.00
|
|
19
19
|
*
|
|
20
20
|
* // 小数(默认保留2位小数)
|
|
21
|
-
* formatMoney(
|
|
21
|
+
* formatMoney(3000.03); // 3,000.03
|
|
22
22
|
*
|
|
23
23
|
* // 保留4位小数
|
|
24
|
-
* formatMoney(
|
|
24
|
+
* formatMoney(3000.03, { precision: 4 }); // 3,000.0300
|
|
25
25
|
*
|
|
26
26
|
* // 保留10位小数
|
|
27
|
-
* formatMoney(
|
|
27
|
+
* formatMoney(1500.2, { precision: 10 }); // 1,500.2000000000
|
|
28
28
|
*
|
|
29
29
|
* // 自定义单位符号
|
|
30
30
|
* formatMoney(1000.00, { symbol: '$' }); // $1,000.00
|
|
@@ -35,9 +35,11 @@ export default formatMoney;
|
|
|
35
35
|
* // 自定义小数位分割符(默认'.')
|
|
36
36
|
* formatMoney(1000.00, { decimal: '&' }); // 1,000&00
|
|
37
37
|
*
|
|
38
|
+
* // 字符串数字
|
|
39
|
+
* formatMoney('3000.03', { precision: 4 }); // 3,000.0300
|
|
38
40
|
*/
|
|
39
41
|
declare function formatMoney(num: string | number, options?: {
|
|
40
|
-
precision?:
|
|
42
|
+
precision?: number | undefined;
|
|
41
43
|
symbol?: string | undefined;
|
|
42
44
|
thousand?: string | undefined;
|
|
43
45
|
decimal?: string | undefined;
|
package/types/listToTree.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export default listToTree;
|
|
|
8
8
|
* @template {Record<string,any>} [T=Record<string,any>]
|
|
9
9
|
* @template {*} [R=T&Record<string,any>]
|
|
10
10
|
* @param {T[]} list 列表数据
|
|
11
|
-
* @param {object} options 配置项
|
|
11
|
+
* @param {object} [options] 配置项
|
|
12
12
|
* @param {string} [options.keyField='id'] 当前数据的键值字段名称
|
|
13
13
|
* @param {string} [options.parentField='pid'] 当前数据的父级字段名称
|
|
14
14
|
* @param {string} [options.childrenField='children'] 子级字段名称
|
|
@@ -40,4 +40,4 @@ declare function listToTree<T extends Record<string, any> = Record<string, any>,
|
|
|
40
40
|
childrenField?: string | undefined;
|
|
41
41
|
emptyChildrenValue?: "none" | "null" | "array" | undefined;
|
|
42
42
|
nodeAssign?: "spread" | "self" | undefined;
|
|
43
|
-
}): R[];
|
|
43
|
+
} | undefined): R[];
|