@pisell/utils 3.0.6 → 3.0.7

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.
Files changed (200) hide show
  1. package/es/arrayUtils.d.ts +23 -26
  2. package/es/arrayUtils.js +157 -97
  3. package/es/common/index.d.ts +5 -0
  4. package/es/common/index.js +5 -0
  5. package/es/common/stateHelper.d.ts +2 -6
  6. package/es/common/stateHelper.js +24 -22
  7. package/es/common/types.d.ts +10 -13
  8. package/es/common/types.js +1 -0
  9. package/es/componentStorage.d.ts +25 -27
  10. package/es/componentStorage.js +130 -94
  11. package/es/constants/index.js +9 -7
  12. package/es/date.js +53 -36
  13. package/es/document.js +67 -43
  14. package/es/escPosPrinter/EscPosPrinter.js +490 -353
  15. package/es/escPosPrinter/index.d.ts +9 -9
  16. package/es/escPosPrinter/index.js +52 -37
  17. package/es/firebase/config/index.js +54 -0
  18. package/es/firebase/index.js +232 -0
  19. package/es/format.d.ts +15 -12
  20. package/es/format.js +156 -89
  21. package/es/image.js +60 -48
  22. package/es/index.d.ts +24 -39
  23. package/es/index.js +35 -40
  24. package/es/jsBridge/index.d.ts +4 -8
  25. package/es/jsBridge/index.js +55 -56
  26. package/es/jsBridge/regDeviceApi.js +126 -87
  27. package/es/jsBridge/types.d.ts +115 -95
  28. package/es/jsBridge/types.js +1 -0
  29. package/es/locales.d.ts +8 -11
  30. package/es/locales.js +96 -77
  31. package/es/log.d.ts +6 -11
  32. package/es/log.js +59 -37
  33. package/es/miniRedux.d.ts +13 -20
  34. package/es/miniRedux.js +76 -42
  35. package/es/number-input/hooks/index.d.ts +4 -0
  36. package/es/number-input/hooks/index.js +5 -0
  37. package/es/number-input/hooks/useNumberInputState.d.ts +2 -6
  38. package/es/number-input/hooks/useNumberInputState.js +128 -71
  39. package/es/number-input/index.d.ts +14 -0
  40. package/es/number-input/index.js +21 -0
  41. package/es/number-input/types.d.ts +88 -88
  42. package/es/number-input/types.js +1 -0
  43. package/es/number-input/utils/formatter.d.ts +10 -13
  44. package/es/number-input/utils/formatter.js +77 -51
  45. package/es/number-input/utils/index.d.ts +7 -0
  46. package/es/number-input/utils/index.js +8 -0
  47. package/es/number-input/utils/validation.d.ts +2 -7
  48. package/es/number-input/utils/validation.js +66 -51
  49. package/es/otherUtils.d.ts +9 -12
  50. package/es/otherUtils.js +129 -71
  51. package/es/platform.d.ts +9 -12
  52. package/es/platform.js +85 -61
  53. package/es/select/hooks/index.d.ts +5 -0
  54. package/es/select/hooks/index.js +6 -0
  55. package/es/select/hooks/useDebouncedSearch.d.ts +1 -4
  56. package/es/select/hooks/useDebouncedSearch.js +53 -39
  57. package/es/select/hooks/useSelectState.d.ts +7 -7
  58. package/es/select/hooks/useSelectState.js +113 -56
  59. package/es/select/index.d.ts +8 -7
  60. package/es/select/index.js +13 -0
  61. package/es/select/types.d.ts +211 -211
  62. package/es/select/types.js +1 -0
  63. package/es/select/utils/filterOptions.d.ts +6 -7
  64. package/es/select/utils/filterOptions.js +31 -26
  65. package/es/select/utils/helpers.d.ts +9 -10
  66. package/es/select/utils/helpers.js +52 -42
  67. package/es/select/utils/index.d.ts +7 -4
  68. package/es/select/utils/index.js +8 -0
  69. package/es/select/utils/sortOptions.d.ts +5 -6
  70. package/es/select/utils/sortOptions.js +31 -19
  71. package/es/select/utils/tagAggregation.d.ts +6 -6
  72. package/es/select/utils/tagAggregation.js +47 -34
  73. package/es/text-input/hooks/index.d.ts +4 -0
  74. package/es/text-input/hooks/index.js +5 -0
  75. package/es/text-input/hooks/useTextInputState.d.ts +2 -6
  76. package/es/text-input/hooks/useTextInputState.js +126 -69
  77. package/es/text-input/index.d.ts +14 -0
  78. package/es/text-input/index.js +20 -0
  79. package/es/text-input/types.d.ts +48 -48
  80. package/es/text-input/types.js +1 -0
  81. package/es/text-input/utils/index.d.ts +5 -0
  82. package/es/text-input/utils/index.js +7 -0
  83. package/es/text-input/utils/validation.d.ts +2 -7
  84. package/es/text-input/utils/validation.js +70 -50
  85. package/es/typeUtils.js +84 -61
  86. package/es/walletValidity.d.ts +42 -44
  87. package/es/walletValidity.js +557 -396
  88. package/es/weighing.d.ts +45 -48
  89. package/es/weighing.js +106 -83
  90. package/lib/arrayUtils.d.ts +23 -26
  91. package/lib/arrayUtils.js +111 -101
  92. package/lib/common/index.d.ts +5 -0
  93. package/lib/common/index.js +29 -0
  94. package/lib/common/stateHelper.d.ts +2 -6
  95. package/lib/common/stateHelper.js +32 -21
  96. package/lib/common/types.d.ts +10 -13
  97. package/lib/common/types.js +17 -0
  98. package/lib/componentStorage.d.ts +25 -27
  99. package/lib/componentStorage.js +126 -96
  100. package/lib/constants/index.js +36 -7
  101. package/lib/date.js +65 -43
  102. package/lib/document.js +62 -46
  103. package/lib/escPosPrinter/EscPosPrinter.js +403 -327
  104. package/lib/escPosPrinter/index.d.ts +9 -9
  105. package/lib/escPosPrinter/index.js +84 -38
  106. package/lib/firebase/config/index.js +79 -0
  107. package/lib/firebase/index.js +180 -0
  108. package/lib/format.d.ts +15 -12
  109. package/lib/format.js +133 -91
  110. package/lib/image.js +74 -48
  111. package/lib/index.d.ts +24 -39
  112. package/lib/index.js +80 -137
  113. package/lib/jsBridge/index.d.ts +4 -8
  114. package/lib/jsBridge/index.js +76 -57
  115. package/lib/jsBridge/regDeviceApi.js +133 -86
  116. package/lib/jsBridge/types.d.ts +115 -95
  117. package/lib/jsBridge/types.js +17 -0
  118. package/lib/locales.d.ts +8 -11
  119. package/lib/locales.js +90 -79
  120. package/lib/log.d.ts +6 -11
  121. package/lib/log.js +61 -37
  122. package/lib/miniRedux.d.ts +13 -20
  123. package/lib/miniRedux.js +89 -43
  124. package/lib/number-input/hooks/index.d.ts +4 -0
  125. package/lib/number-input/hooks/index.js +29 -0
  126. package/lib/number-input/hooks/useNumberInputState.d.ts +2 -6
  127. package/lib/number-input/hooks/useNumberInputState.js +81 -71
  128. package/lib/number-input/index.d.ts +14 -0
  129. package/lib/number-input/index.js +41 -0
  130. package/lib/number-input/types.d.ts +88 -88
  131. package/lib/number-input/types.js +17 -0
  132. package/lib/number-input/utils/formatter.d.ts +10 -13
  133. package/lib/number-input/utils/formatter.js +49 -52
  134. package/lib/number-input/utils/index.d.ts +7 -0
  135. package/lib/number-input/utils/index.js +39 -0
  136. package/lib/number-input/utils/validation.d.ts +2 -7
  137. package/lib/number-input/utils/validation.js +52 -50
  138. package/lib/otherUtils.d.ts +9 -12
  139. package/lib/otherUtils.js +98 -86
  140. package/lib/platform.d.ts +9 -12
  141. package/lib/platform.js +123 -68
  142. package/lib/select/hooks/index.d.ts +5 -0
  143. package/lib/select/hooks/index.js +34 -0
  144. package/lib/select/hooks/useDebouncedSearch.d.ts +1 -4
  145. package/lib/select/hooks/useDebouncedSearch.js +41 -40
  146. package/lib/select/hooks/useSelectState.d.ts +7 -7
  147. package/lib/select/hooks/useSelectState.js +93 -58
  148. package/lib/select/index.d.ts +8 -7
  149. package/lib/select/index.js +53 -0
  150. package/lib/select/types.d.ts +211 -211
  151. package/lib/select/types.js +17 -0
  152. package/lib/select/utils/filterOptions.d.ts +6 -7
  153. package/lib/select/utils/filterOptions.js +37 -26
  154. package/lib/select/utils/helpers.d.ts +9 -10
  155. package/lib/select/utils/helpers.js +41 -45
  156. package/lib/select/utils/index.d.ts +7 -4
  157. package/lib/select/utils/index.js +48 -0
  158. package/lib/select/utils/sortOptions.d.ts +5 -6
  159. package/lib/select/utils/sortOptions.js +39 -18
  160. package/lib/select/utils/tagAggregation.d.ts +6 -6
  161. package/lib/select/utils/tagAggregation.js +41 -33
  162. package/lib/text-input/hooks/index.d.ts +4 -0
  163. package/lib/text-input/hooks/index.js +29 -0
  164. package/lib/text-input/hooks/useTextInputState.d.ts +2 -6
  165. package/lib/text-input/hooks/useTextInputState.js +79 -69
  166. package/lib/text-input/index.d.ts +14 -0
  167. package/lib/text-input/index.js +35 -0
  168. package/lib/text-input/types.d.ts +48 -48
  169. package/lib/text-input/types.js +17 -0
  170. package/lib/text-input/utils/index.d.ts +5 -0
  171. package/lib/text-input/utils/index.js +32 -0
  172. package/lib/text-input/utils/validation.d.ts +2 -7
  173. package/lib/text-input/utils/validation.js +58 -49
  174. package/lib/typeUtils.js +73 -68
  175. package/lib/walletValidity.d.ts +42 -44
  176. package/lib/walletValidity.js +393 -410
  177. package/lib/weighing.d.ts +45 -48
  178. package/lib/weighing.js +149 -104
  179. package/package.json +1 -1
  180. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +0 -27
  181. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +0 -12
  182. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +0 -25
  183. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +0 -14
  184. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +0 -9
  185. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +0 -11
  186. package/es/date.d.ts +0 -31
  187. package/es/document.d.ts +0 -16
  188. package/es/image.d.ts +0 -14
  189. package/es/typeUtils.d.ts +0 -45
  190. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +0 -27
  191. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +0 -12
  192. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +0 -25
  193. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +0 -14
  194. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +0 -9
  195. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +0 -16
  196. package/lib/_virtual/_rolldown/runtime.js +0 -23
  197. package/lib/date.d.ts +0 -31
  198. package/lib/document.d.ts +0 -16
  199. package/lib/image.d.ts +0 -14
  200. package/lib/typeUtils.d.ts +0 -45
