util-helpers 4.15.0 → 4.15.1
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 +66 -61
- 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/filterTree.js +3 -4
- package/esm/findTreeNode.js +3 -0
- package/esm/findTreeNodes.js +3 -0
- package/esm/findTreeSelect.js +3 -4
- 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/filterTree.js +3 -4
- package/lib/findTreeNode.js +3 -0
- package/lib/findTreeNodes.js +3 -0
- package/lib/findTreeSelect.js +3 -4
- 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/listToTree.d.ts +2 -2
package/esm/filterTree.js
CHANGED
|
@@ -32,12 +32,11 @@ import { isObject } from "./utils/type";
|
|
|
32
32
|
function filterTree(tree, predicate) {
|
|
33
33
|
var childrenField = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children';
|
|
34
34
|
var nodeAssign = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'spread';
|
|
35
|
-
if (!Array.isArray(tree)) {
|
|
36
|
-
return tree;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
35
|
/** @type {T[]} */
|
|
40
36
|
var result = [];
|
|
37
|
+
if (!Array.isArray(tree)) {
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
41
40
|
tree.forEach(function (item) {
|
|
42
41
|
var newItem = item;
|
|
43
42
|
if (isObject(item)) {
|
package/esm/findTreeNode.js
CHANGED
package/esm/findTreeNodes.js
CHANGED
package/esm/findTreeSelect.js
CHANGED
|
@@ -11,14 +11,13 @@ import { isObject } from "./utils/type";
|
|
|
11
11
|
* @template {(item: T) => boolean} F
|
|
12
12
|
* @param {T[]} tree 树结构数据
|
|
13
13
|
* @param {F} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 Truthy 将返回包含该节点的所有父级节点
|
|
14
|
-
* @param {string} [childrenField
|
|
14
|
+
* @param {string} [childrenField] 子级字段名
|
|
15
15
|
* @param {T[]} [path=[]] 当前遍历路径
|
|
16
16
|
* @returns {T[]}
|
|
17
17
|
*/
|
|
18
|
-
function internalFindTreeSelect(tree, predicate) {
|
|
19
|
-
var childrenField = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children';
|
|
18
|
+
function internalFindTreeSelect(tree, predicate, childrenField) {
|
|
20
19
|
var path = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
21
|
-
if (!tree) {
|
|
20
|
+
if (!Array.isArray(tree)) {
|
|
22
21
|
return [];
|
|
23
22
|
}
|
|
24
23
|
var _iterator = _createForOfIteratorHelper(tree),
|
package/esm/listToTree.js
CHANGED
|
@@ -9,29 +9,30 @@ import { isObject } from "./utils/type";
|
|
|
9
9
|
* @private
|
|
10
10
|
* @template {Record<string,any>} [T=Record<string,any>]
|
|
11
11
|
* @param {T[]} arr 列表数据
|
|
12
|
-
* @param {object} options 配置项
|
|
12
|
+
* @param {object} [options] 配置项
|
|
13
13
|
* @param {string} [options.childrenField='children'] 子级字段名称
|
|
14
|
-
* @param {'none'|'null'
|
|
14
|
+
* @param {'none'|'null'} [options.emptyChildrenValue='none'] 子级为空时的值,none表示删除该子级,null表示为null,array表示为[]。
|
|
15
15
|
*/
|
|
16
|
-
function processEmptyChildren(arr) {
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
childrenField =
|
|
20
|
-
|
|
21
|
-
emptyChildrenValue =
|
|
16
|
+
function processEmptyChildren(arr, options) {
|
|
17
|
+
var _ref = options || {},
|
|
18
|
+
_ref$childrenField = _ref.childrenField,
|
|
19
|
+
childrenField = _ref$childrenField === void 0 ? 'children' : _ref$childrenField,
|
|
20
|
+
_ref$emptyChildrenVal = _ref.emptyChildrenValue,
|
|
21
|
+
emptyChildrenValue = _ref$emptyChildrenVal === void 0 ? 'none' : _ref$emptyChildrenVal;
|
|
22
22
|
arr.forEach(function (item) {
|
|
23
|
-
if (isObject(item) && Array.isArray(item[childrenField])) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} else if (emptyChildrenValue === 'none') {
|
|
29
|
-
delete item[childrenField];
|
|
30
|
-
}
|
|
23
|
+
// if (isObject(item) && Array.isArray(item[childrenField])) {
|
|
24
|
+
if (item[childrenField].length <= 0) {
|
|
25
|
+
if (emptyChildrenValue === 'null') {
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
item[childrenField] = null;
|
|
28
|
+
// } else if (emptyChildrenValue === 'none') { // emptyChildrenValue='array' 不会执行该内部方法
|
|
31
29
|
} else {
|
|
32
|
-
|
|
30
|
+
delete item[childrenField];
|
|
33
31
|
}
|
|
32
|
+
} else {
|
|
33
|
+
processEmptyChildren(item[childrenField], options);
|
|
34
34
|
}
|
|
35
|
+
// }
|
|
35
36
|
});
|
|
36
37
|
}
|
|
37
38
|
|
|
@@ -44,7 +45,7 @@ function processEmptyChildren(arr) {
|
|
|
44
45
|
* @template {Record<string,any>} [T=Record<string,any>]
|
|
45
46
|
* @template {*} [R=T&Record<string,any>]
|
|
46
47
|
* @param {T[]} list 列表数据
|
|
47
|
-
* @param {object} options 配置项
|
|
48
|
+
* @param {object} [options] 配置项
|
|
48
49
|
* @param {string} [options.keyField='id'] 当前数据的键值字段名称
|
|
49
50
|
* @param {string} [options.parentField='pid'] 当前数据的父级字段名称
|
|
50
51
|
* @param {string} [options.childrenField='children'] 子级字段名称
|
|
@@ -70,24 +71,27 @@ function processEmptyChildren(arr) {
|
|
|
70
71
|
* // [{"id":"1","name":"首页","code":"trade","pid":null},{"id":"2","name":"交易管理","code":"trade","pid":null,"childs":[{"id":"3","name":"交易查询","code":"trade-1","pid":"2","childs":[{"id":"4","name":"交易查询-查询操作","code":"trade-1-1","pid":"3"}]}]},{"id":"5","name":"权限管理","code":"authorization","pid":null,"childs":[{"id":"6","name":"角色管理","code":"authorization-1","pid":"5"},{"id":"7","name":"用户管理","code":"authorization-2","pid":"5"}]}]
|
|
71
72
|
*
|
|
72
73
|
*/
|
|
73
|
-
function listToTree(list) {
|
|
74
|
-
var
|
|
75
|
-
|
|
76
|
-
keyField =
|
|
77
|
-
|
|
78
|
-
parentField =
|
|
79
|
-
|
|
80
|
-
childrenField =
|
|
81
|
-
|
|
82
|
-
emptyChildrenValue =
|
|
83
|
-
|
|
84
|
-
nodeAssign =
|
|
74
|
+
function listToTree(list, options) {
|
|
75
|
+
var _ref2 = options || {},
|
|
76
|
+
_ref2$keyField = _ref2.keyField,
|
|
77
|
+
keyField = _ref2$keyField === void 0 ? 'id' : _ref2$keyField,
|
|
78
|
+
_ref2$parentField = _ref2.parentField,
|
|
79
|
+
parentField = _ref2$parentField === void 0 ? 'pid' : _ref2$parentField,
|
|
80
|
+
_ref2$childrenField = _ref2.childrenField,
|
|
81
|
+
childrenField = _ref2$childrenField === void 0 ? 'children' : _ref2$childrenField,
|
|
82
|
+
_ref2$emptyChildrenVa = _ref2.emptyChildrenValue,
|
|
83
|
+
emptyChildrenValue = _ref2$emptyChildrenVa === void 0 ? 'none' : _ref2$emptyChildrenVa,
|
|
84
|
+
_ref2$nodeAssign = _ref2.nodeAssign,
|
|
85
|
+
nodeAssign = _ref2$nodeAssign === void 0 ? 'spread' : _ref2$nodeAssign;
|
|
85
86
|
|
|
86
87
|
/** @type {R[]} */
|
|
87
88
|
var tree = [];
|
|
88
89
|
|
|
89
90
|
/** @type {Object.<string, T[]>} */
|
|
90
91
|
var record = {};
|
|
92
|
+
if (!Array.isArray(list)) {
|
|
93
|
+
return tree;
|
|
94
|
+
}
|
|
91
95
|
list.forEach(function (item) {
|
|
92
96
|
if (isObject(item)) {
|
|
93
97
|
var newItem = nodeAssign === 'spread' ? _objectSpread({}, item) : item;
|
package/esm/parseIdCard.js
CHANGED
|
@@ -98,24 +98,21 @@ var Provinces = [
|
|
|
98
98
|
*
|
|
99
99
|
*/
|
|
100
100
|
function parseIdCard(id) {
|
|
101
|
-
|
|
101
|
+
var match = regIdCard.exec(id);
|
|
102
|
+
if (!match) {
|
|
102
103
|
return null;
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
/** @type {RegExpExecArray} */
|
|
106
|
-
// @ts-ignore
|
|
107
|
-
var info = regIdCard.exec(id);
|
|
108
|
-
|
|
109
106
|
/** @type {{ province: string, city: string, area: string, year: string, month: string, day: string, gender: string }} */
|
|
110
107
|
// @ts-ignore
|
|
111
|
-
var origin =
|
|
112
|
-
province:
|
|
113
|
-
city:
|
|
114
|
-
area:
|
|
115
|
-
year:
|
|
116
|
-
month:
|
|
117
|
-
day:
|
|
118
|
-
gender:
|
|
108
|
+
var origin = match.groups || {
|
|
109
|
+
province: match[1],
|
|
110
|
+
city: match[2],
|
|
111
|
+
area: match[3],
|
|
112
|
+
year: match[4],
|
|
113
|
+
month: match[5],
|
|
114
|
+
day: match[6],
|
|
115
|
+
gender: match[7]
|
|
119
116
|
};
|
|
120
117
|
var province = Provinces.find(function (item) {
|
|
121
118
|
return item[0] === origin.province;
|
package/esm/randomString.js
CHANGED
|
@@ -4,14 +4,12 @@ var defaultChars = numberChars + letterChars + letterChars.toUpperCase();
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @private
|
|
7
|
-
* @param {number}
|
|
8
|
-
* @param {string}
|
|
7
|
+
* @param {number} len 长度
|
|
8
|
+
* @param {string} optionalChars 允许的字符,默认为数字和大小写字母
|
|
9
9
|
* @param {string} [prefix=''] 前缀部分,不计入长度
|
|
10
10
|
* @returns {string}
|
|
11
11
|
*/
|
|
12
|
-
function internalRandomString() {
|
|
13
|
-
var len = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
14
|
-
var optionalChars = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultChars;
|
|
12
|
+
function internalRandomString(len, optionalChars) {
|
|
15
13
|
var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
16
14
|
while (len-- > 0) {
|
|
17
15
|
var r = optionalChars[Math.floor(Math.random() * optionalChars.length)];
|
|
@@ -55,8 +55,7 @@ function transformFieldNames(data, fieldNames, childrenField) {
|
|
|
55
55
|
* @param {Array.<object>} arr 列表数据
|
|
56
56
|
* @returns {*}
|
|
57
57
|
*/
|
|
58
|
-
function recusion() {
|
|
59
|
-
var arr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
58
|
+
function recusion(arr) {
|
|
60
59
|
return arr.map(function (item) {
|
|
61
60
|
if (!isObject(item)) {
|
|
62
61
|
return item;
|
package/esm/treeToList.js
CHANGED
|
@@ -24,6 +24,9 @@ import { isObject } from "./utils/type";
|
|
|
24
24
|
function treeToList(tree, childrenField) {
|
|
25
25
|
/** @type {R[]} */
|
|
26
26
|
var list = [];
|
|
27
|
+
if (!Array.isArray(tree)) {
|
|
28
|
+
return list;
|
|
29
|
+
}
|
|
27
30
|
|
|
28
31
|
/**
|
|
29
32
|
* 递归遍历
|
|
@@ -35,7 +38,7 @@ function treeToList(tree, childrenField) {
|
|
|
35
38
|
var newItem = _objectSpread({}, item);
|
|
36
39
|
// @ts-ignore
|
|
37
40
|
list.push(newItem);
|
|
38
|
-
if (newItem
|
|
41
|
+
if (newItem[childrenField]) {
|
|
39
42
|
if (Array.isArray(newItem[childrenField]) && newItem[childrenField].length > 0) {
|
|
40
43
|
recusion(newItem[childrenField]);
|
|
41
44
|
}
|
package/esm/utils/config.js
CHANGED
package/lib/filterTree.js
CHANGED
|
@@ -40,12 +40,11 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
40
40
|
function filterTree(tree, predicate) {
|
|
41
41
|
var childrenField = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children';
|
|
42
42
|
var nodeAssign = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'spread';
|
|
43
|
-
if (!Array.isArray(tree)) {
|
|
44
|
-
return tree;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
43
|
/** @type {T[]} */
|
|
48
44
|
var result = [];
|
|
45
|
+
if (!Array.isArray(tree)) {
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
49
48
|
tree.forEach(function (item) {
|
|
50
49
|
var newItem = item;
|
|
51
50
|
if ((0, _type.isObject)(item)) {
|
package/lib/findTreeNode.js
CHANGED
package/lib/findTreeNodes.js
CHANGED
package/lib/findTreeSelect.js
CHANGED
|
@@ -16,14 +16,13 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
16
16
|
* @template {(item: T) => boolean} F
|
|
17
17
|
* @param {T[]} tree 树结构数据
|
|
18
18
|
* @param {F} predicate 遍历每一项执行的函数,参数是当前遍历到的节点数据,如果返回 Truthy 将返回包含该节点的所有父级节点
|
|
19
|
-
* @param {string} [childrenField
|
|
19
|
+
* @param {string} [childrenField] 子级字段名
|
|
20
20
|
* @param {T[]} [path=[]] 当前遍历路径
|
|
21
21
|
* @returns {T[]}
|
|
22
22
|
*/
|
|
23
|
-
function internalFindTreeSelect(tree, predicate) {
|
|
24
|
-
var childrenField = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'children';
|
|
23
|
+
function internalFindTreeSelect(tree, predicate, childrenField) {
|
|
25
24
|
var path = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
26
|
-
if (!tree) {
|
|
25
|
+
if (!Array.isArray(tree)) {
|
|
27
26
|
return [];
|
|
28
27
|
}
|
|
29
28
|
var _iterator = _createForOfIteratorHelper(tree),
|
package/lib/listToTree.js
CHANGED
|
@@ -17,29 +17,30 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
17
17
|
* @private
|
|
18
18
|
* @template {Record<string,any>} [T=Record<string,any>]
|
|
19
19
|
* @param {T[]} arr 列表数据
|
|
20
|
-
* @param {object} options 配置项
|
|
20
|
+
* @param {object} [options] 配置项
|
|
21
21
|
* @param {string} [options.childrenField='children'] 子级字段名称
|
|
22
|
-
* @param {'none'|'null'
|
|
22
|
+
* @param {'none'|'null'} [options.emptyChildrenValue='none'] 子级为空时的值,none表示删除该子级,null表示为null,array表示为[]。
|
|
23
23
|
*/
|
|
24
|
-
function processEmptyChildren(arr) {
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
childrenField =
|
|
28
|
-
|
|
29
|
-
emptyChildrenValue =
|
|
24
|
+
function processEmptyChildren(arr, options) {
|
|
25
|
+
var _ref = options || {},
|
|
26
|
+
_ref$childrenField = _ref.childrenField,
|
|
27
|
+
childrenField = _ref$childrenField === void 0 ? 'children' : _ref$childrenField,
|
|
28
|
+
_ref$emptyChildrenVal = _ref.emptyChildrenValue,
|
|
29
|
+
emptyChildrenValue = _ref$emptyChildrenVal === void 0 ? 'none' : _ref$emptyChildrenVal;
|
|
30
30
|
arr.forEach(function (item) {
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
} else if (emptyChildrenValue === 'none') {
|
|
37
|
-
delete item[childrenField];
|
|
38
|
-
}
|
|
31
|
+
// if (isObject(item) && Array.isArray(item[childrenField])) {
|
|
32
|
+
if (item[childrenField].length <= 0) {
|
|
33
|
+
if (emptyChildrenValue === 'null') {
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
item[childrenField] = null;
|
|
36
|
+
// } else if (emptyChildrenValue === 'none') { // emptyChildrenValue='array' 不会执行该内部方法
|
|
39
37
|
} else {
|
|
40
|
-
|
|
38
|
+
delete item[childrenField];
|
|
41
39
|
}
|
|
40
|
+
} else {
|
|
41
|
+
processEmptyChildren(item[childrenField], options);
|
|
42
42
|
}
|
|
43
|
+
// }
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
46
|
|
|
@@ -52,7 +53,7 @@ function processEmptyChildren(arr) {
|
|
|
52
53
|
* @template {Record<string,any>} [T=Record<string,any>]
|
|
53
54
|
* @template {*} [R=T&Record<string,any>]
|
|
54
55
|
* @param {T[]} list 列表数据
|
|
55
|
-
* @param {object} options 配置项
|
|
56
|
+
* @param {object} [options] 配置项
|
|
56
57
|
* @param {string} [options.keyField='id'] 当前数据的键值字段名称
|
|
57
58
|
* @param {string} [options.parentField='pid'] 当前数据的父级字段名称
|
|
58
59
|
* @param {string} [options.childrenField='children'] 子级字段名称
|
|
@@ -78,24 +79,27 @@ function processEmptyChildren(arr) {
|
|
|
78
79
|
* // [{"id":"1","name":"首页","code":"trade","pid":null},{"id":"2","name":"交易管理","code":"trade","pid":null,"childs":[{"id":"3","name":"交易查询","code":"trade-1","pid":"2","childs":[{"id":"4","name":"交易查询-查询操作","code":"trade-1-1","pid":"3"}]}]},{"id":"5","name":"权限管理","code":"authorization","pid":null,"childs":[{"id":"6","name":"角色管理","code":"authorization-1","pid":"5"},{"id":"7","name":"用户管理","code":"authorization-2","pid":"5"}]}]
|
|
79
80
|
*
|
|
80
81
|
*/
|
|
81
|
-
function listToTree(list) {
|
|
82
|
-
var
|
|
83
|
-
|
|
84
|
-
keyField =
|
|
85
|
-
|
|
86
|
-
parentField =
|
|
87
|
-
|
|
88
|
-
childrenField =
|
|
89
|
-
|
|
90
|
-
emptyChildrenValue =
|
|
91
|
-
|
|
92
|
-
nodeAssign =
|
|
82
|
+
function listToTree(list, options) {
|
|
83
|
+
var _ref2 = options || {},
|
|
84
|
+
_ref2$keyField = _ref2.keyField,
|
|
85
|
+
keyField = _ref2$keyField === void 0 ? 'id' : _ref2$keyField,
|
|
86
|
+
_ref2$parentField = _ref2.parentField,
|
|
87
|
+
parentField = _ref2$parentField === void 0 ? 'pid' : _ref2$parentField,
|
|
88
|
+
_ref2$childrenField = _ref2.childrenField,
|
|
89
|
+
childrenField = _ref2$childrenField === void 0 ? 'children' : _ref2$childrenField,
|
|
90
|
+
_ref2$emptyChildrenVa = _ref2.emptyChildrenValue,
|
|
91
|
+
emptyChildrenValue = _ref2$emptyChildrenVa === void 0 ? 'none' : _ref2$emptyChildrenVa,
|
|
92
|
+
_ref2$nodeAssign = _ref2.nodeAssign,
|
|
93
|
+
nodeAssign = _ref2$nodeAssign === void 0 ? 'spread' : _ref2$nodeAssign;
|
|
93
94
|
|
|
94
95
|
/** @type {R[]} */
|
|
95
96
|
var tree = [];
|
|
96
97
|
|
|
97
98
|
/** @type {Object.<string, T[]>} */
|
|
98
99
|
var record = {};
|
|
100
|
+
if (!Array.isArray(list)) {
|
|
101
|
+
return tree;
|
|
102
|
+
}
|
|
99
103
|
list.forEach(function (item) {
|
|
100
104
|
if ((0, _type.isObject)(item)) {
|
|
101
105
|
var newItem = nodeAssign === 'spread' ? _objectSpread({}, item) : item;
|
package/lib/parseIdCard.js
CHANGED
|
@@ -104,24 +104,21 @@ var Provinces = [
|
|
|
104
104
|
*
|
|
105
105
|
*/
|
|
106
106
|
function parseIdCard(id) {
|
|
107
|
-
|
|
107
|
+
var match = regIdCard.exec(id);
|
|
108
|
+
if (!match) {
|
|
108
109
|
return null;
|
|
109
110
|
}
|
|
110
111
|
|
|
111
|
-
/** @type {RegExpExecArray} */
|
|
112
|
-
// @ts-ignore
|
|
113
|
-
var info = regIdCard.exec(id);
|
|
114
|
-
|
|
115
112
|
/** @type {{ province: string, city: string, area: string, year: string, month: string, day: string, gender: string }} */
|
|
116
113
|
// @ts-ignore
|
|
117
|
-
var origin =
|
|
118
|
-
province:
|
|
119
|
-
city:
|
|
120
|
-
area:
|
|
121
|
-
year:
|
|
122
|
-
month:
|
|
123
|
-
day:
|
|
124
|
-
gender:
|
|
114
|
+
var origin = match.groups || {
|
|
115
|
+
province: match[1],
|
|
116
|
+
city: match[2],
|
|
117
|
+
area: match[3],
|
|
118
|
+
year: match[4],
|
|
119
|
+
month: match[5],
|
|
120
|
+
day: match[6],
|
|
121
|
+
gender: match[7]
|
|
125
122
|
};
|
|
126
123
|
var province = Provinces.find(function (item) {
|
|
127
124
|
return item[0] === origin.province;
|
package/lib/randomString.js
CHANGED
|
@@ -10,14 +10,12 @@ var defaultChars = numberChars + letterChars + letterChars.toUpperCase();
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @private
|
|
13
|
-
* @param {number}
|
|
14
|
-
* @param {string}
|
|
13
|
+
* @param {number} len 长度
|
|
14
|
+
* @param {string} optionalChars 允许的字符,默认为数字和大小写字母
|
|
15
15
|
* @param {string} [prefix=''] 前缀部分,不计入长度
|
|
16
16
|
* @returns {string}
|
|
17
17
|
*/
|
|
18
|
-
function internalRandomString() {
|
|
19
|
-
var len = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
20
|
-
var optionalChars = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultChars;
|
|
18
|
+
function internalRandomString(len, optionalChars) {
|
|
21
19
|
var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
22
20
|
while (len-- > 0) {
|
|
23
21
|
var r = optionalChars[Math.floor(Math.random() * optionalChars.length)];
|
|
@@ -60,8 +60,7 @@ function transformFieldNames(data, fieldNames, childrenField) {
|
|
|
60
60
|
* @param {Array.<object>} arr 列表数据
|
|
61
61
|
* @returns {*}
|
|
62
62
|
*/
|
|
63
|
-
function recusion() {
|
|
64
|
-
var arr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
63
|
+
function recusion(arr) {
|
|
65
64
|
return arr.map(function (item) {
|
|
66
65
|
if (!(0, _type.isObject)(item)) {
|
|
67
66
|
return item;
|
package/lib/treeToList.js
CHANGED
|
@@ -32,6 +32,9 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
32
32
|
function treeToList(tree, childrenField) {
|
|
33
33
|
/** @type {R[]} */
|
|
34
34
|
var list = [];
|
|
35
|
+
if (!Array.isArray(tree)) {
|
|
36
|
+
return list;
|
|
37
|
+
}
|
|
35
38
|
|
|
36
39
|
/**
|
|
37
40
|
* 递归遍历
|
|
@@ -43,7 +46,7 @@ function treeToList(tree, childrenField) {
|
|
|
43
46
|
var newItem = _objectSpread({}, item);
|
|
44
47
|
// @ts-ignore
|
|
45
48
|
list.push(newItem);
|
|
46
|
-
if (newItem
|
|
49
|
+
if (newItem[childrenField]) {
|
|
47
50
|
if (Array.isArray(newItem[childrenField]) && newItem[childrenField].length > 0) {
|
|
48
51
|
recusion(newItem[childrenField]);
|
|
49
52
|
}
|
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.1",
|
|
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/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[];
|