@pisell/utils 3.0.4 → 3.0.6

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 (160) hide show
  1. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +27 -0
  2. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +12 -0
  3. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +25 -0
  4. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +14 -0
  5. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +9 -0
  6. package/es/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +11 -0
  7. package/es/arrayUtils.d.ts +76 -1
  8. package/es/arrayUtils.js +103 -24
  9. package/es/common/stateHelper.d.ts +22 -0
  10. package/es/common/stateHelper.js +23 -0
  11. package/es/common/types.d.ts +31 -0
  12. package/es/componentStorage.d.ts +38 -0
  13. package/es/componentStorage.js +106 -0
  14. package/es/constants/index.js +7 -9
  15. package/es/date.d.ts +6 -3
  16. package/es/date.js +36 -53
  17. package/es/document.d.ts +6 -3
  18. package/es/document.js +43 -67
  19. package/es/escPosPrinter/EscPosPrinter.js +353 -490
  20. package/es/escPosPrinter/index.d.ts +9 -9
  21. package/es/escPosPrinter/index.js +37 -52
  22. package/es/format.d.ts +29 -0
  23. package/es/format.js +90 -112
  24. package/es/image.d.ts +13 -10
  25. package/es/image.js +48 -60
  26. package/es/index.d.ts +39 -18
  27. package/es/index.js +40 -29
  28. package/es/jsBridge/index.d.ts +14 -106
  29. package/es/jsBridge/index.js +57 -40
  30. package/es/jsBridge/regDeviceApi.js +87 -126
  31. package/es/jsBridge/types.d.ts +129 -0
  32. package/es/locales.d.ts +11 -11
  33. package/es/locales.js +79 -69
  34. package/es/log.d.ts +11 -6
  35. package/es/log.js +37 -59
  36. package/es/miniRedux.d.ts +20 -13
  37. package/es/miniRedux.js +42 -71
  38. package/es/number-input/hooks/useNumberInputState.d.ts +29 -0
  39. package/es/number-input/hooks/useNumberInputState.js +72 -0
  40. package/es/number-input/types.d.ts +96 -0
  41. package/es/number-input/utils/formatter.d.ts +56 -0
  42. package/es/number-input/utils/formatter.js +56 -0
  43. package/es/number-input/utils/validation.d.ts +32 -0
  44. package/es/number-input/utils/validation.js +52 -0
  45. package/es/otherUtils.d.ts +12 -9
  46. package/es/otherUtils.js +71 -120
  47. package/es/platform.d.ts +12 -9
  48. package/es/platform.js +61 -85
  49. package/es/select/hooks/useDebouncedSearch.d.ts +23 -0
  50. package/es/select/hooks/useDebouncedSearch.js +41 -0
  51. package/es/select/hooks/useSelectState.d.ts +19 -0
  52. package/es/select/hooks/useSelectState.js +60 -0
  53. package/es/select/index.d.ts +7 -0
  54. package/es/select/types.d.ts +256 -0
  55. package/es/select/utils/filterOptions.d.ts +23 -0
  56. package/es/select/utils/filterOptions.js +29 -0
  57. package/es/select/utils/helpers.d.ts +43 -0
  58. package/es/select/utils/helpers.js +51 -0
  59. package/es/select/utils/index.d.ts +4 -0
  60. package/es/select/utils/sortOptions.d.ts +13 -0
  61. package/es/select/utils/sortOptions.js +20 -0
  62. package/es/select/utils/tagAggregation.d.ts +25 -0
  63. package/es/select/utils/tagAggregation.js +35 -0
  64. package/es/text-input/hooks/useTextInputState.d.ts +28 -0
  65. package/es/text-input/hooks/useTextInputState.js +70 -0
  66. package/es/text-input/types.d.ts +56 -0
  67. package/es/text-input/utils/validation.d.ts +28 -0
  68. package/es/text-input/utils/validation.js +51 -0
  69. package/es/typeUtils.d.ts +11 -8
  70. package/es/typeUtils.js +61 -84
  71. package/es/walletValidity.d.ts +57 -0
  72. package/es/walletValidity.js +404 -460
  73. package/es/weighing.d.ts +65 -0
  74. package/es/weighing.js +96 -0
  75. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js +27 -0
  76. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/defineProperty.js +12 -0
  77. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js +25 -0
  78. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPrimitive.js +14 -0
  79. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/toPropertyKey.js +9 -0
  80. package/lib/_virtual/_@oxc-project_runtime@0.122.0/helpers/typeof.js +16 -0
  81. package/lib/_virtual/_rolldown/runtime.js +23 -0
  82. package/lib/arrayUtils.d.ts +76 -1
  83. package/lib/arrayUtils.js +102 -37
  84. package/lib/common/stateHelper.d.ts +22 -0
  85. package/lib/common/stateHelper.js +23 -0
  86. package/lib/common/types.d.ts +31 -0
  87. package/lib/componentStorage.d.ts +38 -0
  88. package/lib/componentStorage.js +114 -0
  89. package/lib/constants/index.js +7 -36
  90. package/lib/date.d.ts +6 -3
  91. package/lib/date.js +43 -65
  92. package/lib/document.d.ts +6 -3
  93. package/lib/document.js +46 -62
  94. package/lib/escPosPrinter/EscPosPrinter.js +327 -403
  95. package/lib/escPosPrinter/index.d.ts +9 -9
  96. package/lib/escPosPrinter/index.js +38 -84
  97. package/lib/format.d.ts +29 -0
  98. package/lib/format.js +91 -93
  99. package/lib/image.d.ts +13 -10
  100. package/lib/image.js +48 -74
  101. package/lib/index.d.ts +39 -18
  102. package/lib/index.js +137 -68
  103. package/lib/jsBridge/index.d.ts +14 -106
  104. package/lib/jsBridge/index.js +60 -60
  105. package/lib/jsBridge/regDeviceApi.js +86 -133
  106. package/lib/jsBridge/types.d.ts +129 -0
  107. package/lib/locales.d.ts +11 -11
  108. package/lib/locales.js +79 -63
  109. package/lib/log.d.ts +11 -6
  110. package/lib/log.js +37 -61
  111. package/lib/miniRedux.d.ts +20 -13
  112. package/lib/miniRedux.js +43 -91
  113. package/lib/number-input/hooks/useNumberInputState.d.ts +29 -0
  114. package/lib/number-input/hooks/useNumberInputState.js +73 -0
  115. package/lib/number-input/types.d.ts +96 -0
  116. package/lib/number-input/utils/formatter.d.ts +56 -0
  117. package/lib/number-input/utils/formatter.js +58 -0
  118. package/lib/number-input/utils/validation.d.ts +32 -0
  119. package/lib/number-input/utils/validation.js +52 -0
  120. package/lib/otherUtils.d.ts +12 -9
  121. package/lib/otherUtils.js +86 -91
  122. package/lib/platform.d.ts +12 -9
  123. package/lib/platform.js +68 -123
  124. package/lib/select/hooks/useDebouncedSearch.d.ts +23 -0
  125. package/lib/select/hooks/useDebouncedSearch.js +42 -0
  126. package/lib/select/hooks/useSelectState.d.ts +19 -0
  127. package/lib/select/hooks/useSelectState.js +62 -0
  128. package/lib/select/index.d.ts +7 -0
  129. package/lib/select/types.d.ts +256 -0
  130. package/lib/select/utils/filterOptions.d.ts +23 -0
  131. package/lib/select/utils/filterOptions.js +30 -0
  132. package/lib/select/utils/helpers.d.ts +43 -0
  133. package/lib/select/utils/helpers.js +55 -0
  134. package/lib/select/utils/index.d.ts +4 -0
  135. package/lib/select/utils/sortOptions.d.ts +13 -0
  136. package/lib/select/utils/sortOptions.js +20 -0
  137. package/lib/select/utils/tagAggregation.d.ts +25 -0
  138. package/lib/select/utils/tagAggregation.js +35 -0
  139. package/lib/text-input/hooks/useTextInputState.d.ts +28 -0
  140. package/lib/text-input/hooks/useTextInputState.js +71 -0
  141. package/lib/text-input/types.d.ts +56 -0
  142. package/lib/text-input/utils/validation.d.ts +28 -0
  143. package/lib/text-input/utils/validation.js +51 -0
  144. package/lib/typeUtils.d.ts +11 -8
  145. package/lib/typeUtils.js +68 -73
  146. package/lib/walletValidity.d.ts +57 -0
  147. package/lib/walletValidity.js +420 -323
  148. package/lib/weighing.d.ts +65 -0
  149. package/lib/weighing.js +114 -0
  150. package/package.json +1 -1
  151. package/es/constants/index.d.ts +0 -7
  152. package/es/firebase/config/index.d.ts +0 -13
  153. package/es/firebase/config/index.js +0 -54
  154. package/es/firebase/index.d.ts +0 -28
  155. package/es/firebase/index.js +0 -232
  156. package/lib/constants/index.d.ts +0 -7
  157. package/lib/firebase/config/index.d.ts +0 -13
  158. package/lib/firebase/config/index.js +0 -79
  159. package/lib/firebase/index.d.ts +0 -28
  160. package/lib/firebase/index.js +0 -180