package/es/format.js CHANGED
@@ -1,93 +1,160 @@
1
- import { isNumber, isString } from "./typeUtils.js";
2
- //#region src/format.ts
1
+ import { isString, isNumber } from "./typeUtils";
2
+
3
3
  /**
4
- * @title: 格式化金额
5
- * @description:
6
- * @param {number} amount 原金额
7
- * @param {number} precision 小数位数
8
- * @param {string} symbol 货币符号
9
- * @return {*}
10
- * @Author: zhiwei.Wang
11
- * @Date: 2023-11-06 16:51
12
- */
13
- const formatAmount = (amount = 0, precision = 2, symbol = "") => {
14
- if (!isString(amount) && !isNumber(amount)) {
15
- console.error("amount is not a number");
16
- return amount;
17
- }
18
- try {
19
- const roundedAmount = Math.round(amount * Math.pow(10, precision)) / Math.pow(10, precision);
20
- const absoluteAmount = Math.abs(roundedAmount);
21
- const integerPart = Math.floor(absoluteAmount);
22
- const decimalPart = (absoluteAmount - integerPart).toFixed(precision).substring(2);
23
- let formattedAmount = symbol + integerPart.toString();
24
- if (precision > 0) {
25
- formattedAmount += "." + decimalPart;
26
- if (formattedAmount.indexOf(".00") !== -1) formattedAmount = formattedAmount.substring(0, formattedAmount.length - 3);
27
- }
28
- if (roundedAmount < 0) formattedAmount = "-" + formattedAmount;
29
- return formattedAmount;
30
- } catch (err) {
31
- console.error(err);
32
- return amount;
33
- }
4
+ * @title: 格式化金额
5
+ * @description:
6
+ * @param {number} amount 原金额
7
+ * @param {number} precision 小数位数
8
+ * @param {string} symbol 货币符号
9
+ * @return {*}
10
+ * @Author: zhiwei.Wang
11
+ * @Date: 2023-11-06 16:51
12
+ */
13
+ export var formatAmount = function formatAmount() {
14
+ var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
15
+ var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
16
+ var symbol = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
17
+ // 校验格式
18
+ if (!isString(amount) && !isNumber(amount)) {
19
+ console.error('amount is not a number');
20
+ return amount;
21
+ }
22
+ try {
23
+ // 四舍五入
24
+ var roundedAmount = Math.round(amount * Math.pow(10, precision)) / Math.pow(10, precision);
25
+ // 处理负数情况
26
+ var absoluteAmount = Math.abs(roundedAmount);
27
+ // 截取整数
28
+ var integerPart = Math.floor(absoluteAmount);
29
+ // 截取小数部分并补零
30
+ var decimalPart = (absoluteAmount - integerPart).toFixed(precision).substring(2);
31
+
32
+ // 拼接货币符号
33
+ var formattedAmount = symbol + integerPart.toString();
34
+
35
+ // 添加小数点
36
+ if (precision > 0) {
37
+ formattedAmount += '.' + decimalPart;
38
+
39
+ // 如果小数位是 .00的话 抹去
40
+ if (formattedAmount.indexOf('.00') !== -1) {
41
+ formattedAmount = formattedAmount.substring(0, formattedAmount.length - 3);
42
+ }
43
+ }
44
+
45
+ // 添加负号
46
+ if (roundedAmount < 0) {
47
+ formattedAmount = '-' + formattedAmount;
48
+ }
49
+ return formattedAmount;
50
+ } catch (err) {
51
+ // 计算错误则返回原金额
52
+ console.error(err);
53
+ return amount;
54
+ }
34
55
  };
35
- const applyCurrencyFormat = (params) => {
36
- const { amount, symbol, currencyCode, currencyFormat } = params;
37
- const format = currencyFormat.trim();
38
- if (format.includes("{{amount}}") || format.includes("{amount}")) return format.split("{{amount}}").join(amount).split("{{sym}}").join(symbol).split("{{unit}}").join(currencyCode).split("{{symbol}}").join(symbol).split("{{unit_label}}").join(currencyCode).split("{{currency_code}}").join(currencyCode).split("{amount}").join(amount).split("{sym}").join(symbol).split("{unit}").join(currencyCode).split("{symbol}").join(symbol).split("{unit_label}").join(currencyCode).split("{currency_code}").join(currencyCode).trim();
39
- if (format === "symbol_last") {
40
- if (symbol) return `${amount}${symbol}`;
41
- if (currencyCode) return `${amount} ${currencyCode}`;
42
- return amount;
43
- }
44
- if (symbol) return `${symbol}${amount}`;
45
- return currencyCode ? `${amount} ${currencyCode}` : amount;
56
+ var applyCurrencyFormat = function applyCurrencyFormat(params) {
57
+ var amount = params.amount,
58
+ symbol = params.symbol,
59
+ currencyCode = params.currencyCode,
60
+ currencyFormat = params.currencyFormat;
61
+ var format = currencyFormat.trim();
62
+ if (format.includes('{{amount}}') || format.includes('{amount}')) {
63
+ return format.split('{{amount}}').join(amount).split('{{sym}}').join(symbol).split('{{unit}}').join(currencyCode).split('{{symbol}}').join(symbol).split('{{unit_label}}').join(currencyCode).split('{{currency_code}}').join(currencyCode).split('{amount}').join(amount).split('{sym}').join(symbol).split('{unit}').join(currencyCode).split('{symbol}').join(symbol).split('{unit_label}').join(currencyCode).split('{currency_code}').join(currencyCode).trim();
64
+ }
65
+ if (format === 'symbol_last') {
66
+ if (symbol) return "".concat(amount).concat(symbol);
67
+ if (currencyCode) return "".concat(amount, " ").concat(currencyCode);
68
+ return amount;
69
+ }
70
+ if (symbol) return "".concat(symbol).concat(amount);
71
+ return currencyCode ? "".concat(amount, " ").concat(currencyCode) : amount;
46
72
  };
73
+
47
74
  /**
48
- * 根据配置格式化金额
49
- * @param amount
50
- * @param symbol
51
- * @param options
52
- */
53
- const formatAmountWithOptions = (amount = 0, symbol = "", options = {}) => {
54
- const { precision = 2, useThousandsSeparator = false, showCurrencySymbol = true, hideDecimalForWholeNumbers = true, currencyCode = "", currencyFormat = "" } = options;
55
- if (!isString(amount) && !isNumber(amount)) {
56
- console.error("amount is not a number");
57
- return amount;
58
- }
59
- try {
60
- const roundedAmount = Math.round(amount * Math.pow(10, precision)) / Math.pow(10, precision);
61
- const absoluteAmount = Math.abs(roundedAmount);
62
- const integerPart = Math.floor(absoluteAmount);
63
- const decimalPart = (absoluteAmount - integerPart).toFixed(precision).substring(2);
64
- if (!currencyCode && !currencyFormat) {
65
- let legacyFormattedAmount = useThousandsSeparator ? integerPart.toLocaleString() : integerPart.toString();
66
- legacyFormattedAmount = showCurrencySymbol ? symbol + legacyFormattedAmount : legacyFormattedAmount;
67
- if (precision > 0) {
68
- legacyFormattedAmount += "." + decimalPart;
69
- if (hideDecimalForWholeNumbers && legacyFormattedAmount.indexOf(".00") !== -1) legacyFormattedAmount = legacyFormattedAmount.substring(0, legacyFormattedAmount.length - 3);
70
- }
71
- if (roundedAmount < 0) legacyFormattedAmount = "-" + legacyFormattedAmount;
72
- return legacyFormattedAmount;
73
- }
74
- let formattedAmount = useThousandsSeparator ? integerPart.toLocaleString() : integerPart.toString();
75
- if (precision > 0) {
76
- formattedAmount += "." + decimalPart;
77
- if (hideDecimalForWholeNumbers && Number(decimalPart) === 0) formattedAmount = formattedAmount.substring(0, formattedAmount.length - precision - 1);
78
- }
79
- if (showCurrencySymbol) formattedAmount = applyCurrencyFormat({
80
- amount: formattedAmount,
81
- symbol,
82
- currencyCode,
83
- currencyFormat
84
- });
85
- if (roundedAmount < 0) formattedAmount = "-" + formattedAmount;
86
- return formattedAmount;
87
- } catch (err) {
88
- console.error(err);
89
- return amount;
90
- }
91
- };
92
- //#endregion
93
- export { formatAmount, formatAmountWithOptions };
75
+ * 根据配置格式化金额
76
+ * @param amount
77
+ * @param symbol
78
+ * @param options
79
+ */
80
+ export var formatAmountWithOptions = function formatAmountWithOptions() {
81
+ var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
82
+ var symbol = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
83
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
84
+ var _options$precision = options.precision,
85
+ precision = _options$precision === void 0 ? 2 : _options$precision,
86
+ _options$useThousands = options.useThousandsSeparator,
87
+ useThousandsSeparator = _options$useThousands === void 0 ? false : _options$useThousands,
88
+ _options$showCurrency = options.showCurrencySymbol,
89
+ showCurrencySymbol = _options$showCurrency === void 0 ? true : _options$showCurrency,
90
+ _options$hideDecimalF = options.hideDecimalForWholeNumbers,
91
+ hideDecimalForWholeNumbers = _options$hideDecimalF === void 0 ? true : _options$hideDecimalF,
92
+ _options$currencyCode = options.currencyCode,
93
+ currencyCode = _options$currencyCode === void 0 ? '' : _options$currencyCode,
94
+ _options$currencyForm = options.currencyFormat,
95
+ currencyFormat = _options$currencyForm === void 0 ? '' : _options$currencyForm;
96
+ // 校验格式
97
+ if (!isString(amount) && !isNumber(amount)) {
98
+ console.error('amount is not a number');
99
+ return amount;
100
+ }
101
+ try {
102
+ // 四舍五入
103
+ var roundedAmount = Math.round(amount * Math.pow(10, precision)) / Math.pow(10, precision);
104
+ // 处理负数情况
105
+ var absoluteAmount = Math.abs(roundedAmount);
106
+ // 截取整数
107
+ var integerPart = Math.floor(absoluteAmount);
108
+ // 截取小数部分并补零
109
+ var decimalPart = (absoluteAmount - integerPart).toFixed(precision).substring(2);
110
+
111
+ // 新配置缺省时完整保留历史逻辑,避免影响现有调用方。
112
+ if (!currencyCode && !currencyFormat) {
113
+ var legacyFormattedAmount = useThousandsSeparator ? integerPart.toLocaleString() : integerPart.toString();
114
+ legacyFormattedAmount = showCurrencySymbol ? symbol + legacyFormattedAmount : legacyFormattedAmount;
115
+ if (precision > 0) {
116
+ legacyFormattedAmount += '.' + decimalPart;
117
+ if (hideDecimalForWholeNumbers && legacyFormattedAmount.indexOf('.00') !== -1) {
118
+ legacyFormattedAmount = legacyFormattedAmount.substring(0, legacyFormattedAmount.length - 3);
119
+ }
120
+ }
121
+ if (roundedAmount < 0) {
122
+ legacyFormattedAmount = '-' + legacyFormattedAmount;
123
+ }
124
+ return legacyFormattedAmount;
125
+ }
126
+
127
+ // 增加千分位分隔符
128
+ var formattedAmount = useThousandsSeparator ? integerPart.toLocaleString() : integerPart.toString();
129
+
130
+ // 添加小数点
131
+ if (precision > 0) {
132
+ formattedAmount += '.' + decimalPart;
133
+
134
+ // 整数按配置隐藏全部小数位
135
+ if (hideDecimalForWholeNumbers && Number(decimalPart) === 0) {
136
+ formattedAmount = formattedAmount.substring(0, formattedAmount.length - precision - 1);
137
+ }
138
+ }
139
+
140
+ // 数值精度与币种排版分开处理,便于共享法币和虚拟币规则
141
+ if (showCurrencySymbol) {
142
+ formattedAmount = applyCurrencyFormat({
143
+ amount: formattedAmount,
144
+ symbol: symbol,
145
+ currencyCode: currencyCode,
146
+ currencyFormat: currencyFormat
147
+ });
148
+ }
149
+
150
+ // 添加负号
151
+ if (roundedAmount < 0) {
152
+ formattedAmount = '-' + formattedAmount;
153
+ }
154
+ return formattedAmount;
155
+ } catch (err) {
156
+ // 计算错误则返回原金额
157
+ console.error(err);
158
+ return amount;
159
+ }
160
+ };
package/es/image.js CHANGED
@@ -1,51 +1,63 @@
1
- //#region src/image.ts
2
- const ali = (url, w) => {
3
- if (!url || /^\s+$/.test(url)) return "";
4
- if (/x-oss-process=/.test(url)) return url;
5
- let dpr = 2;
6
- w = w || 750;
7
- if (url.indexOf("?") > -1) url += "&";
8
- else url += "?";
9
- url += "x-oss-process=image/resize,w_" + parseInt(w * dpr + "") + ",image/format,webp/interlace,1,image/quality,Q_60/sharpen,90";
10
- return url;
1
+ var ali = function ali(url, w) {
2
+ if (!url || /^\s+$/.test(url)) {
3
+ return '';
4
+ }
5
+ // 如果图片链接中已经包含了过滤参数,则直接跳过
6
+ if (/x-oss-process=/.test(url)) {
7
+ return url;
8
+ }
9
+ var dpr = 2;
10
+ w = w || 750;
11
+ if (url.indexOf('?') > -1) {
12
+ url += '&';
13
+ } else {
14
+ url += '?';
15
+ }
16
+ url += 'x-oss-process=image/resize,w_' + parseInt(w * dpr + '') + ',image/format,webp/interlace,1,image/quality,Q_60/sharpen,90';
17
+ return url;
11
18
  };
19
+
12
20
  /**
13
- * @Title: 获取图片尺寸
14
- * @Describe: 通过 __ 进行分割
15
- * @Author: Wzw
16
- * @param {string} url
17
- */
18
- const getImageSize = (url) => {
19
- let size = {
20
- width: 375,
21
- height: 375,
22
- ratio: 1,
23
- widthRatio: 1,
24
- success: false,
25
- originRatio: 1
26
- };
27
- if (typeof url !== "string") return size;
28
- try {
29
- let arr = url.split("__");
30
- if (arr[1]) {
31
- let sizeArr = arr[1].split("_");
32
- let _width = Number(sizeArr[0]) || 375;
33
- let _height = Number(sizeArr[1]) || 375;
34
- size.width = _width;
35
- size.height = _height;
36
- size.success = true;
37
- size.ratio = Number(_height / _width);
38
- size.widthRatio = Number((_width / _height).toFixed(2));
39
- size.originRatio = Number(_height / _width);
40
- }
41
- return size;
42
- } catch (err) {
43
- return size;
44
- }
21
+ * @Title: 获取图片尺寸
22
+ * @Describe: 通过 __ 进行分割
23
+ * @Author: Wzw
24
+ * @param {string} url
25
+ */
26
+
27
+ var getImageSize = function getImageSize(url) {
28
+ var size = {
29
+ width: 375,
30
+ height: 375,
31
+ ratio: 1,
32
+ widthRatio: 1,
33
+ success: false,
34
+ originRatio: 1
35
+ };
36
+ if (typeof url !== 'string') return size;
37
+ // https://file.mypisel.dev/boxlocal/image/9c4e5a0afdbefadc78e3eab27c9ca3202021_07_23_16_05_00_916_02868331878656287__2160_976__.jpeg
38
+ // 根据 __ 分割url
39
+ try {
40
+ var arr = url.split('__');
41
+ // 根据规则, 第二个下标为图片的宽高
42
+ if (arr[1]) {
43
+ // 分割宽高, 第一个值是宽 第二个值是高
44
+ var sizeArr = arr[1].split('_');
45
+ // 如果没取到则默认为375
46
+ var _width = Number(sizeArr[0]) || 375;
47
+ var _height = Number(sizeArr[1]) || 375;
48
+ size.width = _width;
49
+ size.height = _height;
50
+ size.success = true;
51
+ size.ratio = Number(_height / _width);
52
+ size.widthRatio = Number((_width / _height).toFixed(2));
53
+ size.originRatio = Number(_height / _width);
54
+ }
55
+ return size;
56
+ } catch (err) {
57
+ return size;
58
+ }
45
59
  };
46
- const image = {
47
- ali,
48
- getImageSize
49
- };
50
- //#endregion
51
- export { image };
60
+ export var image = {
61
+ ali: ali,
62
+ getImageSize: getImageSize
63
+ };
package/es/index.d.ts CHANGED
@@ -1,41 +1,26 @@
1
- import { changeArray, createArray, detectIncognito, generateUniqueIdByObj, getItemByArray, getUniqueId } from "./otherUtils.js";
2
- import { isArr, isBoolean, isFunction, isJson, isNumber, isPlainObject, isString, isUndefined } from "./typeUtils.js";
3
- import { ColumnSettingStorageItem, clearColumnSettingFromLocal, clearColumnVisibilityFromLocal, getColumnSettingFromLocal, getColumnVisibilityFromLocal, getComponentStorageKey, getRecordBoardColumnSettingFromLocal, getStorageKeySuffix, saveColumnSettingToLocal, saveColumnVisibilityToLocal } from "./componentStorage.js";
4
- import { copyToClipboard, setTheme } from "./document.js";
5
- import { excelDateToJSDate, formatDate, jsDateToExcelDate } from "./date.js";
6
- import { checkEnv, isAndroid, isIOS, isIos, isIpad, isMobile, isSafari, isWx, isWxApp } from "./platform.js";
7
- import { sendWarningLog } from "./log.js";
8
- import { FormatOptions, formatAmount, formatAmountWithOptions } from "./format.js";
9
- import { ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, EscPosPrinter, columnWidthWithAlignment, preparing } from "./escPosPrinter/index.js";
10
- import { miniRedux } from "./miniRedux.js";
11
- import { dataManager, webPayment, webPrint } from "./jsBridge/index.js";
12
- import { image } from "./image.js";
13
- import { locales } from "./locales.js";
14
- import { GroupByOptions, GroupBySpec, GroupKey, GroupResult, getByPath, groupBy, uniqueByKey } from "./arrayUtils.js";
15
- import { Locale, WalletPassValidity, getScheduleSummary, getWalletValidityRange } from "./walletValidity.js";
16
- import { INVALID_SCALE_READING_STATUSES, MAX_RETAIL_SCALE_WEIGHT_KG, STANDARD_WEIGHT_UNIT, STANDARD_WEIGHT_UNIT_SYMBOL, ScaleReadingStatus, UNIT_PRICE_PRECISION, WEIGHT_PRECISION, WEIGHT_UNIT_GRAMS, WEIGHT_UNIT_NAMES, WEIGHT_UNIT_SYMBOLS, WeighingSnapshot, WeightUnit, WeightUnitName, WeightUnitSymbol, formatUnitPriceValue, formatWeightValue, getUsableScaleWeight, getWeightUnitGrams, getWeightUnitPriceConversionFactor, getWeightUnitSymbol, isInvalidScaleReadingStatus, isSupportedWeightUnit, normalizeWeightUnit, resolveWeighingSnapshot } from "./weighing.js";
17
- import { DisplayState, ValidationResult } from "./common/types.js";
18
- import { getDisplayState } from "./common/stateHelper.js";
19
- import { BaseTextInputProps, TextInputState } from "./text-input/types.js";
20
- import { useTextInputState } from "./text-input/hooks/useTextInputState.js";
21
- import { validateValue as validateValue$1 } from "./text-input/utils/validation.js";
22
- import { BaseNumberInputProps, NumberInputState } from "./number-input/types.js";
23
- import { useNumberInputState } from "./number-input/hooks/useNumberInputState.js";
24
- import { validateValue } from "./number-input/utils/validation.js";
25
- import { NumberFormatOptions, addThousandsSeparator, formatNumber, formatPrecision } from "./number-input/utils/formatter.js";
26
- import { BaseSelectProps, FilterOptionFunc, MultipleSelectState, SelectOption, SelectState, SortDirection, TagDisplayInfo, UseMultipleSelectStateOptions, UseSelectStateOptions } from "./select/types.js";
27
- import { useMultipleSelectState, useSelectState } from "./select/hooks/useSelectState.js";
28
- import { useDebouncedSearch } from "./select/hooks/useDebouncedSearch.js";
29
- import { calculateTagDisplay } from "./select/utils/tagAggregation.js";
30
- import { defaultFilterOption, filterOptions } from "./select/utils/filterOptions.js";
31
- import { sortOptions } from "./select/utils/sortOptions.js";
32
- import { findOptionByValue, findOptionsByValues, generateId, isOptionSelected, isOptionSelectedInMultiple } from "./select/utils/helpers.js";
33
- //#region src/index.d.ts
34
- declare const setPisellUtilsConfig: (config: {
35
- [key: string]: any;
1
+ export * from './otherUtils';
2
+ export * from './typeUtils';
3
+ export * from './componentStorage';
4
+ export * from './document';
5
+ export * from './date';
6
+ export * from './platform';
7
+ export * from './log';
8
+ export * from './format';
9
+ export * from './escPosPrinter';
10
+ export * from './miniRedux';
11
+ export * from './jsBridge';
12
+ export * from './image';
13
+ export * from './locales';
14
+ export * from './arrayUtils';
15
+ export * from './walletValidity';
16
+ export * from './weighing';
17
+ export * from './common';
18
+ export * from './text-input';
19
+ export * from './number-input';
20
+ export * from './select';
21
+ export declare const setPisellUtilsConfig: (config: {
22
+ [key: string]: any;
36
23
  }) => void;
37
- declare const getPisellUtilsConfig: () => {
38
- [key: string]: any;
24
+ export declare const getPisellUtilsConfig: () => {
25
+ [key: string]: any;
39
26
  };
40
- //#endregion
41
- export { ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, BaseNumberInputProps, BaseSelectProps, BaseTextInputProps, ColumnSettingStorageItem, DisplayState, EscPosPrinter, FilterOptionFunc, FormatOptions, GroupByOptions, GroupBySpec, GroupKey, GroupResult, INVALID_SCALE_READING_STATUSES, Locale, MAX_RETAIL_SCALE_WEIGHT_KG, MultipleSelectState, NumberFormatOptions, NumberInputState, STANDARD_WEIGHT_UNIT, STANDARD_WEIGHT_UNIT_SYMBOL, ScaleReadingStatus, SelectOption, SelectState, SortDirection, TagDisplayInfo, TextInputState, UNIT_PRICE_PRECISION, UseMultipleSelectStateOptions, UseSelectStateOptions, ValidationResult, WEIGHT_PRECISION, WEIGHT_UNIT_GRAMS, WEIGHT_UNIT_NAMES, WEIGHT_UNIT_SYMBOLS, WalletPassValidity, WeighingSnapshot, WeightUnit, WeightUnitName, WeightUnitSymbol, addThousandsSeparator, calculateTagDisplay, changeArray, checkEnv, clearColumnSettingFromLocal, clearColumnVisibilityFromLocal, columnWidthWithAlignment, copyToClipboard, createArray, dataManager, defaultFilterOption, detectIncognito, excelDateToJSDate, filterOptions, findOptionByValue, findOptionsByValues, formatAmount, formatAmountWithOptions, formatDate, formatNumber, formatPrecision, formatUnitPriceValue, formatWeightValue, generateId, generateUniqueIdByObj, getByPath, getColumnSettingFromLocal, getColumnVisibilityFromLocal, getComponentStorageKey, getDisplayState, getItemByArray, getPisellUtilsConfig, getRecordBoardColumnSettingFromLocal, getScheduleSummary, getStorageKeySuffix, getUniqueId, getUsableScaleWeight, getWalletValidityRange, getWeightUnitGrams, getWeightUnitPriceConversionFactor, getWeightUnitSymbol, groupBy, image, isAndroid, isArr, isBoolean, isFunction, isIOS, isInvalidScaleReadingStatus, isIos, isIpad, isJson, isMobile, isNumber, isOptionSelected, isOptionSelectedInMultiple, isPlainObject, isSafari, isString, isSupportedWeightUnit, isUndefined, isWx, isWxApp, jsDateToExcelDate, locales, miniRedux, normalizeWeightUnit, preparing, resolveWeighingSnapshot, saveColumnSettingToLocal, saveColumnVisibilityToLocal, sendWarningLog, setPisellUtilsConfig, setTheme, sortOptions, uniqueByKey, useDebouncedSearch, useMultipleSelectState, useNumberInputState, useSelectState, useTextInputState, validateValue as validateNumberValue, validateValue$1 as validateTextValue, webPayment, webPrint };
package/es/index.js CHANGED
@@ -1,41 +1,36 @@
1
- import { _objectSpread2 } from "./_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
2
- import { changeArray, createArray, detectIncognito, generateUniqueIdByObj, getItemByArray, getUniqueId } from "./otherUtils.js";
3
- import { isArr, isBoolean, isFunction, isJson, isNumber, isPlainObject, isString, isUndefined } from "./typeUtils.js";
4
- import { clearColumnSettingFromLocal, clearColumnVisibilityFromLocal, getColumnSettingFromLocal, getColumnVisibilityFromLocal, getComponentStorageKey, getRecordBoardColumnSettingFromLocal, getStorageKeySuffix, saveColumnSettingToLocal, saveColumnVisibilityToLocal } from "./componentStorage.js";
5
- import { copyToClipboard, setTheme } from "./document.js";
6
- import { excelDateToJSDate, formatDate, jsDateToExcelDate } from "./date.js";
7
- import { checkEnv, isAndroid, isIOS, isIos, isIpad, isMobile, isSafari, isWx, isWxApp } from "./platform.js";
8
- import { sendWarningLog } from "./log.js";
9
- import { formatAmount, formatAmountWithOptions } from "./format.js";
10
- import EscPosPrinter, { ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, columnWidthWithAlignment } from "./escPosPrinter/EscPosPrinter.js";
11
- import { preparing } from "./escPosPrinter/index.js";
12
- import { miniRedux } from "./miniRedux.js";
13
- import { dataManager, webPayment, webPrint } from "./jsBridge/index.js";
14
- import { image } from "./image.js";
15
- import { locales } from "./locales.js";
16
- import { getByPath, groupBy, uniqueByKey } from "./arrayUtils.js";
17
- import { getScheduleSummary, getWalletValidityRange } from "./walletValidity.js";
18
- import { INVALID_SCALE_READING_STATUSES, MAX_RETAIL_SCALE_WEIGHT_KG, STANDARD_WEIGHT_UNIT, STANDARD_WEIGHT_UNIT_SYMBOL, UNIT_PRICE_PRECISION, WEIGHT_PRECISION, WEIGHT_UNIT_GRAMS, WEIGHT_UNIT_NAMES, WEIGHT_UNIT_SYMBOLS, formatUnitPriceValue, formatWeightValue, getUsableScaleWeight, getWeightUnitGrams, getWeightUnitPriceConversionFactor, getWeightUnitSymbol, isInvalidScaleReadingStatus, isSupportedWeightUnit, normalizeWeightUnit, resolveWeighingSnapshot } from "./weighing.js";
19
- import { getDisplayState } from "./common/stateHelper.js";
20
- import { validateValue as validateValue$1 } from "./text-input/utils/validation.js";
21
- import { useTextInputState } from "./text-input/hooks/useTextInputState.js";
22
- import { validateValue } from "./number-input/utils/validation.js";
23
- import { useNumberInputState } from "./number-input/hooks/useNumberInputState.js";
24
- import { addThousandsSeparator, formatNumber, formatPrecision } from "./number-input/utils/formatter.js";
25
- import { useMultipleSelectState, useSelectState } from "./select/hooks/useSelectState.js";
26
- import { useDebouncedSearch } from "./select/hooks/useDebouncedSearch.js";
27
- import { calculateTagDisplay } from "./select/utils/tagAggregation.js";
28
- import { defaultFilterOption, filterOptions } from "./select/utils/filterOptions.js";
29
- import { sortOptions } from "./select/utils/sortOptions.js";
30
- import { findOptionByValue, findOptionsByValues, generateId, isOptionSelected, isOptionSelectedInMultiple } from "./select/utils/helpers.js";
31
- //#region src/index.ts
32
- const setPisellUtilsConfig = (config) => {
33
- globalThis.pisellUtilsConfig = _objectSpread2(_objectSpread2({}, globalThis.pisellUtilsConfig || {}), config || {});
34
- console.log("PisellUtilsConfig_set>>>>", config, globalThis);
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ export * from "./otherUtils";
8
+ export * from "./typeUtils";
9
+ export * from "./componentStorage";
10
+ export * from "./document";
11
+ export * from "./date";
12
+ export * from "./platform";
13
+ export * from "./log";
14
+ export * from "./format";
15
+ export * from "./escPosPrinter";
16
+ export * from "./miniRedux";
17
+ export * from "./jsBridge";
18
+ export * from "./image";
19
+ export * from "./locales";
20
+ export * from "./arrayUtils";
21
+ export * from "./walletValidity";
22
+ export * from "./weighing";
23
+ export * from "./common";
24
+ export * from "./text-input";
25
+ export * from "./number-input";
26
+ export * from "./select";
27
+ // export { default as firebase } from './firebase';
28
+
29
+ export var setPisellUtilsConfig = function setPisellUtilsConfig(config) {
30
+ globalThis.pisellUtilsConfig = _objectSpread(_objectSpread({}, globalThis.pisellUtilsConfig || {}), config || {});
31
+ console.log('PisellUtilsConfig_set>>>>', config, globalThis);
35
32
  };
36
- const getPisellUtilsConfig = () => {
37
- console.log("PisellUtilsConfig_get>>>>", globalThis);
38
- return globalThis.pisellUtilsConfig || {};
39
- };
40
- //#endregion
41
- export { ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, EscPosPrinter, INVALID_SCALE_READING_STATUSES, MAX_RETAIL_SCALE_WEIGHT_KG, STANDARD_WEIGHT_UNIT, STANDARD_WEIGHT_UNIT_SYMBOL, UNIT_PRICE_PRECISION, WEIGHT_PRECISION, WEIGHT_UNIT_GRAMS, WEIGHT_UNIT_NAMES, WEIGHT_UNIT_SYMBOLS, addThousandsSeparator, calculateTagDisplay, changeArray, checkEnv, clearColumnSettingFromLocal, clearColumnVisibilityFromLocal, columnWidthWithAlignment, copyToClipboard, createArray, dataManager, defaultFilterOption, detectIncognito, excelDateToJSDate, filterOptions, findOptionByValue, findOptionsByValues, formatAmount, formatAmountWithOptions, formatDate, formatNumber, formatPrecision, formatUnitPriceValue, formatWeightValue, generateId, generateUniqueIdByObj, getByPath, getColumnSettingFromLocal, getColumnVisibilityFromLocal, getComponentStorageKey, getDisplayState, getItemByArray, getPisellUtilsConfig, getRecordBoardColumnSettingFromLocal, getScheduleSummary, getStorageKeySuffix, getUniqueId, getUsableScaleWeight, getWalletValidityRange, getWeightUnitGrams, getWeightUnitPriceConversionFactor, getWeightUnitSymbol, groupBy, image, isAndroid, isArr, isBoolean, isFunction, isIOS, isInvalidScaleReadingStatus, isIos, isIpad, isJson, isMobile, isNumber, isOptionSelected, isOptionSelectedInMultiple, isPlainObject, isSafari, isString, isSupportedWeightUnit, isUndefined, isWx, isWxApp, jsDateToExcelDate, locales, miniRedux, normalizeWeightUnit, preparing, resolveWeighingSnapshot, saveColumnSettingToLocal, saveColumnVisibilityToLocal, sendWarningLog, setPisellUtilsConfig, setTheme, sortOptions, uniqueByKey, useDebouncedSearch, useMultipleSelectState, useNumberInputState, useSelectState, useTextInputState, validateValue as validateNumberValue, validateValue$1 as validateTextValue, webPayment, webPrint };
33
+ export var getPisellUtilsConfig = function getPisellUtilsConfig() {
34
+ console.log('PisellUtilsConfig_get>>>>', globalThis);
35
+ return globalThis.pisellUtilsConfig || {};
36
+ };
@@ -1,26 +1,22 @@
1
- import { DataManagerParams, WebPaymentParams, WebPrintParams } from "./types.js";
2
-
3
- //#region src/jsBridge/index.d.ts
1
+ import { WebPrintParams, DataManagerParams, WebPaymentParams } from './types';
4
2
  /**
5
3
  * webView页面中调用打印机打印
6
4
  * 此api暂时只支持native app平台下ios手机
7
5
  * @param params
8
6
  * @param callback
9
7
  */
10
- declare function webPrint(params: WebPrintParams, callback: (...arg: any) => void, onError?: (error: any) => void): void;
8
+ export declare function webPrint(params: WebPrintParams, callback: (...arg: any) => void, onError?: (error: any) => void): void;
11
9
  /**
12
10
  * webView页面中调用APP内的数据
13
11
  * 此api暂时只支持native app平台下ios手机
14
12
  * @param params
15
13
  * @param callback
16
14
  */
17
- declare function dataManager(params: DataManagerParams, callback: (...arg: any) => void, onError: () => void): void;
15
+ export declare function dataManager(params: DataManagerParams, callback: (...arg: any) => void, onError: () => void): void;
18
16
  /**
19
17
  * webView页面中调用APP内的支付
20
18
  * 此api暂时只支持native app平台下ios
21
19
  * @param params
22
20
  * @param callback
23
21
  */
24
- declare function webPayment(params: WebPaymentParams, callback: (...arg: any) => void, onError?: (error: any) => void): void;
25
- //#endregion
26
- export { dataManager, webPayment, webPrint };
22
+ export declare function webPayment(params: WebPaymentParams, callback: (...arg: any) => void, onError?: (error: any) => void): void;