utiller 1.0.347 → 1.0.348

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.
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports["default"] = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
- var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray"));
10
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
10
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
12
11
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
@@ -352,25 +351,6 @@ var Utiller = /*#__PURE__*/function () {
352
351
  cloned.splice(targetIndex, 0, object);
353
352
  return cloned;
354
353
  });
355
- /**
356
- * 編碼成 Firestore-safe UID(Base64 URL 安全版,可還原)
357
- */
358
- (0, _defineProperty2["default"])(this, "encodeToUid", function (str) {
359
- var utf8Bytes = new TextEncoder().encode(str);
360
- var base64 = btoa(String.fromCharCode.apply(String, (0, _toConsumableArray2["default"])(utf8Bytes)));
361
- return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
362
- });
363
- /**
364
- * 解碼 UID 回原始組合
365
- */
366
- (0, _defineProperty2["default"])(this, "decodeFromUid", function (uid) {
367
- var base64 = uid.replace(/-/g, "+").replace(/_/g, "/");
368
- var binary = atob(base64);
369
- var bytes = Uint8Array.from(binary, function (c) {
370
- return c.charCodeAt(0);
371
- });
372
- return new TextDecoder().decode(bytes);
373
- });
374
354
  /**
375
355
  * const origin = [
376
356
  * { label: 'aa', value: 1203 },
@@ -583,6 +563,37 @@ var Utiller = /*#__PURE__*/function () {
583
563
  });
584
564
  });
585
565
  });
566
+ /**
567
+ * 將 array2 的對應項目合併到 array1 中(支援巢狀 idKey 路徑)
568
+ * @param {Array<Object>} array1
569
+ * @param {Array<Object>} array2
570
+ * @param {string} idKey - 用來比對的 key(可為巢狀路徑,例如 'meta.id')
571
+ * @returns {Array<Object>} - 合併後的 array1
572
+ *
573
+ * const array1 = [
574
+ * { meta: { id: 'a1' }, name: 'Red' },
575
+ * { meta: { id: 'b2' }, name: 'Black' }
576
+ * ];
577
+ *
578
+ * const array2 = [
579
+ * { meta: { id: 'a1' }, price: 200 },
580
+ * { meta: { id: 'b2' }, name: 'Black Special' }
581
+ * ];
582
+ *
583
+ * const result = mergeById(array1, array2, 'meta.id');
584
+ * console.log(result);
585
+ */
586
+ (0, _defineProperty2["default"])(this, "getArrayOfMergeBySpecificId", function (array1, array2) {
587
+ var idKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "id";
588
+ var map2 = _lodash["default"].keyBy(array2, function (item) {
589
+ return _lodash["default"].get(item, idKey);
590
+ });
591
+ return array1.map(function (item) {
592
+ var id = _lodash["default"].get(item, idKey);
593
+ var match = map2[id];
594
+ return match ? _lodash["default"].merge({}, item, match) : item;
595
+ });
596
+ });
586
597
  this.init();
587
598
  this.env = "dev";
588
599
  }
@@ -3999,107 +4010,9 @@ var Utiller = /*#__PURE__*/function () {
3999
4010
  }).keys().compact() // 過濾掉 null, undefined, '' 等 falsy 值
4000
4011
  .value();
4001
4012
  }