@@ -1,141 +1,94 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/jsBridge/regDeviceApi.js
20
- var regDeviceApi_exports = {};
21
- __export(regDeviceApi_exports, {
22
- default: () => regDeviceApi
23
- });
24
- module.exports = __toCommonJS(regDeviceApi_exports);
25
- var import_platform = require("../platform");
26
- var androidRegStatus = false;
27
- var iosRegStatus = false;
28
- var androidBridge;
29
- var iosBridge;
30
- var composedBridge;
1
+ const require_platform = require("../platform.js");
2
+ //#region src/jsBridge/regDeviceApi.js
3
+ let androidRegStatus = false;
4
+ let iosRegStatus = false;
5
+ let androidBridge;
6
+ let iosBridge;
7
+ let composedBridge;
31
8
  function regIosJsBridge(callback) {
32
- if (window.WebViewJavascriptBridge) {
33
- callback(window.WebViewJavascriptBridge);
34
- return;
35
- }
36
- if (window.WVJBCallbacks) {
37
- window.WVJBCallbacks.push(callback);
38
- return;
39
- }
40
- window.WVJBCallbacks = [callback];
41
- const WVJBIframe = document.createElement("iframe");
42
- WVJBIframe.style.display = "none";
43
- WVJBIframe.src = "https://__bridge_loaded__";
44
- document.documentElement && document.documentElement.appendChild(WVJBIframe);
45
- setTimeout(() => {
46
- try {
47
- document.documentElement && document.documentElement.removeChild(WVJBIframe);
48
- } catch (e) {
49
- console.log(e);
50
- }
51
- }, 0);
9
+ if (window.WebViewJavascriptBridge) {
10
+ callback(window.WebViewJavascriptBridge);
11
+ return;
12
+ }
13
+ if (window.WVJBCallbacks) {
14
+ window.WVJBCallbacks.push(callback);
15
+ return;
16
+ }
17
+ window.WVJBCallbacks = [callback];
18
+ const WVJBIframe = document.createElement("iframe");
19
+ WVJBIframe.style.display = "none";
20
+ WVJBIframe.src = "https://__bridge_loaded__";
21
+ document.documentElement && document.documentElement.appendChild(WVJBIframe);
22
+ setTimeout(() => {
23
+ try {
24
+ document.documentElement && document.documentElement.removeChild(WVJBIframe);
25
+ } catch (e) {
26
+ console.log(e);
27
+ }
28
+ }, 0);
52
29
  }
