util-helpers 4.15.1 → 4.15.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.
@@ -7,6 +7,7 @@
7
7
  * @param {number} bytes 字节大小
8
8
  * @param {Object} [options] 配置项
9
9
  * @param {string} [options.spaceMark=' '] 间隔字符
10
+ * @param {number} [options.precision=2] 精度
10
11
  * @returns {string} 存储单位值
11
12
  * @example
12
13
  *
@@ -23,13 +24,15 @@
23
24
  function bytesToSize(bytes) {
24
25
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
25
26
  var _options$spaceMark = options.spaceMark,
26
- spaceMark = _options$spaceMark === void 0 ? ' ' : _options$spaceMark;
27
+ spaceMark = _options$spaceMark === void 0 ? ' ' : _options$spaceMark,
28
+ _options$precision = options.precision,
29
+ precision = _options$precision === void 0 ? 2 : _options$precision;
27
30
  var numBytes = typeof bytes !== 'number' ? Number(bytes) : bytes;
28
31
  if (numBytes === 0 || isNaN(numBytes)) return "0".concat(spaceMark, "B");
29
32
  var k = 1024;
30
33
  // 存储单位
31
34
  var sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
32
35
  var i = Math.floor(Math.log(numBytes) / Math.log(k));
33
- return sizes[i] ? "".concat(Number((numBytes / Math.pow(k, i)).toFixed(2))).concat(spaceMark).concat(sizes[i]) : numBytes + '';
36
+ return sizes[i] ? "".concat(Number((numBytes / Math.pow(k, i)).toFixed(precision))).concat(spaceMark).concat(sizes[i]) : numBytes + '';
34
37
  }
35
38
  export default bytesToSize;
package/esm/filterTree.js CHANGED
@@ -7,7 +7,7 @@ import { isObject } from "./utils/type";
7
7
  * 过滤/筛选树节点。<br/><br/>如果某节点被过滤掉,它的子节点也一并抛弃
8
8
  *
9
9
  * @static
10
- * @alias module:Processor.filterTree
10
+ * @alias module:Tree.filterTree
11
11
  * @since 4.15.0
12
12
  * @template {any} T
13
13
  * @template {(item: T) => boolean} F
@@ -8,7 +8,7 @@ import { isObject } from "./utils/type";
8
8
  * 查找树结构数据节点
9
9
  *
10
10
  * @static
11
- * @alias module:Other.findTreeNode
11
+ * @alias module:Tree.findTreeNode
12
12
  * @since 4.14.0
13
13
  * @template {any} T
14
14
  * @template {(item: T) => boolean} F
@@ -8,7 +8,7 @@ import { isObject } from "./utils/type";
8
8
  * 查找树结构数据多个节点
9
9
  *
10
10
  * @static
11
- * @alias module:Other.findTreeNodes
11
+ * @alias module:Tree.findTreeNodes
12
12
  * @since 4.15.0
13
13
  * @template {any} T
14
14
  * @template {(item: T) => boolean} F
