@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
@@ -0,0 +1,96 @@
1
+ import { DisplayState, ValidationResult } from "../common/types.js";
2
+
3
+ //#region src/number-input/types.d.ts
4
+ /**
5
+ * 数值输入状态 Hook 返回值
6
+ */
7
+ interface NumberInputState {
8
+ /**
9
+ * 当前值
10
+ */
11
+ value: number | null | undefined;
12
+ /**
13
+ * 是否已被触摸(交互过)
14
+ */
15
+ isTouched: boolean;
16
+ /**
17
+ * 是否校验通过
18
+ */
19
+ isValid: boolean;
20
+ /**
21
+ * 错误信息数组
22
+ */
23
+ errors: string[];
24
+ /**
25
+ * 值变更处理函数
26
+ */
27
+ handleChange: (value: number | null) => void;
28
+ /**
29
+ * 失焦处理函数
30
+ */
31
+ handleBlur: () => void;
32
+ /**
33
+ * 聚焦处理函数
34
+ */
35
+ handleFocus: () => void;
36
+ }
37
+ /**
38
+ * 基础数值输入 Props(供校验和状态管理使用)
39
+ */
40
+ interface BaseNumberInputProps {
41
+ /**
42
+ * 当前值(受控)
43
+ */
44
+ value?: number | null;
45
+ /**
46
+ * 默认值(非受控)
47
+ */
48
+ defaultValue?: number | null;
49
+ /**
50
+ * 是否必填
51
+ */
52
+ required?: boolean;
53
+ /**
54
+ * 最小值
55
+ */
56
+ min?: number;
57
+ /**
58
+ * 最大值
59
+ */
60
+ max?: number;
61
+ /**
62
+ * 自定义校验函数
63
+ * @param value 当前值
64
+ * @returns true 表示通过,false 或错误信息字符串表示不通过
65
+ */
66
+ validator?: (value: number | null) => boolean | string;
67
+ /**
68
+ * 校验触发时机
69
+ * - onChange: 输入时即时校验
70
+ * - onBlur: 失焦时校验
71
+ * - both: 输入和失焦时都校验
72
+ */
73
+ validateTrigger?: 'onChange' | 'onBlur' | 'both';
74
+ /**
75
+ * 自定义错误提示信息
76
+ */
77
+ errorMessage?: string;
78
+ /**
79
+ * 值变更回调
80
+ */
81
+ onChange?: (value: number | null) => void;
82
+ /**
83
+ * 失焦回调
84
+ */
85
+ onBlur?: (value: number | null) => void;
86
+ /**
87
+ * 聚焦回调
88
+ */
89
+ onFocus?: () => void;
90
+ /**
91
+ * 校验回调
92
+ */
93
+ onValidate?: (isValid: boolean, errors: string[]) => void;
94
+ }
95
+ //#endregion
96
+ export { BaseNumberInputProps, NumberInputState };
@@ -0,0 +1,56 @@
1
+ //#region src/number-input/utils/formatter.d.ts
2
+ /**
3
+ * 数值格式化工具函数
4
+ */
5
+ /**
6
+ * 格式化选项
7
+ */
8
+ interface NumberFormatOptions {
9
+ /** 小数精度 */
10
+ precision?: number;
11
+ /** 是否使用千分位分隔符 */
12
+ useGrouping?: boolean;
13
+ /** 自定义格式化函数 */
14
+ formatter?: (value: number | null) => string;
15
+ }
16
+ /**
17
+ * 格式化数值
18
+ *
19
+ * @param value 数值
20
+ * @param options 格式化选项
21
+ * @returns 格式化后的字符串,null 时返回 null
22
+ *
23
+ * @example
24
+ * formatNumber(1234.567, { precision: 2, useGrouping: true })
25
+ * // 返回: "1,234.57"
26
+ *
27
+ * @example
28
+ * formatNumber(1234, { precision: 0, useGrouping: true })
29
+ * // 返回: "1,234"
30
+ */
31
+ declare function formatNumber(value: number | null | undefined, options?: NumberFormatOptions): string | null;
32
+ /**
33
+ * 添加千分位分隔符
34
+ *
35
+ * @param value 数值
36
+ * @returns 添加千分位后的字符串
37
+ *
38
+ * @example
39
+ * addThousandsSeparator(1234567)
40
+ * // 返回: "1,234,567"
41
+ */
42
+ declare function addThousandsSeparator(value: number): string;
43
+ /**
44
+ * 格式化精度
45
+ *
46
+ * @param value 数值
47
+ * @param precision 小数位数
48
+ * @returns 格式化后的数值
49
+ *
50
+ * @example
51
+ * formatPrecision(1.2345, 2)
52
+ * // 返回: 1.23
53
+ */
54
+ declare function formatPrecision(value: number, precision: number): number;
55
+ //#endregion
56
+ export { NumberFormatOptions, addThousandsSeparator, formatNumber, formatPrecision };
@@ -0,0 +1,56 @@
1
+ //#region src/number-input/utils/formatter.ts
2
+ /**
3
+ * 格式化数值
4
+ *
5
+ * @param value 数值
6
+ * @param options 格式化选项
7
+ * @returns 格式化后的字符串,null 时返回 null
8
+ *
9
+ * @example
10
+ * formatNumber(1234.567, { precision: 2, useGrouping: true })
11
+ * // 返回: "1,234.57"
12
+ *
13
+ * @example
14
+ * formatNumber(1234, { precision: 0, useGrouping: true })
15
+ * // 返回: "1,234"
16
+ */
17
+ function formatNumber(value, options = {}) {
18
+ if (value === null || value === void 0) return null;
19
+ const { precision, useGrouping = false, formatter } = options;
20
+ if (formatter) return formatter(value);
21
+ if (useGrouping || precision !== void 0) return value.toLocaleString("zh-CN", {
22
+ minimumFractionDigits: precision,
23
+ maximumFractionDigits: precision,
24
+ useGrouping
25
+ });
26
+ return String(value);
27
+ }
28
+ /**
29
+ * 添加千分位分隔符
30
+ *
31
+ * @param value 数值
32
+ * @returns 添加千分位后的字符串
33
+ *
34
+ * @example
35
+ * addThousandsSeparator(1234567)
36
+ * // 返回: "1,234,567"
37
+ */
38
+ function addThousandsSeparator(value) {
39
+ return value.toLocaleString("zh-CN", { useGrouping: true });
40
+ }
41
+ /**
42
+ * 格式化精度
43
+ *
44
+ * @param value 数值
45
+ * @param precision 小数位数
46
+ * @returns 格式化后的数值
47
+ *
48
+ * @example
49
+ * formatPrecision(1.2345, 2)
50
+ * // 返回: 1.23
51
+ */
52
+ function formatPrecision(value, precision) {
53
+ return Number(value.toFixed(precision));
54
+ }
55
+ //#endregion
56
+ export { addThousandsSeparator, formatNumber, formatPrecision };
@@ -0,0 +1,32 @@
1
+ import { ValidationResult } from "../../common/types.js";
2
+ import { BaseNumberInputProps } from "../types.js";
3
+
4
+ //#region src/number-input/utils/validation.d.ts
5
+ /**
6
+ * 校验数值输入
7
+ *
8
+ * 按照优先级执行校验规则:
9
+ * 1. 必填校验(required)
10
+ * 2. 最小值校验(min)
11
+ * 3. 最大值校验(max)
12
+ * 4. 自定义校验函数(validator)
13
+ *
14
+ * @param value 待校验的值
15
+ * @param props 校验配置
16
+ * @returns 校验结果对象,包含 isValid 和 errors
17
+ *
18
+ * @example
19
+ * validateValue(10, { required: true, min: 0, max: 100 })
20
+ * // { isValid: true, errors: [] }
21
+ *
22
+ * @example
23
+ * validateValue(null, { required: true })
24
+ * // { isValid: false, errors: ['此字段为必填项'] }
25
+ *
26
+ * @example
27
+ * validateValue(150, { min: 0, max: 100 })
28
+ * // { isValid: false, errors: ['不能大于 100'] }
29
+ */
30
+ declare function validateValue(value: number | null | undefined, props: BaseNumberInputProps): ValidationResult;
31
+ //#endregion
32
+ export { validateValue };
@@ -0,0 +1,52 @@
1
+ //#region src/number-input/utils/validation.ts
2
+ /**
3
+ * 校验数值输入
4
+ *
5
+ * 按照优先级执行校验规则:
6
+ * 1. 必填校验(required)
7
+ * 2. 最小值校验(min)
8
+ * 3. 最大值校验(max)
9
+ * 4. 自定义校验函数(validator)
10
+ *
11
+ * @param value 待校验的值
12
+ * @param props 校验配置
13
+ * @returns 校验结果对象,包含 isValid 和 errors
14
+ *
15
+ * @example
16
+ * validateValue(10, { required: true, min: 0, max: 100 })
17
+ * // { isValid: true, errors: [] }
18
+ *
19
+ * @example
20
+ * validateValue(null, { required: true })
21
+ * // { isValid: false, errors: ['此字段为必填项'] }
22
+ *
23
+ * @example
24
+ * validateValue(150, { min: 0, max: 100 })
25
+ * // { isValid: false, errors: ['不能大于 100'] }
26
+ */
27
+ function validateValue(value, props) {
28
+ const errors = [];
29
+ if (props.required && (value === null || value === void 0)) {
30
+ errors.push(props.errorMessage || "此字段为必填项");
31
+ return {
32
+ isValid: false,
33
+ errors
34
+ };
35
+ }
36
+ if (value === null || value === void 0) return {
37
+ isValid: true,
38
+ errors
39
+ };
40
+ if (props.min !== void 0 && value < props.min) errors.push(`不能小于 ${props.min}`);
41
+ if (props.max !== void 0 && value > props.max) errors.push(`不能大于 ${props.max}`);
42
+ if (props.validator) {
43
+ const result = props.validator(value);
44
+ if (result !== true) errors.push(typeof result === "string" ? result : "校验失败");
45
+ }
46
+ return {
47
+ isValid: errors.length === 0,
48
+ errors
49
+ };
50
+ }
51
+ //#endregion
52
+ export { validateValue };
@@ -1,3 +1,4 @@
1
+ //#region src/otherUtils.d.ts
1
2
  /**
2
3
  * @title: 判断是否无痕模式
3
4
  * @description:
@@ -5,11 +6,11 @@
5
6
  * @Author: shengjie.zuo
6
7
  * @Date: 2024-09-4 09:58:22
7
8
  */