53
30
  function regAndroidJsBridge(extraInit) {
54
- if (window._jsBridge) {
55
- extraInit(window._jsBridge);
56
- return;
57
- }
58
- document.addEventListener(
59
- "WebViewJavascriptBridgeReady",
60
- (event) => {
61
- const { bridge } = event;
62
- window._jsBridge = bridge;
63
- if (!bridge) return;
64
- bridge.init((message, responseCallback) => {
65
- if (responseCallback) {
66
- responseCallback("init responseCallback");
67
- }
68
- });
69
- extraInit(bridge);
70
- },
71
- false
72
- );
31
+ if (window._jsBridge) {
32
+ extraInit(window._jsBridge);
33
+ return;
34
+ }
35
+ document.addEventListener("WebViewJavascriptBridgeReady", (event) => {
36
+ const { bridge } = event;
37
+ window._jsBridge = bridge;
38
+ if (!bridge) return;
39
+ bridge.init((message, responseCallback) => {
40
+ if (responseCallback) responseCallback("init responseCallback");
41
+ });
42
+ extraInit(bridge);
43
+ }, false);
73
44
  }
45
+ /**
46
+ * 通用jsBridge
47
+ * @param deviceType
48
+ */
74
49
  function getComposedBridge(deviceType) {
75
- if (composedBridge) {
76
- return composedBridge;
77
- }
78
- composedBridge = {
79
- // 主动调用设备的方法
80
- callDeviceApi: ({ apiName, callback: inCb, params = {}, onError }) => {
81
- const callback = (res, ...args) => {
82
- let result = res;
83
- try {
84
- result = JSON.parse(res);
85
- } catch (error) {
86
- console.log(`error ${apiName}`, error);
87
- }
88
- inCb(result, ...args);
89
- };
90
- if (deviceType === "iphone") {
91
- iosBridge.callHandler(apiName, params, callback, (e) => {
92
- console.log(e, "--- 调用ios api报错:", apiName);
93
- if (onError) {
94
- onError(e);
95
- }
96
- });
97
- } else if (deviceType === "android") {
98
- const res = androidBridge.callHandler(apiName, JSON.stringify(params));
99
- callback(res);
100
- } else {
101
- console.log("--- 没获取到js bridge ---");
102
- }
103
- },
104
- // 被设备调用的方法
105
- calledByDevice: ({ apiName, callback }) => {
106
- if (deviceType === "iphone") {
107
- iosBridge.registerHandler(apiName, callback);
108
- } else if (deviceType === "android") {
109
- androidBridge.registerHandler(apiName, callback);
110
- }
111
- }
112
- };
113
- return composedBridge;
50
+ if (composedBridge) return composedBridge;
51
+ composedBridge = {
52
+ callDeviceApi: ({ apiName, callback: inCb, params = {}, onError }) => {
53
+ const callback = (res, ...args) => {
54
+ let result = res;
55
+ try {
56
+ result = JSON.parse(res);
57
+ } catch (error) {
58
+ console.log(`error ${apiName}`, error);
59
+ }
60
+ inCb(result, ...args);
61
+ };
62
+ if (deviceType === "iphone") iosBridge.callHandler(apiName, params, callback, (e) => {
63
+ console.log(e, "--- 调用ios api报错:", apiName);
64
+ if (onError) onError(e);
65
+ });
66
+ else if (deviceType === "android") callback(androidBridge.callHandler(apiName, JSON.stringify(params)));
67
+ else console.log("--- 没获取到js bridge ---");
68
+ },
69
+ calledByDevice: ({ apiName, callback }) => {
70
+ if (deviceType === "iphone") iosBridge.registerHandler(apiName, callback);
71
+ else if (deviceType === "android") androidBridge.registerHandler(apiName, callback);
72
+ }
73
+ };
74
+ return composedBridge;
114
75
  }
