@pawover/kit 0.4.0 → 0.4.2

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.
@@ -1,4 +1,4 @@
1
- import { n as TypeUtil, t as StringUtil } from "./stringUtil-voQaLOJj.js";
1
+ import { n as StringUtil, r as TypeUtil, t as MathUtil } from "./math-B5PyWuKn.js";
2
2
  //#region src/array/arrayUtil.ts
3
3
  /**
4
4
  * 数组工具类
@@ -236,6 +236,145 @@ var ArrayUtil = class {
236
236
  }
237
237
  };
238
238
  //#endregion
239
+ //#region src/currency/currencyUtil.ts
240
+ /**
241
+ * 货币工具类
242
+ * - 基于 [`Intl.NumberFormat`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat) 进行本地化格式化
243
+ * - 支持精确小数位处理(依赖 `mathjs`)
244
+ */
245
+ var CurrencyUtil = class {
246
+ /**
247
+ * 货币代码到 Locale 的映射枚举
248
+ * - 键为 ISO 4217 货币代码,值为 BCP 47 语言标签
249
+ * - 用于 `Intl.NumberFormat` 的本地化数字格式化
250
+ * - 格式示例基于 `Intl.NumberFormat` 对 `1,234,567.89` 的输出
251
+ *
252
+ * @example
253
+ * ```ts
254
+ * import { CurrencyUtil } from "@pawover/kit/utils";
255
+ * // 获取人民币的格式化 locale
256
+ * const locale = CurrencyUtil.CURRENCY_ENUM.CNY; // "zh-CN"
257
+ *
258
+ * // 结合 Intl.NumberFormat 使用
259
+ * new Intl.NumberFormat(CurrencyUtil.CURRENCY_ENUM.USD, {
260
+ * style: "currency",
261
+ * currency: "USD",
262
+ * }).format(1234.56); // "$1,234.56"
263
+ * ```
264
+ */
265
+ static CURRENCY_ENUM = {
266
+ /** 美元(美国及美元化国家,Locale: 美式英语) → 1,234,567.89 */
267
+ USD: "en-US",
268
+ /** 加拿大元(加拿大,Locale: 加拿大英语) → 1,234,567.89 */
269
+ CAD: "en-CA",
270
+ /** 墨西哥比索(墨西哥,Locale: 墨西哥西班牙语) → 1,234,567.89 */
271
+ MXN: "es-MX",
272
+ /** 巴西雷亚尔(巴西,Locale: 巴西葡萄牙语) → 1.234.567,89 */
273
+ BRL: "pt-BR",
274
+ /** 阿根廷比索(阿根廷,Locale: 阿根廷西班牙语) → 1.234.567,89 */
275
+ ARS: "es-AR",
276
+ /** 智利比索(智利,Locale: 智利西班牙语) → 1.234.567,89 */
277
+ CLP: "es-CL",
278
+ /** 秘鲁新索尔(秘鲁,Locale: 秘鲁西班牙语) → 1,234,567.89 */
279
+ PEN: "es-PE",
280
+ /** 哥伦比亚比索(哥伦比亚,Locale: 哥伦比亚西班牙语) → 1.234.567,89 */
281
+ COP: "es-CO",
282
+ /** 哥斯达黎加科朗(哥斯达黎加,Locale: 哥斯达黎加西班牙语) → 1 234 567,89(空格千分位) */
283
+ CRC: "es-CR",
284
+ /** 人民币(中国,Locale: 简体中文) → 1,234,567.89 */
285
+ CNY: "zh-CN",
286
+ /** 港元(中国香港,Locale: 繁体中文+香港) → 1,234,567.89 */
287
+ HKD: "zh-HK",
288
+ /** 澳门元(中国澳门,Locale: 繁体中文+澳门) → 1,234,567.89 */
289
+ MOP: "zh-MO",
290
+ /** 日元(日本,Locale: 日语) → 1,234,567.89 */
291
+ JPY: "ja-JP",
292
+ /** 韩元(韩国,Locale: 韩语) → 1,234,567.89 */
293
+ KRW: "ko-KR",
294
+ /** 新加坡元(新加坡,Locale: 英语+新加坡) → 1,234,567.89 */
295
+ SGD: "en-SG",
296
+ /** 泰铢(泰国,Locale: 泰语) → 1,234,567.89 */
297
+ THB: "th-TH",
298
+ /** 印度卢比(印度,Locale: 英语+印度) → 12,34,567.89(2,2,3 分组) */
299
+ INR: "en-IN",
300
+ /** 沙特里亚尔(沙特,Locale: 阿拉伯语+沙特) → ١٬٢٣٤٬٥٦٧٫٨٩(阿拉伯数字) */
301
+ SAR: "ar-SA",
302
+ /** 阿联酋迪拉姆(阿联酋,Locale: 阿拉伯语+阿联酋) → 1,234,567.89 */
303
+ AED: "ar-AE",
304
+ /** 印尼盾(印尼,Locale: 印尼语) → 1.234.567,89 */
305
+ IDR: "id-ID",
306
+ /** 马来西亚林吉特(马来西亚,Locale: 马来语) → 1,234,567.89 */
307
+ MYR: "ms-MY",
308
+ /** 越南盾(越南,Locale: 越南语) → 1.234.567,89 */
309
+ VND: "vi-VN",
310
+ /** 菲律宾比索(菲律宾,Locale: 英语+菲律宾) → 1,234,567.89 */
311
+ PHP: "en-PH",
312
+ /** 巴基斯坦卢比(巴基斯坦,Locale: 英语+巴基斯坦) → 1,234,567.89 */
313
+ PKR: "en-PK",
314
+ /** 新台币(中国台湾地区,Locale: 繁体中文+台湾) → 1,234,567.89 */
315
+ TWD: "zh-TW",
316
+ /** 欧元(德国,Locale: 德语+德国,代表欧元区) → 1.234.567,89 */
317
+ EUR: "de-DE",
318
+ /** 英镑(英国,Locale: 英式英语) → 1,234,567.89 */
319
+ GBP: "en-GB",
320
+ /** 瑞士法郎(瑞士,Locale: 德语+瑞士) → 1'234'567.89 */
321
+ CHF: "de-CH",
322
+ /** 瑞典克朗(瑞典,Locale: 瑞典语) → 1 234 567,89(空格千分位) */
323
+ SEK: "sv-SE",
324
+ /** 挪威克朗(挪威,Locale: 挪威语) → 1 234 567,89(空格千分位) */
325
+ NOK: "no-NO",
326
+ /** 丹麦克朗(丹麦,Locale: 丹麦语) → 1.234.567,89 */
327
+ DKK: "da-DK",
328
+ /** 波兰兹罗提(波兰,Locale: 波兰语) → 1 234 567,89(空格千分位) */
329
+ PLN: "pl-PL",
330
+ /** 捷克克朗(捷克,Locale: 捷克语) → 1 234 567,89(空格千分位) */
331
+ CZK: "cs-CZ",
332
+ /** 匈牙利福林(匈牙利,Locale: 匈牙利语) → 1 234 567,89(空格千分位) */
333
+ HUF: "hu-HU",
334
+ /** 俄罗斯卢布(俄罗斯,Locale: 俄语) → 1 234 567,89(空格千分位) */
335
+ RUB: "ru-RU",
336
+ /** 罗马尼亚列伊(罗马尼亚,Locale: 罗马尼亚语) → 1.234.567,89 */
337
+ RON: "ro-RO",
338
+ /** 乌克兰格里夫纳(乌克兰,Locale: 乌克兰语) → 1 234 567,89(空格千分位) */
339
+ UAH: "uk-UA",
340
+ /** 澳大利亚元(澳大利亚,Locale: 澳大利亚英语) → 1,234,567.89 */
341
+ AUD: "en-AU",
342
+ /** 新西兰元(新西兰,Locale: 新西兰英语) → 1,234,567.89 */
343
+ NZD: "en-NZ",
344
+ /** 南非兰特(南非,Locale: 英语+南非) → 1 234 567,89(空格千分位) */
345
+ ZAR: "en-ZA",
346
+ /** 埃及镑(埃及,Locale: 阿拉伯语+埃及) → ١٬٢٣٤٬٥٦٧٫٨٩(阿拉伯数字) */
347
+ EGP: "ar-EG",
348
+ /** 土耳其里拉(土耳其,Locale: 土耳其语) → 1.234.567,89 */
349
+ TRY: "tr-TR",
350
+ /** 以色列新谢克尔(以色列,Locale: 希伯来语) → 1,234,567.89 */
351
+ ILS: "he-IL",
352
+ /** 摩洛哥迪拉姆(摩洛哥,Locale: 阿拉伯语+摩洛哥) → 1.234.567,89 */
353
+ MAD: "ar-MA",
354
+ /** 科威特第纳尔(科威特,Locale: 阿拉伯语+科威特) → ١٬٢٣٤٬٥٦٧٫٨٩(阿拉伯数字) */
355
+ KWD: "ar-KW",
356
+ /** 卡塔尔里亚尔(卡塔尔,Locale: 阿拉伯语+卡塔尔) → ١٬٢٣٤٬٥٦٧٫٨٩(阿拉伯数字) */
357
+ QAR: "ar-QA",
358
+ /** 尼日利亚奈拉(尼日利亚,Locale: 英语+尼日利亚) → 1,234,567.89 */
359
+ NGN: "en-NG",
360
+ /** 太平洋法郎(法属波利尼西亚,Locale: 法语+太平洋) → 1[U+202F]234[U+202F]567,89(窄空格千分位) */
361
+ XPF: "fr-PF"
362
+ };
363
+ static currencyFormatter(value, options) {
364
+ if (TypeUtil.isNull(value) || TypeUtil.isUndefined(value)) return null;
365
+ const { currencySign, currencySignPosition, locales, currencyFormatOptions } = options;
366
+ let formatedValue = Number(value).toLocaleString(locales, currencyFormatOptions).replace(currencySign, "").trim();
367
+ if (currencySignPosition === "start") formatedValue = `${currencySign} ${formatedValue}`;
368
+ if (currencySignPosition === "end") formatedValue = `${formatedValue} ${currencySign}`;
369
+ return formatedValue;
370
+ }
371
+ static toRealValue(mathJsInstance, value, precision, stringMode) {
372
+ if (TypeUtil.isNull(value) || TypeUtil.isUndefined(value)) return null;
373
+ const precisionValue = MathUtil.toDecimal(mathJsInstance, value, precision);
374
+ return stringMode ? precisionValue : Number(precisionValue);
375
+ }
376
+ };
377
+ //#endregion
239
378
  //#region src/dateTime/dateTimeUtil.ts
