utiller 1.0.268 → 1.0.270

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.
@@ -125,6 +125,43 @@ var Utiller = /*#__PURE__*/function () {
125
125
  }, _callee2);
126
126
  }));
127
127
  });
128
+ /** const items = [{ price: 10 }, { price: 120 }, { price: 230 }];
129
+ console.log(findLowestPrice(items)); // 輸出: 10
130
+ */
131
+ (0, _defineProperty2["default"])(this, "findLowestValue", function (items) {
132
+ var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "price";
133
+ // 提取價格並找出最小值
134
+ var minPrice = _lodash["default"].minBy(items, key)[key];
135
+
136
+ // 確保回傳的最低價為 integer 型態
137
+ return Math.floor(minPrice);
138
+ });
139
+ /** const items = [{ price: 10 }, { price: 120 }, { price: 230 }];
140
+ console.log(findLowestPrice(items)); // 輸出: 120
141
+ */
142
+ (0, _defineProperty2["default"])(this, "findHighestValue", function (items) {
143
+ var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "price";
144
+ // 提取價格並找出最小值
145
+ var maxPrice = _lodash["default"].maxBy(items, key)[key];
146
+
147
+ // 確保回傳的最低價為 integer 型態
148
+ return Math.floor(maxPrice);
149
+ });
150
+ /**
151
+ * // 測試數據
152
+ * const items = [{ price: 10 }, { price: 120 }, { price: 230 }];
153
+ * console.log(getPriceRange(items)); // 輸出: $10 - $230
154
+ * */
155
+ (0, _defineProperty2["default"])(this, "getStringOfValueRange", function (items) {
156
+ var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "price";
157
+ var sign = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "$";
158
+ // 找出最小值和最大值
159
+ var minV = _lodash["default"].minBy(items, key)[key];
160
+ var maxV = _lodash["default"].maxBy(items, key)[key];
161
+
162
+ // 判斷並返回字串
163
+ return maxV === minV ? "$".concat(minV) : "".concat(sign).concat(minV, " - ").concat(sign).concat(maxV);
164
+ });
128
165
  (0, _defineProperty2["default"])(this, "getCallersName", function () {
129
166
  var callerName;
130
167
  try {
@@ -239,6 +276,33 @@ var Utiller = /*#__PURE__*/function () {
239
276
  return _ref3.apply(this, arguments);
240
277
  };
241
278
  }());
279
+ (0, _defineProperty2["default"])(this, "formatPriceWithCurrency", function (number, locale) {
280
+ if (typeof number !== "number" || typeof locale !== "string") {
281
+ throw new TypeError("Invalid input: number must be a number and locale must be a string.");
282
+ }
283
+ return new Intl.NumberFormat(locale, {
284
+ style: "currency",
285
+ currency: new Intl.Locale(locale).maximize().currency || "USD",
286
+ minimumFractionDigits: 0 // 確保不顯示小數
287
+ }).format(number);
288
+ });
289
+ (0, _defineProperty2["default"])(this, "formatPrice", function (number, locale) {
290
+ if (typeof number !== "number") {
291
+ throw new TypeError("Invalid input: number must be a number.");
292
+ }
293
+
294
+ // 如果沒有傳入 locale,僅格式化數字
295
+ if (!locale) {
296
+ return number.toLocaleString("en-US"); // 預設使用美式數字格式
297
+ }
298
+
299
+ // 有傳入 locale,使用貨幣格式化
300
+ return new Intl.NumberFormat(locale, {
301
+ style: "currency",
302
+ currency: new Intl.Locale(locale).maximize().currency || "USD",
303
+ minimumFractionDigits: 0 // 確保不顯示小數
304
+ }).format(number);
305
+ });
242
306
  this.init();
243
307
  this.env = "dev";
244
308
  }
@@ -905,11 +969,10 @@ var Utiller = /*#__PURE__*/function () {
905
969
  var shuffled = _lodash["default"].shuffle(arr);
906
970
  return _lodash["default"].take(shuffled, n);
907
971
  }
908
-
909
- /** ignore 就是黑名單的意思 */
910
972
  }, {
911
973
  key: "getRandomItemOfArray",
912
- value: function getRandomItemOfArray(array) {
974
+ value: /** ignore 就是黑名單的意思 */
975
+ function getRandomItemOfArray(array) {
913
976
  if (!_lodash["default"].isArray(array)) throw new _exceptioner["default"](9999, "why are you so stupid, typeof array should be array, not ==> ".concat(array, " "));
914
977
  for (var _len11 = arguments.length, ignores = new Array(_len11 > 1 ? _len11 - 1 : 0), _key12 = 1; _key12 < _len11; _key12++) {
915
978
  ignores[_key12 - 1] = arguments[_key12];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utiller",
3
- "version": "1.0.268",
3
+ "version": "1.0.270",
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.267",
14
+ "utiller": "^1.0.269",
15
15
  "linepayer": "^1.0.4",
16
16
  "databazer": "^1.0.12",
17
17
  "lodash": "^4.17.20",