util-helpers 4.14.0 → 4.14.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 +9 -4
- 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/listToTree.js +5 -2
- package/esm/transformFieldNames.doc.js +1 -0
- package/esm/transformFieldNames.js +3 -1
- package/esm/utils/config.js +1 -1
- package/lib/listToTree.js +5 -2
- package/lib/transformFieldNames.doc.js +1 -0
- package/lib/transformFieldNames.js +3 -1
- package/lib/utils/config.js +1 -1
- package/package.json +1 -1
- package/types/listToTree.d.ts +2 -0
- package/types/transformFieldNames.d.ts +2 -1
package/esm/listToTree.js
CHANGED
|
@@ -49,6 +49,7 @@ function processEmptyChildren(arr) {
|
|
|
49
49
|
* @param {string} [options.parentField='pid'] 当前数据的父级字段名称
|
|
50
50
|
* @param {string} [options.childrenField='children'] 子级字段名称
|
|
51
51
|
* @param {'none'|'null'|'array'} [options.emptyChildrenValue='none'] 子级为空时的值,none表示删除该子级,null表示为null,array表示为[]。
|
|
52
|
+
* @param {'spread'|'self'} [options.nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
|
|
52
53
|
* @returns {R[]} 树结构
|
|
53
54
|
* @example
|
|
54
55
|
*
|
|
@@ -78,7 +79,9 @@ function listToTree(list) {
|
|
|
78
79
|
_options$childrenFiel2 = options.childrenField,
|
|
79
80
|
childrenField = _options$childrenFiel2 === void 0 ? 'children' : _options$childrenFiel2,
|
|
80
81
|
_options$emptyChildre2 = options.emptyChildrenValue,
|
|
81
|
-
emptyChildrenValue = _options$emptyChildre2 === void 0 ? 'none' : _options$emptyChildre2
|
|
82
|
+
emptyChildrenValue = _options$emptyChildre2 === void 0 ? 'none' : _options$emptyChildre2,
|
|
83
|
+
_options$nodeAssign = options.nodeAssign,
|
|
84
|
+
nodeAssign = _options$nodeAssign === void 0 ? 'spread' : _options$nodeAssign;
|
|
82
85
|
|
|
83
86
|
/** @type {R[]} */
|
|
84
87
|
var tree = [];
|
|
@@ -87,7 +90,7 @@ function listToTree(list) {
|
|
|
87
90
|
var record = {};
|
|
88
91
|
list.forEach(function (item) {
|
|
89
92
|
if (isObject(item)) {
|
|
90
|
-
var newItem = _objectSpread({}, item);
|
|
93
|
+
var newItem = nodeAssign === 'spread' ? _objectSpread({}, item) : item;
|
|
91
94
|
|
|
92
95
|
/** @type {string} */
|
|
93
96
|
var id = newItem[keyField];
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* @param {object[]} data 对象数组。如果是树结构数据,需要指定第三个参数 childrenFieldName
|
|
11
11
|
* @param {object} fieldNames 字段名映射
|
|
12
12
|
* @param {string} [childrenFieldName] 子级数据字段名
|
|
13
|
+
* @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
|
|
13
14
|
* @returns {object[]}
|
|
14
15
|
* @example
|
|
15
16
|
*
|
|
@@ -18,6 +18,7 @@ import { isObject } from './utils/type';
|
|
|
18
18
|
* @param {D[]} data 对象数组。如果是树结构数据,需要指定第三个参数 childrenFieldName
|
|
19
19
|
* @param {F} fieldNames 字段名映射
|
|
20
20
|
* @param {C} [childrenFieldName] 子级数据字段名
|
|
21
|
+
* @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
|
|
21
22
|
* @returns {import('./transformFieldNames.type.js').TransformFieldNames<D, F, C>}
|
|
22
23
|
* @example
|
|
23
24
|
*
|
|
@@ -39,6 +40,7 @@ import { isObject } from './utils/type';
|
|
|
39
40
|
* // [{value: '1', label: 'one'},{value:'2', label:'two', children: [{value: '2-1', label:'two-one'}]}]
|
|
40
41
|
*/
|
|
41
42
|
function transformFieldNames(data, fieldNames, childrenFieldName) {
|
|
43
|
+
var nodeAssign = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'spread';
|
|
42
44
|
if (!Array.isArray(data)) {
|
|
43
45
|
return data;
|
|
44
46
|
}
|
|
@@ -59,7 +61,7 @@ function transformFieldNames(data, fieldNames, childrenFieldName) {
|
|
|
59
61
|
if (!isObject(item)) {
|
|
60
62
|
return item;
|
|
61
63
|
}
|
|
62
|
-
var newItem = _objectSpread({}, item);
|
|
64
|
+
var newItem = nodeAssign === 'spread' ? _objectSpread({}, item) : item;
|
|
63
65
|
/** @type {Array.<string>} */
|
|
64
66
|
var delKeys = [];
|
|
65
67
|
|
package/esm/utils/config.js
CHANGED
package/lib/listToTree.js
CHANGED
|
@@ -57,6 +57,7 @@ function processEmptyChildren(arr) {
|
|
|
57
57
|
* @param {string} [options.parentField='pid'] 当前数据的父级字段名称
|
|
58
58
|
* @param {string} [options.childrenField='children'] 子级字段名称
|
|
59
59
|
* @param {'none'|'null'|'array'} [options.emptyChildrenValue='none'] 子级为空时的值,none表示删除该子级,null表示为null,array表示为[]。
|
|
60
|
+
* @param {'spread'|'self'} [options.nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
|
|
60
61
|
* @returns {R[]} 树结构
|
|
61
62
|
* @example
|
|
62
63
|
*
|
|
@@ -86,7 +87,9 @@ function listToTree(list) {
|
|
|
86
87
|
_options$childrenFiel2 = options.childrenField,
|
|
87
88
|
childrenField = _options$childrenFiel2 === void 0 ? 'children' : _options$childrenFiel2,
|
|
88
89
|
_options$emptyChildre2 = options.emptyChildrenValue,
|
|
89
|
-
emptyChildrenValue = _options$emptyChildre2 === void 0 ? 'none' : _options$emptyChildre2
|
|
90
|
+
emptyChildrenValue = _options$emptyChildre2 === void 0 ? 'none' : _options$emptyChildre2,
|
|
91
|
+
_options$nodeAssign = options.nodeAssign,
|
|
92
|
+
nodeAssign = _options$nodeAssign === void 0 ? 'spread' : _options$nodeAssign;
|
|
90
93
|
|
|
91
94
|
/** @type {R[]} */
|
|
92
95
|
var tree = [];
|
|
@@ -95,7 +98,7 @@ function listToTree(list) {
|
|
|
95
98
|
var record = {};
|
|
96
99
|
list.forEach(function (item) {
|
|
97
100
|
if ((0, _type.isObject)(item)) {
|
|
98
|
-
var newItem = _objectSpread({}, item);
|
|
101
|
+
var newItem = nodeAssign === 'spread' ? _objectSpread({}, item) : item;
|
|
99
102
|
|
|
100
103
|
/** @type {string} */
|
|
101
104
|
var id = newItem[keyField];
|
|
@@ -16,6 +16,7 @@ exports["default"] = void 0;
|
|
|
16
16
|
* @param {object[]} data 对象数组。如果是树结构数据,需要指定第三个参数 childrenFieldName
|
|
17
17
|
* @param {object} fieldNames 字段名映射
|
|
18
18
|
* @param {string} [childrenFieldName] 子级数据字段名
|
|
19
|
+
* @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
|
|
19
20
|
* @returns {object[]}
|
|
20
21
|
* @example
|
|
21
22
|
*
|
|
@@ -23,6 +23,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
23
23
|
* @param {D[]} data 对象数组。如果是树结构数据,需要指定第三个参数 childrenFieldName
|
|
24
24
|
* @param {F} fieldNames 字段名映射
|
|
25
25
|
* @param {C} [childrenFieldName] 子级数据字段名
|
|
26
|
+
* @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
|
|
26
27
|
* @returns {import('./transformFieldNames.type.js').TransformFieldNames<D, F, C>}
|
|
27
28
|
* @example
|
|
28
29
|
*
|
|
@@ -44,6 +45,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
44
45
|
* // [{value: '1', label: 'one'},{value:'2', label:'two', children: [{value: '2-1', label:'two-one'}]}]
|
|
45
46
|
*/
|
|
46
47
|
function transformFieldNames(data, fieldNames, childrenFieldName) {
|
|
48
|
+
var nodeAssign = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'spread';
|
|
47
49
|
if (!Array.isArray(data)) {
|
|
48
50
|
return data;
|
|
49
51
|
}
|
|
@@ -64,7 +66,7 @@ function transformFieldNames(data, fieldNames, childrenFieldName) {
|
|
|
64
66
|
if (!(0, _type.isObject)(item)) {
|
|
65
67
|
return item;
|
|
66
68
|
}
|
|
67
|
-
var newItem = _objectSpread({}, item);
|
|
69
|
+
var newItem = nodeAssign === 'spread' ? _objectSpread({}, item) : item;
|
|
68
70
|
/** @type {Array.<string>} */
|
|
69
71
|
var delKeys = [];
|
|
70
72
|
|
package/lib/utils/config.js
CHANGED
package/package.json
CHANGED
package/types/listToTree.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export default listToTree;
|
|
|
13
13
|
* @param {string} [options.parentField='pid'] 当前数据的父级字段名称
|
|
14
14
|
* @param {string} [options.childrenField='children'] 子级字段名称
|
|
15
15
|
* @param {'none'|'null'|'array'} [options.emptyChildrenValue='none'] 子级为空时的值,none表示删除该子级,null表示为null,array表示为[]。
|
|
16
|
+
* @param {'spread'|'self'} [options.nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
|
|
16
17
|
* @returns {R[]} 树结构
|
|
17
18
|
* @example
|
|
18
19
|
*
|
|
@@ -38,4 +39,5 @@ declare function listToTree<T extends Record<string, any> = Record<string, any>,
|
|
|
38
39
|
parentField?: string | undefined;
|
|
39
40
|
childrenField?: string | undefined;
|
|
40
41
|
emptyChildrenValue?: "none" | "null" | "array" | undefined;
|
|
42
|
+
nodeAssign?: "spread" | "self" | undefined;
|
|
41
43
|
}): R[];
|
|
@@ -11,6 +11,7 @@ export default transformFieldNames;
|
|
|
11
11
|
* @param {D[]} data 对象数组。如果是树结构数据,需要指定第三个参数 childrenFieldName
|
|
12
12
|
* @param {F} fieldNames 字段名映射
|
|
13
13
|
* @param {C} [childrenFieldName] 子级数据字段名
|
|
14
|
+
* @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
|
|
14
15
|
* @returns {import('./transformFieldNames.type.js').TransformFieldNames<D, F, C>}
|
|
15
16
|
* @example
|
|
16
17
|
*
|
|
@@ -31,4 +32,4 @@ export default transformFieldNames;
|
|
|
31
32
|
* const newOptions4 = transformFieldNames(options3, {label: 'name', value: 'code', children: 'childs'}, 'childs');
|
|
32
33
|
* // [{value: '1', label: 'one'},{value:'2', label:'two', children: [{value: '2-1', label:'two-one'}]}]
|
|
33
34
|
*/
|
|
34
|
-
declare function transformFieldNames<D extends unknown, F extends Record<string, keyof D>, C extends string>(data: D[], fieldNames: F, childrenFieldName?: C | undefined): import("./transformFieldNames.type.js").TransformFieldNames<D, F, C>;
|
|
35
|
+
declare function transformFieldNames<D extends unknown, F extends Record<string, keyof D>, C extends string>(data: D[], fieldNames: F, childrenFieldName?: C | undefined, nodeAssign?: "spread" | "self" | undefined): import("./transformFieldNames.type.js").TransformFieldNames<D, F, C>;
|