8
- export declare const detectIncognito: () => Promise<{
9
- isPrivate: boolean;
10
- browserName: string;
9
+ declare const detectIncognito: () => Promise<{
10
+ isPrivate: boolean;
11
+ browserName: string;
11
12
  } | {
12
- isPrivate: boolean;
13
+ isPrivate: boolean;
13
14
  }>;
14
15
  /**
15
16
  * @Description: 生成唯一id
@@ -18,7 +19,7 @@ export declare const detectIncognito: () => Promise<{
18
19
  * @param {*}
19
20
  * @return {*}
20
21
  */
21
- export declare const getUniqueId: (prefix?: string, maxLength?: number) => string;
22
+ declare const getUniqueId: (prefix?: string, maxLength?: number) => string;
22
23
  /**
23
24
  * @title: 对数组进行增|删
24
25
  * @description: 用于多选选中和取消选中的处理
@@ -29,7 +30,7 @@ export declare const getUniqueId: (prefix?: string, maxLength?: number) => strin
29
30
  * @Author: zhiwei.Wang
30
31
  * @Date: 2023-12-19 16:44
31
32
  */
32
- export declare const changeArray: <T>(list: T[] | undefined, item: T, key?: string) => T[];
33
+ declare const changeArray: <T>(list: T[] | undefined, item: T, key?: string) => T[];
33
34
  /**
34
35
  * @title: 判断某个字段是否在列表内
35
36
  * @description:
@@ -39,10 +40,12 @@ export declare const changeArray: <T>(list: T[] | undefined, item: T, key?: stri
39
40
  * @Author: zhiwei.Wang
40
41
  * @Date: 2023-12-19 16:54
41
42
  */
42
- export declare const getItemByArray: <T>(list: T[] | undefined, item: T, key?: string) => boolean;
43
- export declare const createArray: (length: number, returnItem: any) => unknown[];
43
+ declare const getItemByArray: <T>(list: T[] | undefined, item: T, key?: string) => boolean;
44
+ declare const createArray: (length: number, returnItem: any) => unknown[];
44
45
  /**
45
46
  * 根据对象内容生成唯一id
46
47
  * @param obj
47
48
  */
48
- export declare const generateUniqueIdByObj: (obj: Record<string, any>) => any;
49
+ declare const generateUniqueIdByObj: (obj: Record<string, any>) => any;
50
+ //#endregion
51
+ export { changeArray, createArray, detectIncognito, generateUniqueIdByObj, getItemByArray, getUniqueId };
package/es/otherUtils.js CHANGED
@@ -1,132 +1,83 @@
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 _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
- // @ts-ignore
1
+ import { _asyncToGenerator } from "./_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
6
2
  import md5 from "crypto-js/md5";
7
- // @ts-ignore
8
3
  import enc from "crypto-js/enc-hex";
9
- import { detectIncognito as originDetectIncognito } from "detectincognitojs";
10
-
4
+ import { detectIncognito } from "detectincognitojs";
5
+ //#region src/otherUtils.ts
11
6
  /**
12
- * @title: 判断是否无痕模式
13
- * @description:
14
- * @return: *
15
- * @Author: shengjie.zuo
16
- * @Date: 2024-09-4 09:58:22
17
- */
18
- export var detectIncognito = /*#__PURE__*/function () {
19
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
20
- return _regeneratorRuntime().wrap(function _callee$(_context) {
21
- while (1) switch (_context.prev = _context.next) {
22
- case 0:
23
- if (!navigator.userAgent.toLowerCase().includes('honor')) {
24
- _context.next = 2;
25
- break;
26
- }
27
- return _context.abrupt("return", {
28
- isPrivate: false
29
- });
30
- case 2:
31
- _context.next = 4;
32
- return originDetectIncognito();
33
- case 4:
34
- return _context.abrupt("return", _context.sent);
35
- case 5:
36
- case "end":
37
- return _context.stop();
38
- }
39
- }, _callee);
40
- }));
41
- return function detectIncognito() {
42
- return _ref.apply(this, arguments);
43
- };
7
+ * @title: 判断是否无痕模式
8
+ * @description:
9
+ * @return: *
10
+ * @Author: shengjie.zuo
11
+ * @Date: 2024-09-4 09:58:22
12
+ */
13
+ const detectIncognito$1 = function() {
14
+ var _ref = _asyncToGenerator(function* () {
15
+ try {
16
+ if (navigator.userAgent.toLowerCase().includes("honor")) return { isPrivate: false };
17
+ return yield detectIncognito();
18
+ } catch (error) {
19
+ console.warn("detectIncognito failed:", error);
20
+ return { isPrivate: false };
21
+ }
22
+ });
23
+ return function detectIncognito$2() {
24
+ return _ref.apply(this, arguments);
25
+ };
44
26
  }();