@@ -54,7 +54,7 @@ function internalFindTreeSelect(tree, predicate, childrenField) {
54
54
  * 查找包含当前节点的所有父级节点
55
55
  *
56
56
  * @static
57
- * @alias module:Other.findTreeSelect
57
+ * @alias module:Tree.findTreeSelect
58
58
  * @since 4.14.0
59
59
  * @template {any} T
60
60
  * @template {(item: T) => boolean} F
@@ -77,25 +77,25 @@ function formatDec(decStr, precision, decimal) {
77
77
  * @alias module:Processor.formatMoney
78
78
  * @since 1.1.0
79
79
  * @param {string | number} num 需转换金额 (最大:9007199254740991 最小: -9007199254740991)
80
- * @param {Object} [options] - 金额格式化配置
81
- * @param {string | number} [options.precision=2] - 保留位数 (最高:10位)
82
- * @param {string} [options.symbol] - 货币符号
83
- * @param {string} [options.thousand=","] - 千分位符号
84
- * @param {string} [options.decimal="."] - 小数位符号
80
+ * @param {Object} [options] 金额格式化配置
81
+ * @param {number} [options.precision=2] 保留位数 (最高:10位)
82
+ * @param {string} [options.symbol] 货币符号
83
+ * @param {string} [options.thousand=","] 千分位符号
84
+ * @param {string} [options.decimal="."] 小数位符号
85
85
  * @returns {string} 格式化的金额
86
86
  * @example
87
87
  *
88
88
  * // 整数
89
- * formatMoney('1000'); // 1,000.00
89
+ * formatMoney(1000); // 1,000.00
90
90
  *
91
91
  * // 小数(默认保留2位小数)
92
- * formatMoney('3000.03'); // 3,000.03
92
+ * formatMoney(3000.03); // 3,000.03
93
93
  *
94
94
  * // 保留4位小数
95
- * formatMoney('3000.0300', { precision: 4 }); // 3,000.0300
95
+ * formatMoney(3000.03, { precision: 4 }); // 3,000.0300
96
96
  *
97
97
  * // 保留10位小数
98
- * formatMoney('1500.2', { precision: 10 }); // 1,500.2000000000
98
+ * formatMoney(1500.2, { precision: 10 }); // 1,500.2000000000
99
99
  *
100
100
  * // 自定义单位符号
101
101
  * formatMoney(1000.00, { symbol: '$' }); // $1,000.00
@@ -106,6 +106,8 @@ function formatDec(decStr, precision, decimal) {
106
106
  * // 自定义小数位分割符(默认'.')
107
107
  * formatMoney(1000.00, { decimal: '&' }); // 1,000&00
108
108
  *
109
+ * // 字符串数字
110
+ * formatMoney('3000.03', { precision: 4 }); // 3,000.0300
109
111
  */
110
112
  var formatMoney = function formatMoney(num) {
111
113
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
package/esm/index.js CHANGED
@@ -46,10 +46,6 @@ export { default as normalizeString } from './normalizeString';
46
46
  export { default as safeDate } from './safeDate';
47
47
  export { default as formatMobile } from './formatMobile';
48
48
  export { default as padZero } from './padZero';
49
- export { default as transformFieldNames } from './transformFieldNames';
50
- export { default as listToTree } from './listToTree';
51
- export { default as treeToList } from './treeToList';
52
- export { default as filterTree } from './filterTree';
53
49
 
54
50
  /**
55
51
  * 数学计算,修正浮点数计算问题
@@ -106,6 +102,17 @@ export { default as waitTime } from './waitTime';
106
102
  export { default as calculateCursorPosition } from './calculateCursorPosition';
107
103
  export { default as randomString } from './randomString';
108
104
  export { default as strlen } from './strlen';
105
+
106
+ /**
107
+ * 树结构数据查询、过滤、转换等处理方法
108
+ *
109
+ * @module Tree
110
+ * @since 4.14.0
111
+ */
112
+ export { default as transformFieldNames } from './transformFieldNames';
113
+ export { default as listToTree } from './listToTree';
114
+ export { default as treeToList } from './treeToList';
115
+ export { default as filterTree } from './filterTree';
109
116
  export { default as findTreeNode } from './findTreeNode';
110
117
  export { default as findTreeNodes } from './findTreeNodes';
111
118
  export { default as findTreeSelect } from './findTreeSelect';
package/esm/listToTree.js CHANGED
@@ -40,7 +40,7 @@ function processEmptyChildren(arr, options) {
40
40
  * 列表数据转树结构
41
41
  *
42
42
  * @static
43
- * @alias module:Processor.listToTree
43
+ * @alias module:Tree.listToTree
44
44
  * @since 4.14.0
45
45
  * @template {Record<string,any>} [T=Record<string,any>]
46
46
  * @template {*} [R=T&Record<string,any>]
@@ -16,20 +16,24 @@ import normalizeString from './normalizeString';
16
16
  * @returns {string} 处理后的字符
17
17
  * @example
18
18
  *
19
- * // 手机号
19
+ * // 手机号 前3后4
20
20
  * replaceChar('13000000000'); // 130****0000
21
21
  *
22
- * // 身份证
23
- * replaceChar('130701199310302288'); // 130***********2288
22
+ * // 身份证 前6后4
23
+ * replaceChar('130701199310302288', { start: 6, end: -4 }); // 130701********2288
24
24
  *
25
- * // 邮箱
25
+ * // 邮箱 @前两位
26
26
  * const email = '12345@qq.com'
27
+ * const emailAtIndex = email.indexOf('@');
28
+ * replaceChar(email, { start: emailAtIndex - 2, end: emailAtIndex }); // 123**@qq.com
29
+ * // 邮箱 前2和@后面内容,固定替换字符4位
27
30
  * replaceChar(email, {start: 2, end: email.indexOf('@'), repeat: 4}); // 12****@qq.com
28
31
  *
29
- * // 银行卡号
32
+ * // 银行卡号 只展示后4位,固定替换字符4位
30
33
  * replaceChar('6228480402564890018', {start: 0, end: -4, repeat: 4}); // ****0018
31
- *
32
- * // 带格式的银行卡号,忽略空字符串
34
+ * // 银行卡号 前6后4
35
+ * replaceChar('6228480402564890018', { start: 6, end: -4 }); // 622848*********0018
36
+ * // 银行卡号 前4后3 忽略格式的空格
33
37
  * replaceChar('6228 4804 0256 4890 018', {start: 4, end: -4, exclude: ' '}); // 6228 **** **** **** 018
34
38
  *
35
39
  * // 用户名
@@ -5,7 +5,7 @@
5
5
  * 转换字段名,返回一个转换字段后的值,不改变原值。
6
6
  *
7
7
  * @static
8
- * @alias module:Processor.transformFieldNames
8
+ * @alias module:Tree.transformFieldNames
9
9
  * @since 4.14.0
10
10
  * @param {object[]} data 对象数组。如果是树结构数据,需要指定第三个参数 childrenField
11
11
  * @param {object} fieldNames 字段名映射
@@ -1,5 +1,3 @@
1
- // @ts-nocheck
2
-
3
1
  // 交换字段名
4
2
  /**
5
3
  * @template {*} D
@@ -8,10 +6,10 @@
8
6
  */
9
7
 
10
8
  // 交换字段名,支持嵌套
11
- // 先排除子级字段名,再交换字段名,然后加上子级字段名,再替换一次。这里的 F 有类型问题,因为排除了子级字段名,暂时没有比较好的方案处理。
9
+ // 先排除子级字段名,再交换字段名,然后加上子级字段名,再替换一次。
12
10
  /**
13
11
  * @template {*} D
14
- * @template {Record<string, keyof D>} F
12
+ * @template {Record<string, any>} F
15
13
  * @template {string} C
16
14
  * @typedef {(C extends keyof D ? ExchangeFieldNames<Omit<D, C> & Record<C, TransformFieldNames<D, F, C>>, F> : ExchangeFieldNames<D, F>)[]} TransformFieldNames
17
15
  */
package/esm/treeToList.js CHANGED
@@ -7,7 +7,7 @@ import { isObject } from "./utils/type";
7
7
  * 树结构转列表数据
8
8
  *
9
9
  * @static
10
- * @alias module:Processor.treeToList
10
+ * @alias module:Tree.treeToList
11
11
  * @since 4.14.0
12
12
  * @template {Record<string,any>} T
13
13
  * @template {keyof T} K
@@ -15,5 +15,5 @@ function setDisableWarning(bool) {
15
15
  }
16
16
 
17
17
  // eslint-disable-next-line no-undef
18
- var version = "4.15.1";
18
+ var version = "4.15.3";
19
19
  export { config, setDisableWarning, version };
@@ -13,6 +13,7 @@ exports["default"] = void 0;
13
13
  * @param {number} bytes 字节大小
14
14
  * @param {Object} [options] 配置项
15
15
  * @param {string} [options.spaceMark=' '] 间隔字符
16
+ * @param {number} [options.precision=2] 精度
16
17
  * @returns {string} 存储单位值
17
18
  * @example
18
19
  *
@@ -29,14 +30,16 @@ exports["default"] = void 0;
29
30
  function bytesToSize(bytes) {
30
31
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
31
32
  var _options$spaceMark = options.spaceMark,
32
- spaceMark = _options$spaceMark === void 0 ? ' ' : _options$spaceMark;
33
+ spaceMark = _options$spaceMark === void 0 ? ' ' : _options$spaceMark,
34
+ _options$precision = options.precision,
35
+ precision = _options$precision === void 0 ? 2 : _options$precision;
33
36
  var numBytes = typeof bytes !== 'number' ? Number(bytes) : bytes;
34
37
  if (numBytes === 0 || isNaN(numBytes)) return "0".concat(spaceMark, "B");
35
38
  var k = 1024;
36
39
  // 存储单位
37
40
  var sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
38
41
  var i = Math.floor(Math.log(numBytes) / Math.log(k));
39
- return sizes[i] ? "".concat(Number((numBytes / Math.pow(k, i)).toFixed(2))).concat(spaceMark).concat(sizes[i]) : numBytes + '';
42
+ return sizes[i] ? "".concat(Number((numBytes / Math.pow(k, i)).toFixed(precision))).concat(spaceMark).concat(sizes[i]) : numBytes + '';
40
43
  }
41
44
  var _default = bytesToSize;
42
45
  exports["default"] = _default;
package/lib/filterTree.js CHANGED
@@ -15,7 +15,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
15
15
  * 过滤/筛选树节点。<br/><br/>如果某节点被过滤掉,它的子节点也一并抛弃
16
16
  *
17
17
  * @static
18
- * @alias module:Processor.filterTree
18
+ * @alias module:Tree.filterTree
19
19
  * @since 4.15.0
20
20
  * @template {any} T
21
21
  * @template {(item: T) => boolean} F
@@ -16,7 +16,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
16
16
  * 查找树结构数据节点
17
17
  *
18
18
  * @static
19
- * @alias module:Other.findTreeNode
19
+ * @alias module:Tree.findTreeNode
20
20
  * @since 4.14.0
21
21
  * @template {any} T
22
22
  * @template {(item: T) => boolean} F
@@ -16,7 +16,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
16
16
  * 查找树结构数据多个节点
17
17
  *
18
18
  * @static
19
- * @alias module:Other.findTreeNodes
19
+ * @alias module:Tree.findTreeNodes
20
20
  * @since 4.15.0
21
21
  * @template {any} T
22
22
  * @template {(item: T) => boolean} F
@@ -59,7 +59,7 @@ function internalFindTreeSelect(tree, predicate, childrenField) {
59
59
  * 查找包含当前节点的所有父级节点
60
60
  *
61
61
  * @static
62
- * @alias module:Other.findTreeSelect
62
+ * @alias module:Tree.findTreeSelect
63
63
  * @since 4.14.0
64
64
  * @template {any} T
65
65
  * @template {(item: T) => boolean} F
@@ -88,25 +88,25 @@ function formatDec(decStr, precision, decimal) {
88
88
  * @alias module:Processor.formatMoney
89
89
  * @since 1.1.0
90
90
  * @param {string | number} num 需转换金额 (最大:9007199254740991 最小: -9007199254740991)
91
- * @param {Object} [options] - 金额格式化配置
92
- * @param {string | number} [options.precision=2] - 保留位数 (最高:10位)
93
- * @param {string} [options.symbol] - 货币符号
94
- * @param {string} [options.thousand=","] - 千分位符号
95
- * @param {string} [options.decimal="."] - 小数位符号
91
+ * @param {Object} [options] 金额格式化配置
92
+ * @param {number} [options.precision=2] 保留位数 (最高:10位)
93
+ * @param {string} [options.symbol] 货币符号
94
+ * @param {string} [options.thousand=","] 千分位符号
95
+ * @param {string} [options.decimal="."] 小数位符号
96
96
  * @returns {string} 格式化的金额
97
97
  * @example
98
98
  *
99
99
  * // 整数
100
- * formatMoney('1000'); // 1,000.00
100
+ * formatMoney(1000); // 1,000.00
101
101
  *
102
102
  * // 小数(默认保留2位小数)
103
- * formatMoney('3000.03'); // 3,000.03
103
+ * formatMoney(3000.03); // 3,000.03
104
104
  *
105
105
  * // 保留4位小数
106
- * formatMoney('3000.0300', { precision: 4 }); // 3,000.0300
106
+ * formatMoney(3000.03, { precision: 4 }); // 3,000.0300
107
107
  *
108
108
  * // 保留10位小数
109
- * formatMoney('1500.2', { precision: 10 }); // 1,500.2000000000
109
+ * formatMoney(1500.2, { precision: 10 }); // 1,500.2000000000
110
110
  *
111
111
  * // 自定义单位符号
112
112
  * formatMoney(1000.00, { symbol: '$' }); // $1,000.00
@@ -117,6 +117,8 @@ function formatDec(decStr, precision, decimal) {
117
117
  * // 自定义小数位分割符(默认'.')
118
118
  * formatMoney(1000.00, { decimal: '&' }); // 1,000&00
119
119
  *
120
+ * // 字符串数字
121
+ * formatMoney('3000.03', { precision: 4 }); // 3,000.0300
120
122
  */
121
123
  var formatMoney = function formatMoney(num) {
122
124
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
package/lib/index.js CHANGED
@@ -356,10 +356,6 @@ var _normalizeString = _interopRequireDefault(require("./normalizeString"));
356
356
  var _safeDate = _interopRequireDefault(require("./safeDate"));
357
357
  var _formatMobile = _interopRequireDefault(require("./formatMobile"));
358
358
  var _padZero = _interopRequireDefault(require("./padZero"));
359
- var _transformFieldNames = _interopRequireDefault(require("./transformFieldNames"));
360
- var _listToTree = _interopRequireDefault(require("./listToTree"));
361
- var _treeToList = _interopRequireDefault(require("./treeToList"));
362
- var _filterTree = _interopRequireDefault(require("./filterTree"));
363
359
  var _plus = _interopRequireDefault(require("./plus"));
364
360
  var _minus = _interopRequireDefault(require("./minus"));
365
361
  var _times = _interopRequireDefault(require("./times"));
@@ -369,6 +365,10 @@ var _waitTime = _interopRequireDefault(require("./waitTime"));
369
365
  var _calculateCursorPosition = _interopRequireDefault(require("./calculateCursorPosition"));
370
366
  var _randomString = _interopRequireDefault(require("./randomString"));
371
367
  var _strlen = _interopRequireDefault(require("./strlen"));
368
+ var _transformFieldNames = _interopRequireDefault(require("./transformFieldNames"));
369
+ var _listToTree = _interopRequireDefault(require("./listToTree"));
370
+ var _treeToList = _interopRequireDefault(require("./treeToList"));
371
+ var _filterTree = _interopRequireDefault(require("./filterTree"));
372
372
  var _findTreeNode = _interopRequireDefault(require("./findTreeNode"));
373
373
  var _findTreeNodes = _interopRequireDefault(require("./findTreeNodes"));
374
374
  var _findTreeSelect = _interopRequireDefault(require("./findTreeSelect"));
package/lib/listToTree.js CHANGED
@@ -48,7 +48,7 @@ function processEmptyChildren(arr, options) {
48
48
  * 列表数据转树结构
49
49
  *
50
50
  * @static
51
- * @alias module:Processor.listToTree
51
+ * @alias module:Tree.listToTree
52
52
  * @since 4.14.0
53
53
  * @template {Record<string,any>} [T=Record<string,any>]
54
54
  * @template {*} [R=T&Record<string,any>]
@@ -22,20 +22,24 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
22
22
  * @returns {string} 处理后的字符
23
23
  * @example
24
24
  *
25
- * // 手机号
25
+ * // 手机号 前3后4
26
26
  * replaceChar('13000000000'); // 130****0000
27
27
  *
28
- * // 身份证
29
- * replaceChar('130701199310302288'); // 130***********2288
28
+ * // 身份证 前6后4
29
+ * replaceChar('130701199310302288', { start: 6, end: -4 }); // 130701********2288
30
30
  *
31
- * // 邮箱
31
+ * // 邮箱 @前两位
32
32
  * const email = '12345@qq.com'
33
+ * const emailAtIndex = email.indexOf('@');
34
+ * replaceChar(email, { start: emailAtIndex - 2, end: emailAtIndex }); // 123**@qq.com
35
+ * // 邮箱 前2和@后面内容,固定替换字符4位
33
36
  * replaceChar(email, {start: 2, end: email.indexOf('@'), repeat: 4}); // 12****@qq.com
34
37
  *
35
- * // 银行卡号
38
+ * // 银行卡号 只展示后4位,固定替换字符4位
36
39
  * replaceChar('6228480402564890018', {start: 0, end: -4, repeat: 4}); // ****0018
37
- *
38
- * // 带格式的银行卡号,忽略空字符串
40
+ * // 银行卡号 前6后4
41
+ * replaceChar('6228480402564890018', { start: 6, end: -4 }); // 622848*********0018
42
+ * // 银行卡号 前4后3 忽略格式的空格
39
43
  * replaceChar('6228 4804 0256 4890 018', {start: 4, end: -4, exclude: ' '}); // 6228 **** **** **** 018
40
44
  *
41
45
  * // 用户名
@@ -11,7 +11,7 @@ exports["default"] = void 0;
11
11
  * 转换字段名,返回一个转换字段后的值,不改变原值。
12
12
  *
13
13
  * @static
14
- * @alias module:Processor.transformFieldNames
14
+ * @alias module:Tree.transformFieldNames
15
15
  * @since 4.14.0
16
16
  * @param {object[]} data 对象数组。如果是树结构数据,需要指定第三个参数 childrenField
17
17
  * @param {object} fieldNames 字段名映射
package/lib/treeToList.js CHANGED
@@ -15,7 +15,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
15
15
  * 树结构转列表数据
16
16
  *
17
17
  * @static
18
- * @alias module:Processor.treeToList
18
+ * @alias module:Tree.treeToList
19
19
  * @since 4.14.0
20
20
  * @template {Record<string,any>} T
21
21
  * @template {keyof T} K
@@ -24,5 +24,5 @@ function setDisableWarning(bool) {
24
24
  }
25
25
 
26
26
  // eslint-disable-next-line no-undef
27
- var version = "4.15.1";
27
+ var version = "4.15.3";
28
28
  exports.version = version;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "util-helpers",
3
- "version": "4.15.1",
3
+ "version": "4.15.3",
4
4
  "description": "一个基于业务场景的工具方法库",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -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;
@@ -3,7 +3,7 @@ export default filterTree;
3
3
  * 过滤/筛选树节点。<br/><br/>如果某节点被过滤掉,它的子节点也一并抛弃
4
4
  *
5
5
  * @static
6
- * @alias module:Processor.filterTree
6
+ * @alias module:Tree.filterTree
7
7
  * @since 4.15.0
8
8
  * @template {any} T
9
9
  * @template {(item: T) => boolean} F
@@ -3,7 +3,7 @@ export default findTreeNode;
3
3
  * 查找树结构数据节点
4
4
  *
5
5
  * @static
6
- * @alias module:Other.findTreeNode
6
+ * @alias module:Tree.findTreeNode
7
7
  * @since 4.14.0
8
8
  * @template {any} T
9
9
  * @template {(item: T) => boolean} F
@@ -3,7 +3,7 @@ export default findTreeNodes;
3
3
  * 查找树结构数据多个节点
4
4
  *
5
5
  * @static
6
- * @alias module:Other.findTreeNodes
6
+ * @alias module:Tree.findTreeNodes
7
7
  * @since 4.15.0
8
8
  * @template {any} T
9
9
  * @template {(item: T) => boolean} F
@@ -3,7 +3,7 @@ export default findTreeSelect;
3
3
  * 查找包含当前节点的所有父级节点
4
4
  *
5
5
  * @static
6
- * @alias module:Other.findTreeSelect
6
+ * @alias module:Tree.findTreeSelect
7
7
  * @since 4.14.0
8
8
  * @template {any} T
9
9
  * @template {(item: T) => boolean} F
@@ -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 {string | number} [options.precision=2] - 保留位数 (最高:10位)
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('1000'); // 1,000.00
18
+ * formatMoney(1000); // 1,000.00
19
19
  *
20
20
  * // 小数(默认保留2位小数)
21
- * formatMoney('3000.03'); // 3,000.03
21
+ * formatMoney(3000.03); // 3,000.03
22
22
  *
23
23
  * // 保留4位小数
24
- * formatMoney('3000.0300', { precision: 4 }); // 3,000.0300
24
+ * formatMoney(3000.03, { precision: 4 }); // 3,000.0300
25
25
  *
26
26
  * // 保留10位小数
27
- * formatMoney('1500.2', { precision: 10 }); // 1,500.2000000000
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?: string | number | undefined;
42
+ precision?: number | undefined;
41
43
  symbol?: string | undefined;
42
44
  thousand?: string | undefined;
43
45
  decimal?: string | undefined;
package/types/index.d.ts CHANGED
@@ -33,10 +33,6 @@ export { default as normalizeString } from "./normalizeString";
33
33
  export { default as safeDate } from "./safeDate";
34
34
  export { default as formatMobile } from "./formatMobile";
35
35
  export { default as padZero } from "./padZero";
36
- export { default as transformFieldNames } from "./transformFieldNames";
37
- export { default as listToTree } from "./listToTree";
38
- export { default as treeToList } from "./treeToList";
39
- export { default as filterTree } from "./filterTree";
40
36
  export { default as plus } from "./plus";
41
37
  export { default as minus } from "./minus";
42
38
  export { default as times } from "./times";
@@ -46,6 +42,10 @@ export { default as waitTime } from "./waitTime";
46
42
  export { default as calculateCursorPosition } from "./calculateCursorPosition";
47
43
  export { default as randomString } from "./randomString";
48
44
  export { default as strlen } from "./strlen";
45
+ export { default as transformFieldNames } from "./transformFieldNames";
46
+ export { default as listToTree } from "./listToTree";
47
+ export { default as treeToList } from "./treeToList";
48
+ export { default as filterTree } from "./filterTree";
49
49
  export { default as findTreeNode } from "./findTreeNode";
50
50
  export { default as findTreeNodes } from "./findTreeNodes";
51
51
  export { default as findTreeSelect } from "./findTreeSelect";
@@ -3,7 +3,7 @@ export default listToTree;
3
3
  * 列表数据转树结构
4
4
  *
5
5
  * @static
6
- * @alias module:Processor.listToTree
6
+ * @alias module:Tree.listToTree
7
7
  * @since 4.14.0
8
8
  * @template {Record<string,any>} [T=Record<string,any>]
9
9
  * @template {*} [R=T&Record<string,any>]
@@ -15,20 +15,24 @@ export default replaceChar;
15
15
  * @returns {string} 处理后的字符
16
16
  * @example
17
17
  *
18
- * // 手机号
18
+ * // 手机号 前3后4
19
19
  * replaceChar('13000000000'); // 130****0000
20
20
  *
21
- * // 身份证
22
- * replaceChar('130701199310302288'); // 130***********2288
21
+ * // 身份证 前6后4
22
+ * replaceChar('130701199310302288', { start: 6, end: -4 }); // 130701********2288
23
23
  *
24
- * // 邮箱
24
+ * // 邮箱 @前两位
25
25
  * const email = '12345@qq.com'
26
+ * const emailAtIndex = email.indexOf('@');
27
+ * replaceChar(email, { start: emailAtIndex - 2, end: emailAtIndex }); // 123**@qq.com
28
+ * // 邮箱 前2和@后面内容,固定替换字符4位
26
29
  * replaceChar(email, {start: 2, end: email.indexOf('@'), repeat: 4}); // 12****@qq.com
27
30
  *
28
- * // 银行卡号
31
+ * // 银行卡号 只展示后4位,固定替换字符4位
29
32
  * replaceChar('6228480402564890018', {start: 0, end: -4, repeat: 4}); // ****0018
30
- *
31
- * // 带格式的银行卡号,忽略空字符串
33
+ * // 银行卡号 前6后4
34
+ * replaceChar('6228480402564890018', { start: 6, end: -4 }); // 622848*********0018
35
+ * // 银行卡号 前4后3 忽略格式的空格
32
36
  * replaceChar('6228 4804 0256 4890 018', {start: 4, end: -4, exclude: ' '}); // 6228 **** **** **** 018
33
37
  *
34
38
  * // 用户名
@@ -1,2 +1,2 @@
1
1
  export type ExchangeFieldNames<D extends unknown, F extends Record<string, keyof D>> = Omit<D, F[keyof F]> & { [P in keyof F]: D[F[P]]; };
2
- export type TransformFieldNames<D extends unknown, F extends Record<string, keyof D>, C extends string> = (C extends keyof D ? ExchangeFieldNames<Omit<D, C> & Record<C, TransformFieldNames<D, F, C>>, F> : ExchangeFieldNames<D, F>)[];
2
+ export type TransformFieldNames<D extends unknown, F extends Record<string, any>, C extends string> = (C extends keyof D ? ExchangeFieldNames<Omit<D, C> & Record<C, TransformFieldNames<D, F, C>>, F> : ExchangeFieldNames<D, F>)[];
@@ -3,7 +3,7 @@ export default treeToList;
3
3
  * 树结构转列表数据
4
4
  *
5
5
  * @static
6
- * @alias module:Processor.treeToList
6
+ * @alias module:Tree.treeToList
7
7
  * @since 4.14.0
8
8
  * @template {Record<string,any>} T
9
9
  * @template {keyof T} K