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/dist/util-helpers.js
CHANGED
|
@@ -537,7 +537,7 @@
|
|
|
537
537
|
}
|
|
538
538
|
|
|
539
539
|
// eslint-disable-next-line no-undef
|
|
540
|
-
var version = "4.14.
|
|
540
|
+
var version = "4.14.1";
|
|
541
541
|
|
|
542
542
|
/**
|
|
543
543
|
* 打印警告信息
|
|
@@ -2707,6 +2707,7 @@
|
|
|
2707
2707
|
* @param {D[]} data 对象数组。如果是树结构数据,需要指定第三个参数 childrenFieldName
|
|
2708
2708
|
* @param {F} fieldNames 字段名映射
|
|
2709
2709
|
* @param {C} [childrenFieldName] 子级数据字段名
|
|
2710
|
+
* @param {'spread'|'self'} [nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
|
|
2710
2711
|
* @returns {import('./transformFieldNames.type.js').TransformFieldNames<D, F, C>}
|
|
2711
2712
|
* @example
|
|
2712
2713
|
*
|
|
@@ -2728,6 +2729,7 @@
|
|
|
2728
2729
|
* // [{value: '1', label: 'one'},{value:'2', label:'two', children: [{value: '2-1', label:'two-one'}]}]
|
|
2729
2730
|
*/
|
|
2730
2731
|
function transformFieldNames(data, fieldNames, childrenFieldName) {
|
|
2732
|
+
var nodeAssign = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'spread';
|
|
2731
2733
|
if (!Array.isArray(data)) {
|
|
2732
2734
|
return data;
|
|
2733
2735
|
}
|
|
@@ -2748,7 +2750,7 @@
|
|
|
2748
2750
|
if (!isObject(item)) {
|
|
2749
2751
|
return item;
|
|
2750
2752
|
}
|
|
2751
|
-
var newItem = _objectSpread2({}, item);
|
|
2753
|
+
var newItem = nodeAssign === 'spread' ? _objectSpread2({}, item) : item;
|
|
2752
2754
|
/** @type {Array.<string>} */
|
|
2753
2755
|
var delKeys = [];
|
|
2754
2756
|
|
|
@@ -2831,6 +2833,7 @@
|
|
|
2831
2833
|
* @param {string} [options.parentField='pid'] 当前数据的父级字段名称
|
|
2832
2834
|
* @param {string} [options.childrenField='children'] 子级字段名称
|
|
2833
2835
|
* @param {'none'|'null'|'array'} [options.emptyChildrenValue='none'] 子级为空时的值,none表示删除该子级,null表示为null,array表示为[]。
|
|
2836
|
+
* @param {'spread'|'self'} [options.nodeAssign='spread'] 节点赋值方式。spread表示使用展开运算符创建新值,self表示使用自身对象。
|
|
2834
2837
|
* @returns {R[]} 树结构
|
|
2835
2838
|
* @example
|
|
2836
2839
|
*
|
|
@@ -2860,7 +2863,9 @@
|
|
|
2860
2863
|
_options$childrenFiel2 = options.childrenField,
|
|
2861
2864
|
childrenField = _options$childrenFiel2 === void 0 ? 'children' : _options$childrenFiel2,
|
|
2862
2865
|
_options$emptyChildre2 = options.emptyChildrenValue,
|
|
2863
|
-
emptyChildrenValue = _options$emptyChildre2 === void 0 ? 'none' : _options$emptyChildre2
|
|
2866
|
+
emptyChildrenValue = _options$emptyChildre2 === void 0 ? 'none' : _options$emptyChildre2,
|
|
2867
|
+
_options$nodeAssign = options.nodeAssign,
|
|
2868
|
+
nodeAssign = _options$nodeAssign === void 0 ? 'spread' : _options$nodeAssign;
|
|
2864
2869
|
|
|
2865
2870
|
/** @type {R[]} */
|
|
2866
2871
|
var tree = [];
|
|
@@ -2869,7 +2874,7 @@
|
|
|
2869
2874
|
var record = {};
|
|
2870
2875
|
list.forEach(function (item) {
|
|
2871
2876
|
if (isObject(item)) {
|
|
2872
|
-
var newItem = _objectSpread2({}, item);
|
|
2877
|
+
var newItem = nodeAssign === 'spread' ? _objectSpread2({}, item) : item;
|
|
2873
2878
|
|
|
2874
2879
|
/** @type {string} */
|
|
2875
2880
|
var id = newItem[keyField];
|