utiller 1.0.380 → 1.0.381
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/lib/utiller/index.js +54 -5
- package/package.json +1 -1
- package/template/sample.package.json +1 -1
package/lib/utiller/index.js
CHANGED
|
@@ -930,8 +930,8 @@ var Utiller = /*#__PURE__*/function () {
|
|
|
930
930
|
}, {
|
|
931
931
|
key: "accumulate",
|
|
932
932
|
value:
|
|
933
|
-
/**
|
|
934
|
-
*
|
|
933
|
+
/**
|
|
934
|
+
* 把敘述句和條件子句累加在一起,讓其變成一個合理的functional呼叫
|
|
935
935
|
* condition2(condition1(target)) => 為了應付 collection(path).where('age','>',11).orderBy('age');
|
|
936
936
|
* */
|
|
937
937
|
function accumulate(target, conditions) {
|
|
@@ -4291,8 +4291,55 @@ var Utiller = /*#__PURE__*/function () {
|
|
|
4291
4291
|
}, {});
|
|
4292
4292
|
}
|
|
4293
4293
|
}, {
|
|
4294
|
-
key: "
|
|
4295
|
-
value:
|
|
4294
|
+
key: "mergeArrayByKey",
|
|
4295
|
+
value:
|
|
4296
|
+
/**
|
|
4297
|
+
* 📦 mergeArrayByKey(array)
|
|
4298
|
+
* ---------------------------------------
|
|
4299
|
+
* 將陣列中相同 key 的物件進行「巢狀合併」,並直接 mutate 原陣列內容。
|
|
4300
|
+
*
|
|
4301
|
+
* ✅ 特點:
|
|
4302
|
+
* - 自動合併相同 key 的物件內容(深層合併)
|
|
4303
|
+
* - 不建立新陣列,會直接修改傳入的 array
|
|
4304
|
+
* - 適用於需要整併設定、狀態、表單資料等情境
|
|
4305
|
+
*
|
|
4306
|
+
* 🧩 範例:
|
|
4307
|
+
* ```js
|
|
4308
|
+
* const array = [
|
|
4309
|
+
* { a: { c: 1 } },
|
|
4310
|
+
* { b: { d: 2 } },
|
|
4311
|
+
* { a: { f: 3 } }
|
|
4312
|
+
* ];
|
|
4313
|
+
*
|
|
4314
|
+
* ArrayHelper.mergeArrayByKey(array);
|
|
4315
|
+
*
|
|
4316
|
+
* console.log(array);
|
|
4317
|
+
* // 👉 [ { a: { c: 1, f: 3 } }, { b: { d: 2 } } ]
|
|
4318
|
+
* ```
|
|
4319
|
+
*
|
|
4320
|
+
* @param {Array<Object>} array - 需被合併的物件陣列
|
|
4321
|
+
* @returns {Array<Object>} - 回傳同一個(已被 mutate 的)陣列
|
|
4322
|
+
*/
|
|
4323
|
+
function mergeArrayByKey(array) {
|
|
4324
|
+
if (!Array.isArray(array)) return array;
|
|
4325
|
+
|
|
4326
|
+
// 1️⃣ 利用 lodash 深層合併所有物件(例如 {a:{x}} + {a:{y}} => {a:{x,y}})
|
|
4327
|
+
var merged = _lodash["default"].merge.apply(_lodash["default"], [{}].concat((0, _toConsumableArray2["default"])(array)));
|
|
4328
|
+
|
|
4329
|
+
// 2️⃣ 清空原陣列(mutate)
|
|
4330
|
+
array.length = 0;
|
|
4331
|
+
|
|
4332
|
+
// 3️⃣ 將合併結果重新拆成 [{a:{...}}, {b:{...}}] 結構
|
|
4333
|
+
Object.entries(merged).forEach(function (_ref12) {
|
|
4334
|
+
var _ref13 = (0, _slicedToArray2["default"])(_ref12, 2),
|
|
4335
|
+
key = _ref13[0],
|
|
4336
|
+
value = _ref13[1];
|
|
4337
|
+
array.push((0, _defineProperty2["default"])({}, key, value));
|
|
4338
|
+
});
|
|
4339
|
+
return array;
|
|
4340
|
+
}
|
|
4341
|
+
|
|
4342
|
+
/** ============== 排課系統公式 開始 ============== */
|
|
4296
4343
|
|
|
4297
4344
|
/**
|
|
4298
4345
|
* /const arrayWithDup = [
|
|
@@ -4309,7 +4356,9 @@ var Utiller = /*#__PURE__*/function () {
|
|
|
4309
4356
|
* 2. idOfBooze和idOfVariant為PK, 重複的只保留一組
|
|
4310
4357
|
* 3. 回傳filter array,(反查出哪些課程重複會用到其他資訊)
|
|
4311
4358
|
* */
|
|
4312
|
-
|
|
4359
|
+
}, {
|
|
4360
|
+
key: "getFilteredHeraPeriods",
|
|
4361
|
+
value: function getFilteredHeraPeriods(arr, idOfCurrentBooze) {
|
|
4313
4362
|
return _lodash["default"].chain(arr)
|
|
4314
4363
|
// 1️⃣ 刪掉 idOfBooze 等於目標值的項目
|
|
4315
4364
|
.filter(function (item) {
|
package/package.json
CHANGED