4002
- }, {
4003
- key: "generateUidCombinations",
4004
- value:
4005
- /** ------------------------------------------------------------------------------------- 起始UID-COMBINATION
4006
- * 建立組合清單及 UID 映射清單
4007
- *
4008
- * 原始資料組合
4009
- * const array1 = ['黑色', '綠色']
4010
- * const array2 = ['S', 'M']
4011
- * const array3 = ['短袖', '長袖']
4012
- *
4013
- * 產生 UID 清單
4014
- * const uidList = generateUidCombinations([array1, array2, array3])
4015
- *
4016
- * console.log('📦 所有組合的 UID 對照:')
4017
- * console.log(uidList)
4018
- *
4019
- * 建立查詢表(可選)
4020
- * const lookupTable = buildLookupTable(uidList)
4021
- *
4022
- * 任選一個 UID 測試還原
4023
- * const sampleUid = Object.keys(uidList[2])[0]
4024
- * console.log('\n🔍 測試 UID:', sampleUid)
4025
- * console.log('✅ 還原結果:', getOriginalFromUid(sampleUid, lookupTable))
4026
- *
4027
- */
4028
- /**
4029
- * 產生所有排列組合並轉成 Firestore-safe UID
4030
- * @param {string[][]} arrays - 字串陣列的陣列,例如 [['黑色', '綠色'], ['S', 'M']]
4031
- * @param {string} separator - 分隔符號,預設為 ' | '
4032
- * @returns {Array<{[uid: string]: string}>} - 每個 UID 對應一組原始組合的對照表陣列
4033
- */
4034
- function generateUidCombinations(arrays) {
4035
- var _this4 = this;
4036
- var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : " | ";
4037
- if (!arrays.length) return [];
4038
-
4039
- // 過濾每個子陣列中的 null、undefined、空字串
4040
- var sanitizedArrays = arrays.map(function (group) {
4041
- return group.filter(function (item) {
4042
- return item !== null && item !== undefined && item !== "";
4043
- });
4044
- }).filter(function (group) {
4045
- return group.length > 0;
4046
- }); // 移除空子陣列
4047
-
4048
- // 若最終沒東西,回傳空
4049
- if (sanitizedArrays.length === 0) return [];
4050
-
4051
- // 只有一組有效子陣列,直接映射
4052
- if (sanitizedArrays.length === 1) {
4053
- return sanitizedArrays[0].map(function (str) {
4054
- var uid = _this4.encodeToUid(str);
4055
- return (0, _defineProperty2["default"])({}, uid, str);
4056
- });
4057
- }
4058
-
4059
- // 多組時進行組合
4060
- var _sanitizedArrays = (0, _toArray2["default"])(sanitizedArrays),
4061
- first = _sanitizedArrays[0],
4062
- rest = _sanitizedArrays.slice(1);
4063
- var combinations = rest.reduce(function (acc, curr) {
4064
- return _lodash["default"].flatMap(acc, function (a) {
4065
- return curr.map(function (b) {
4066
- return (Array.isArray(a) ? a.join(separator) : a) + separator + b;
4067
- });
4068
- });
4069
- }, first);
4070
- return combinations.map(function (str) {
4071
- var uid = _this4.encodeToUid(str);
4072
- return (0, _defineProperty2["default"])({}, uid, str);
4073
- });
4074
- }
4075
-
4076
- /**
4077
- * 快速建立 UID -> 組合 對照表(Object)
4078
- */
4079
- }, {
4080
- key: "buildLookupTable",
4081
- value: function buildLookupTable(uidList) {
4082
- return uidList.reduce(function (acc, item) {
4083
- var _Object$entries$ = (0, _slicedToArray2["default"])(Object.entries(item)[0], 2),
4084
- uid = _Object$entries$[0],
4085
- value = _Object$entries$[1];
4086
- acc[uid] = value;
4087
- return acc;
4088
- }, {});
4089
- }
4090
-
4091
- /**
4092
- * 根據 UID 還原原始組合(透過對照表或解碼備援)
4093
- */
4094
- }, {
4095
- key: "getOriginalFromUid",
4096
- value: function getOriginalFromUid(uid, lookupTable) {
4097
- return (lookupTable === null || lookupTable === void 0 ? void 0 : lookupTable[uid]) || this.decodeFromUid(uid) || null;
4098
- }
4099
4013
  }, {
4100
4014
  key: "getArrayOfFillMissingValues",
4101
- value: /** ------------------------------------------------------------------------------------- 結束UID-COMBINATION */
4102
-
4015
+ value:
4103
4016
  /**
4104
4017
  * const input = [
4105
4018
  * { value: 'xx0132', label: 'A款' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utiller",
3
- "version": "1.0.347",
3
+ "version": "1.0.348",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -11,7 +11,7 @@
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
13
  "configerer": "^1.0.11",
14
- "utiller": "^1.0.346",
14
+ "utiller": "^1.0.347",
15
15
  "linepayer": "^1.0.4",
16
16
  "databazer": "^1.0.12",
17
17
  "lodash": "^4.17.20",