115
76
  function regDeviceApi() {
116
- return new Promise((resolve, reject) => {
117
- if ((0, import_platform.isIos)() && !iosRegStatus) {
118
- regIosJsBridge((bridge) => {
119
- iosRegStatus = true;
120
- iosBridge = bridge;
121
- const realBridge = getComposedBridge("iphone");
122
- resolve(realBridge);
123
- });
124
- } else if ((0, import_platform.isIos)() && iosRegStatus) {
125
- const realBridge = getComposedBridge("iphone");
126
- resolve(realBridge);
127
- } else if ((0, import_platform.isAndroid)() && !androidRegStatus) {
128
- regAndroidJsBridge((bridge) => {
129
- androidBridge = bridge;
130
- androidRegStatus = true;
131
- const realBridge = getComposedBridge("android");
132
- resolve(realBridge);
133
- });
134
- } else if ((0, import_platform.isAndroid)() && androidRegStatus) {
135
- const realBridge = getComposedBridge("android");
136
- resolve(realBridge);
137
- } else {
138
- reject();
139
- }
140
- });
77
+ return new Promise((resolve, reject) => {
78
+ if (require_platform.isIos() && !iosRegStatus) regIosJsBridge((bridge) => {
79
+ iosRegStatus = true;
80
+ iosBridge = bridge;
81
+ resolve(getComposedBridge("iphone"));
82
+ });
83
+ else if (require_platform.isIos() && iosRegStatus) resolve(getComposedBridge("iphone"));
84
+ else if (require_platform.isAndroid() && !androidRegStatus) regAndroidJsBridge((bridge) => {
85
+ androidBridge = bridge;
86
+ androidRegStatus = true;
87
+ resolve(getComposedBridge("android"));
88
+ });
89
+ else if (require_platform.isAndroid() && androidRegStatus) resolve(getComposedBridge("android"));
90
+ else reject();
91
+ });
141
92
  }