240
379
  /**
241
380
  * 日期工具类
@@ -2058,4 +2197,4 @@ var ValidateUtil = class {
2058
2197
  }
2059
2198
  };
2060
2199
  //#endregion
2061
- export { ArrayUtil, DateTimeUtil, EnvUtil, FunctionUtil, MimeUtil, NumberUtil, ObjectUtil, StringUtil, ThemeUtil, TreeUtil, TypeUtil, ValidateUtil };
2200
+ export { ArrayUtil, CurrencyUtil, DateTimeUtil, EnvUtil, FunctionUtil, MimeUtil, NumberUtil, ObjectUtil, StringUtil, ThemeUtil, TreeUtil, TypeUtil, ValidateUtil };
@@ -260,6 +260,19 @@ var TypeUtil = class {
260
260
  return value === null;
261
261
  }
262
262
  /**
263
+ * 检查 value 是否为 null 或 undefined
264
+ * @param value 待检查值
265
+ * @returns 是否为 Nullish
266
+ * @example
267
+ * ```ts
268
+ * TypeUtil.isNullish(null); // true
269
+ * TypeUtil.isNullish(undefined); // true
270
+ * ```
271
+ */
272
+ static isNullish(value) {
273
+ return this.isNull(value) || this.isUndefined(value);
274
+ }
275
+ /**
263
276
  * 检查 value 是否为 Function
264
277
  * @param value 待检查值
265
278
  * @returns 是否为 Function
@@ -938,4 +951,58 @@ var StringUtil = class {
938
951
  }
939
952
  };
940
953
  //#endregion
941
- export { TypeUtil as n, StringUtil as t };
954
+ //#region src/math/mathUtil.ts
955
+ /**
956
+ * 数学工具类
957
+ * - 基于 [`mathjs`](https://mathjs.org)
958
+ */
959
+ var MathUtil = class MathUtil {
960
+ /**
961
+ * 将任意类型的值转换为 `math.bignumber`
962
+ *
963
+ * @param mathJsInstance mathJs 实例
964
+ * @param value 任意类型的值
965
+ * @param fallback 回退值
966
+ * @returns 转换后的 BigNumber
967
+ * @example
968
+ * ```ts
969
+ * import { create, all } from "mathjs";
970
+ * const math = create(all);
971
+ * MathUtil.toBignumber(math, "0.1");
972
+ * ```
973
+ */
974
+ static toBignumber(mathJsInstance, value, fallback) {
975
+ const errorValue = fallback ?? mathJsInstance.bignumber(0);
976
+ if (TypeUtil.isFalsyLike(value) || TypeUtil.isInfinityLike(value)) return errorValue;
977
+ try {
978
+ return mathJsInstance.bignumber(StringUtil.toNumber(`${value}`));
979
+ } catch (error) {
980
+ return errorValue;
981
+ }
982
+ }
983
+ static toDecimal(mathJsInstance, value, precision, isFormat = true) {
984
+ const bigNumber = MathUtil.toBignumber(mathJsInstance, value);
985
+ return isFormat ? mathJsInstance.format(bigNumber, {
986
+ notation: "fixed",
987
+ precision
988
+ }) : bigNumber;
989
+ }
990
+ /**
991
+ * 数学表达式求值
992
+ *
993
+ * @param mathJsInstance mathJs 实例
994
+ * @param expr 表达式
995
+ * @param scope 键值映射
996
+ * @returns 计算结果的字符串表示
997
+ * @example
998
+ * ```ts
999
+ * MathUtil.toEvaluate(math, "a + b", { a: 1, b: 2 }); // "3"
1000
+ * ```
1001
+ */
1002
+ static toEvaluate(mathJsInstance, expr, scope) {
1003
+ const evaluateValue = `${mathJsInstance.evaluate(expr, scope || {})}`;
1004
+ return mathJsInstance.format(MathUtil.toBignumber(mathJsInstance, evaluateValue), { notation: "fixed" });
1005
+ }
1006
+ };
1007
+ //#endregion
1008
+ export { StringUtil as n, TypeUtil as r, MathUtil as t };
@@ -1,56 +1,2 @@
1
- import { n as TypeUtil, t as StringUtil } from "./stringUtil-voQaLOJj.js";
2
- //#region src/math/mathUtil.ts
3
- /**
4
- * 数学工具类
5
- * - 基于 [`mathjs`](https://mathjs.org)
6
- */
7
- var MathUtil = class MathUtil {
8
- /**
9
- * 将任意类型的值转换为 `math.bignumber`
10
- *
11
- * @param mathJsInstance mathJs 实例
12
- * @param value 任意类型的值
13
- * @param fallback 回退值
14
- * @returns 转换后的 BigNumber
15
- * @example
16
- * ```ts
17
- * import { create, all } from "mathjs";
18
- * const math = create(all);
19
- * MathUtil.toBignumber(math, "0.1");
20
- * ```
21
- */
22
- static toBignumber(mathJsInstance, value, fallback) {
23
- const errorValue = fallback ?? mathJsInstance.bignumber(0);
24
- if (TypeUtil.isFalsyLike(value) || TypeUtil.isInfinityLike(value)) return errorValue;
25
- try {
26
- return mathJsInstance.bignumber(StringUtil.toNumber(`${value}`));
27
- } catch (error) {
28
- return errorValue;
29
- }
30
- }
31
- static toDecimal(mathJsInstance, value, precision, isFormat = true) {
32
- const bigNumber = MathUtil.toBignumber(mathJsInstance, value);
33
- return isFormat ? mathJsInstance.format(bigNumber, {
34
- notation: "fixed",
35
- precision
36
- }) : bigNumber;
37
- }
38
- /**
39
- * 数学表达式求值
40
- *
41
- * @param mathJsInstance mathJs 实例
42
- * @param expr 表达式
43
- * @param scope 键值映射
44
- * @returns 计算结果的字符串表示
45
- * @example
46
- * ```ts
47
- * MathUtil.toEvaluate(math, "a + b", { a: 1, b: 2 }); // "3"
48
- * ```
49
- */
50
- static toEvaluate(mathJsInstance, expr, scope) {
51
- const evaluateValue = `${mathJsInstance.evaluate(expr, scope || {})}`;
52
- return mathJsInstance.format(MathUtil.toBignumber(mathJsInstance, evaluateValue), { notation: "fixed" });
53
- }
54
- };
55
- //#endregion
1
+ import { t as MathUtil } from "./math-B5PyWuKn.js";
56
2
  export { MathUtil };
@@ -1,5 +1,6 @@
1
1
  [
2
2
  "ArrayUtil",
3
+ "CurrencyUtil",
3
4
  "DateTimeUtil",
4
5
  "EnvUtil",
5
6
  "FunctionUtil",
@@ -24,7 +24,7 @@ var ViteUtil = class {
24
24
  static toProxy(proxyList, options) {
25
25
  const httpsRE = /^https:\/\//;
26
26
  const result = {};
27
- if (typeof proxyList === "object") for (const [prefix, target] of proxyList) result[prefix] = {
27
+ if (Array.isArray(proxyList)) for (const [prefix, target] of proxyList) result[prefix] = {
28
28
  target,
29
29
  changeOrigin: true,
30
30
  ws: true,