45
-
46
27
  /**
47
- * @Description: 生成唯一id
48
- * @Author: wzw
49
- * @Date: 2020-12-01 14:20:29
50
- * @param {*}
51
- * @return {*}
52
- */
53
- export var getUniqueId = function getUniqueId() {
54
- var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
55
- var maxLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 11;
56
- return prefix + (Math.random() + '').replace(/\D/g, '').substring(0, maxLength);
28
+ * @Description: 生成唯一id
29
+ * @Author: wzw
30
+ * @Date: 2020-12-01 14:20:29
31
+ * @param {*}
32
+ * @return {*}
33
+ */
34
+ const getUniqueId = (prefix = "", maxLength = 11) => {
35
+ return prefix + (Math.random() + "").replace(/\D/g, "").substring(0, maxLength);
57
36
  };
58
-
59
37
  /**
60
- * @title: 对数组进行增|删
61
- * @description: 用于多选选中和取消选中的处理
62
- * @param {any} list
63
- * @param {any} item
64
- * @param {string} key
65
- * @return {*}
66
- * @Author: zhiwei.Wang
67
- * @Date: 2023-12-19 16:44
68
- */
69
- export var changeArray = function changeArray() {
70
- var list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
71
- var item = arguments.length > 1 ? arguments[1] : undefined;
72
- var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'this';
73
- var _list = JSON.parse(JSON.stringify(list));
74
- var isSome = false;
75
- if (key === 'this') {
76
- isSome = _list.includes(item);
77
- } else {
78
- //@ts-ignore
79
- isSome = _list.some(function (d) {
80
- return d[key] === item[key];
81
- });
82
- }
83
- if (isSome) {
84
- _list = _list.filter(function (d) {
85
- if (key === 'this') {
86
- return d !== item;
87
- }
88
-
89
- //@ts-ignore
90
- return d[key] !== item[key];
91
- });
92
- } else {
93
- _list.push(item);
94
- }
95
- return _list;
38
+ * @title: 对数组进行增|删
39
+ * @description: 用于多选选中和取消选中的处理
40
+ * @param {any} list
41
+ * @param {any} item
42
+ * @param {string} key
43
+ * @return {*}
44
+ * @Author: zhiwei.Wang
45
+ * @Date: 2023-12-19 16:44
46
+ */
47
+ const changeArray = (list = [], item, key = "this") => {
48
+ let _list = JSON.parse(JSON.stringify(list));
49
+ let isSome = false;
50
+ if (key === "this") isSome = _list.includes(item);
51
+ else isSome = _list.some((d) => d[key] === item[key]);
52
+ if (isSome) _list = _list.filter((d) => {
53
+ if (key === "this") return d !== item;
54
+ return d[key] !== item[key];
55
+ });
56
+ else _list.push(item);
57
+ return _list;
96
58
  };
97
-
98
59
  /**
99
- * @title: 判断某个字段是否在列表内
100
- * @description:
101
- * @param {*} T
102
- * @param {boolean} param2
103
- * @return {*}
104
- * @Author: zhiwei.Wang
105
- * @Date: 2023-12-19 16:54
106
- */
107
- export var getItemByArray = function getItemByArray() {
108
- var list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
109
- var item = arguments.length > 1 ? arguments[1] : undefined;
110
- var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'this';
111
- if (key === 'this') {
112
- return list.includes(item);
113
- }
114
-
115
- //@ts-ignore
116
- return list.some(function (d) {
117
- return d[key] === item[key];
118
- });
60
+ * @title: 判断某个字段是否在列表内
61
+ * @description:
62
+ * @param {*} T
63
+ * @param {boolean} param2
64
+ * @return {*}
65
+ * @Author: zhiwei.Wang
66
+ * @Date: 2023-12-19 16:54
67
+ */
68
+ const getItemByArray = (list = [], item, key = "this") => {
69
+ if (key === "this") return list.includes(item);
70
+ return list.some((d) => d[key] === item[key]);
119
71
  };
120
- export var createArray = function createArray(length, returnItem) {
121
- return Array.from(new Array(length)).map(returnItem);
72
+ const createArray = (length, returnItem) => {
73
+ return Array.from(new Array(length)).map(returnItem);
122
74
  };
123
-
124
75
  /**
125
- * 根据对象内容生成唯一id
126
- * @param obj
127
- */
128
- export var generateUniqueIdByObj = function generateUniqueIdByObj(obj) {
129
- var jsonString = JSON.stringify(obj);
130
- var hash = md5(jsonString);
131
- return hash.toString(enc.Hex);
132
- };
76
+ * 根据对象内容生成唯一id
77
+ * @param obj
78
+ */
79
+ const generateUniqueIdByObj = (obj) => {
80
+ return md5(JSON.stringify(obj)).toString(enc.Hex);
81
+ };
82
+ //#endregion
83
+ export { changeArray, createArray, detectIncognito$1 as detectIncognito, generateUniqueIdByObj, getItemByArray, getUniqueId };
package/es/platform.d.ts CHANGED
@@ -1,9 +1,12 @@
1
- export declare const isIpad: () => boolean;
2
- export declare const isMobile: () => boolean;
3
- export declare const isAndroid: () => boolean;
4
- export declare const isIos: () => boolean;
5
- export declare const checkEnv: () => number;
6
- export declare const isWx: () => boolean;
7
- export declare const isIOS: () => boolean;
8
- export declare const isWxApp: () => boolean;
9
- export declare const isSafari: () => boolean;
1
+ //#region src/platform.d.ts
2
+ declare const isIpad: () => boolean;
3
+ declare const isMobile: () => boolean;
4
+ declare const isAndroid: () => boolean;
5
+ declare const isIos: () => boolean;
6
+ declare const checkEnv: () => number;
7
+ declare const isWx: () => boolean;
8
+ declare const isIOS: () => boolean;
9
+ declare const isWxApp: () => boolean;
10
+ declare const isSafari: () => boolean;
11
+ //#endregion
12
+ export { checkEnv, isAndroid, isIOS, isIos, isIpad, isMobile, isSafari, isWx, isWxApp };