93
+ //#endregion
94
+ exports.default = regDeviceApi;
@@ -0,0 +1,129 @@
1
+ //#region src/jsBridge/types.d.ts
2
+ type LanguageNumber = {
3
+ en: number;
4
+ zh_CN: number;
5
+ zh_HK: number;
6
+ };
7
+ type LanguageString = {
8
+ en: string;
9
+ zh_CN: string;
10
+ zh_HK: string;
11
+ } | string;
12
+ /**
13
+ * 打印小票
14
+ */
15
+ type WebPrint0 = {
16
+ /**
17
+ * 打印类型
18
+ * 0: 小票
19
+ * 1:ITS备货单/划菜单
20
+ * 2:手环
21
+ */
22
+ type: '0';
23
+ data: {
24
+ /** 订单ID */order_id: string;
25
+ }; /** 打印语言对应的数量 */
26
+ language: LanguageNumber;
27
+ };
28
+ /**
29
+ * 打印ITS备货单/划菜单
30
+ */
31
+ type WebPrint1 = {
32
+ /**
33
+ * 打印类型
34
+ * 0: 小票
35
+ * 1:ITS备货单/划菜单
36
+ * 2:手环
37
+ */
38
+ type: '1';
39
+ data: {
40
+ /** 0:备货 1:划单 */mode: '0' | '1';
41
+ resource: LanguageString; /** 订单备注 */
42
+ order_note: string; /** 订单时间或商品下单时间 */
43
+ time: string; /** 订单编号 */
44
+ order_number?: string; /** 商品 */
45
+ products: {
46
+ /** 商品名称 */product_title: LanguageString; /** 商品规格 */
47
+ product_option_string: LanguageString; /** 商品备注 */
48
+ product_note: string; /** 商品数量 */
49
+ product_quantity: number; /** 加菜标识 待定 */
50
+ is_append?: boolean; /** 退菜标识 待定 */
51
+ is_removed?: boolean;
52
+ }[];
53
+ }; /** 打印语言对应的数量 */
54
+ language: LanguageNumber;
55
+ };
56
+ /**
57
+ * 打印手环
58
+ */
59
+ type WebPrint2 = {
60
+ /**
61
+ * 打印类型
62
+ * 0: 小票
63
+ * 1:ITS备货单/划菜单
64
+ * 2:手环
65
+ */
66
+ type: '2';
67
+ data: {
68
+ /** 0: 普通票 1:成人票 2:免费成人票 */type: '0' | '1' | '2'; /** 发行编码 */
69
+ encoded: string; /** 编码 */
70
+ code: string; /** 到期时间 */
71
+ expire_date: string;
72
+ areas: {
73
+ /** 区域名字 */area_name: string; /** 区域代码 */
74
+ area_code: string; /** 可用次数 */
75
+ limit_num: number; /** 已用次数 */
76
+ used_num: number;
77
+ }[];
78
+ };
79
+ };
80
+ /**
81
+ * 打印充值卡
82
+ */
83
+ type WebPrint4 = {
84
+ type: '4';
85
+ data: {
86
+ order_id: string;
87
+ };
88
+ };
89
+ /**
90
+ * 打印订单中所有
91
+ */
92
+ type WebPrint99 = {
93
+ type: '99';
94
+ data: {
95
+ order_id: string;
96
+ machine_code_print_info: {
97
+ [key: string]: any;
98
+ }[];
99
+ small_ticket_data: {
100
+ [key: string]: any;
101
+ };
102
+ };
103
+ };
104
+ /**
105
+ * 打印
106
+ */
107
+ type WebPrintParams = WebPrint0 | WebPrint1 | WebPrint2 | WebPrint4 | WebPrint99;
108
+ /**
109
+ * 数据管理
110
+ */
111
+ type DataManagerParams = {
112
+ module: 'set' | 'get';
113
+ key: string;
114
+ data?: any;
115
+ };
116
+ /**
117
+ * 支付
118
+ */
119
+ type WebPaymentParams = {
120
+ module: 'payment' | 'refund' | string;
121
+ key: 'mx51' | string;
122
+ data?: {
123
+ order_id: string | number;
124
+ amount: string | number;
125
+ surcharge?: string | number;
126
+ };
127
+ };
128
+ //#endregion
129
+ export { DataManagerParams, WebPaymentParams, WebPrintParams };
package/lib/locales.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- export declare const locales: {
2
- init: (_localeMaps: any, _locale: string) => void;
3
- getText: (id: string) => any;
4
- locale: string;
5
- localeMap: any;
6
- localeMaps: {
7
- en: {};
8
- 'zh-CN': {};
9
- 'zh-HK': {};
10
- };
11
- formatLocale: (_locale: string) => string;
1
+ //#region src/locales.d.ts
2
+ declare const locales: {
3
+ init: (_localeMaps: any, _locale: string) => void;
4
+ getText: (id: string) => any;
5
+ getLocale: () => string;
6
+ locale: string;
7
+ localeMap: any;
8
+ localeMaps: any;
9
+ formatLocale: (_locale: string) => string;
12
10
  };
11
+ //#endregion
12
+ export { locales };
package/lib/locales.js CHANGED
@@ -1,69 +1,85 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
1
+ const require_objectSpread2 = require("./_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
2
+ //#region src/locales.ts
3
+ let localeMaps = {
4
+ en: {},
5
+ "zh-CN": {},
6
+ "zh-HK": {},
7
+ "ja": {},
8
+ "pt": {}
8
9
  };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
10
+ let locale = "en";
11
+ let localeMap = {};
12
+ const formatLocale = (_locale) => {
13
+ const obj = {
14
+ en: "en",
15
+ "en-US": "en",
16
+ "en-us": "en",
17
+ "zh-CN": "zh-CN",
18
+ "zh-cn": "zh-CN",
19
+ "zh-HK": "zh-HK",
20
+ "zh-hk": "zh-HK",
21
+ "zh-TW": "zh-HK",
22
+ "zh-tw": "zh-HK",
23
+ ja: "ja",
24
+ "ja-JP": "ja",
25
+ "ja-jp": "ja",
26
+ pt: "pt",
27
+ "pt-BR": "pt",
28
+ "pt-br": "pt",
29
+ "pt-PT": "pt",
30
+ "pt-pt": "pt"
31
+ };
32
+ const direct = obj[_locale];
33
+ if (direct) return direct;
34
+ const norm = String(_locale || "").trim().replace(/_/g, "-").toLowerCase();
35
+ if (obj[norm]) return obj[norm];
36
+ if (norm.startsWith("ja")) return "ja";
37
+ if (norm.startsWith("pt")) return "pt";
38
+ if (norm.startsWith("zh-hk") || norm.startsWith("zh-tw")) return "zh-HK";
39
+ if (norm.startsWith("zh-cn")) return "zh-CN";
40
+ if (norm.startsWith("en")) return "en";
41
+ return "en";
16
42
  };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/locales.ts
20
- var locales_exports = {};
21
- __export(locales_exports, {
22
- locales: () => locales
23
- });
24
- module.exports = __toCommonJS(locales_exports);
25
- var localeMaps = {
26
- en: {},
27
- "zh-CN": {},
28
- "zh-HK": {}
43
+ /**
44
+ * @title: 初始化多语言
45
+ * @description:
46
+ * @param {any} _localeMaps
47
+ * @param {string} _locale
48
+ * @return {*}
49
+ * @Author: zhiwei.Wang
50
+ * @Date: 2024-01-17 21:38
51
+ */
52
+ const init = (_localeMaps, _locale) => {
53
+ locale = formatLocale(_locale);
54
+ let allLocales = {};
55
+ for (let key in localeMaps) allLocales[key] = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, localeMaps[key]), _localeMaps[key]);
56
+ localeMaps = allLocales;
57
+ localeMap = localeMaps[locale];
29
58
  };
30
- var locale = "en";
31
- var localeMap = {};
32
- var formatLocale = (_locale) => {
33
- let obj = {
34
- "en": "en",
35
- "zh-CN": "zh-CN",
36
- "zh-HK": "zh-HK",
37
- "zh-TW": "zh-HK",
38
- "en-US": "en"
39
- };
40
- return obj[_locale] || "en";
59
+ /**
60
+ * @title: 获取语言
61
+ * @description:
62
+ * @param {string} id
63
+ * @return {*}
64
+ * @Author: zhiwei.Wang
65
+ * @Date: 2024-01-17 21:39
66
+ */
67
+ const getText = (id) => {
68
+ var _localeMaps$en;
69
+ return localeMap[id] || (localeMaps === null || localeMaps === void 0 || (_localeMaps$en = localeMaps["en"]) === null || _localeMaps$en === void 0 ? void 0 : _localeMaps$en[id]) || id;
41
70
  };
42
- var init = (_localeMaps, _locale) => {
43
- locale = formatLocale(_locale);
44
- let allLocales = {};
45
- for (let key in localeMaps) {
46
- allLocales[key] = {
47
- ...localeMaps[key],
48
- ..._localeMaps[key]
49
- };
50
- }
51
- localeMaps = allLocales;
52
- localeMap = localeMaps[locale];
53
- console.log("多语言注入成功, 当前语言为:" + locale);
71
+ /** 获取当前语言(与 getText 同源,供 datetime 等组件与 getText 语言一致) */
72
+ const getLocale = () => {
73
+ return locale;
54
74
  };
55
- var getText = (id) => {
56
- return localeMap[id] || id;
75
+ const locales = {
76
+ init,
77
+ getText,
78
+ getLocale,
79
+ locale,
80
+ localeMap,
81
+ localeMaps,
82
+ formatLocale
57
83
  };
58
- var locales = {
59
- init,
60
- getText,
61
- locale,
62
- localeMap,
63
- localeMaps,
64
- formatLocale
65
- };
66
- // Annotate the CommonJS export names for ESM import in node:
67
- 0 && (module.exports = {
68
- locales
69
- });
84
+ //#endregion
85
+ exports.locales = locales;
package/lib/log.d.ts CHANGED
@@ -1,10 +1,15 @@
1
+ //#region src/log.d.ts
1
2
  interface contentItem {
2
- key: string;
3
- value: string;
3
+ key: string;
4
+ value: string;
4
5
  }
5
6
  interface sendWebhookProps {
6
- title: string;
7
- content: contentItem[];
7
+ title: string;
8
+ content: contentItem[];
8
9
  }
9
- export declare const sendWarningLog: ({ title, content }: sendWebhookProps) => Promise<any>;
10
- export {};
10
+ declare const sendWarningLog: ({
11
+ title,
12
+ content
13
+ }: sendWebhookProps) => Promise<any>;
14
+ //#endregion
15
+ export { sendWarningLog };
package/lib/log.js CHANGED
@@ -1,62 +1,38 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
1
+ const require_asyncToGenerator = require("./_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
2
+ const require_index = require("./constants/index.js");
3
+ const require_index$1 = require("./index.js");
4
+ //#region src/log.ts
5
+ const createFeishuMessageContent = (contentArr) => {
6
+ return JSON.stringify(contentArr.map((item) => {
7
+ return [{
8
+ tag: "text",
9
+ text: `${item.key}: `
10
+ }, {
11
+ tag: "text",
12
+ text: `${item.value}`
13
+ }];
14
+ }));
8
15
  };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/log.ts
20
- var log_exports = {};
21
- __export(log_exports, {
22
- sendWarningLog: () => sendWarningLog
23
- });
24
- module.exports = __toCommonJS(log_exports);
25
- var import_index = require("./index");
26
- var import_constants = require("./constants");
27
- var createFeishuMessageContent = (contentArr) => {
28
- return JSON.stringify(
29
- contentArr.map((item) => {
30
- return [
31
- { tag: "text", text: `${item.key}: ` },
32
- { tag: "text", text: `${item.value}` }
33
- ];
34
- })
35
- );
36
- };
37
- var sendWarningLog = async ({ title, content }) => {
38
- const contentStr = createFeishuMessageContent(content);
39
- let apiUrl = "";
40
- const config = (0, import_index.getPisellUtilsConfig)();
41
- console.log("PISELL_UTILS_CONFIG>>>>", config);
42
- if ((config == null ? void 0 : config.env) === "dev" || (config == null ? void 0 : config.env) === "pre" || (config == null ? void 0 : config.env) === "release") {
43
- apiUrl = import_constants.webHookApi.warning_log.test;
44
- } else {
45
- apiUrl = import_constants.webHookApi.warning_log.prod;
46
- }
47
- const response = await fetch(apiUrl, {
48
- headers: {
49
- "Content-Type": "application/json"
50
- },
51
- method: "POST",
52
- body: JSON.stringify({
53
- msg_type: "post",
54
- content: `{"post":{"zh_cn":{"title":"${title}","content":${contentStr}}}}`
55
- })
56
- });
57
- return await response.json();
58
- };
59
- // Annotate the CommonJS export names for ESM import in node:
60
- 0 && (module.exports = {
61
- sendWarningLog
62
- });
16
+ const sendWarningLog = function() {
17
+ var _ref = require_asyncToGenerator._asyncToGenerator(function* ({ title, content }) {
18
+ const contentStr = createFeishuMessageContent(content);
19
+ let apiUrl = "";
20
+ const config = require_index$1.getPisellUtilsConfig();
21
+ console.log("PISELL_UTILS_CONFIG>>>>", config);
22
+ if ((config === null || config === void 0 ? void 0 : config.env) === "dev" || (config === null || config === void 0 ? void 0 : config.env) === "pre" || (config === null || config === void 0 ? void 0 : config.env) === "release") apiUrl = require_index.webHookApi.warning_log.test;
23
+ else apiUrl = require_index.webHookApi.warning_log.prod;
24
+ return yield (yield fetch(apiUrl, {
25
+ headers: { "Content-Type": "application/json" },
26
+ method: "POST",
27
+ body: JSON.stringify({
28
+ msg_type: "post",
29
+ content: `{"post":{"zh_cn":{"title":"${title}","content":${contentStr}}}}`
30
+ })
31
+ })).json();
32
+ });
33
+ return function sendWarningLog(_x) {
34
+ return _ref.apply(this, arguments);
35
+ };
36
+ }();
37
+ //#endregion
38
+ exports.sendWarningLog = sendWarningLog;