@pisell/utils 3.0.3 → 3.0.5

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.
package/es/index.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ export * from './otherUtils';
2
+ export * from './typeUtils';
3
+ export * from './document';
4
+ export * from './date';
5
+ export * from './platform';
6
+ export * from './log';
7
+ export * from './format';
8
+ export * from './escPosPrinter';
9
+ export * from './miniRedux';
10
+ export * from './jsBridge';
11
+ export * from './image';
12
+ export * from './locales';
13
+ export * from './arrayUtils';
14
+ export * from './walletValidity';
15
+ export declare const setPisellUtilsConfig: (config: {
16
+ [key: string]: any;
17
+ }) => void;
18
+ export declare const getPisellUtilsConfig: () => {
19
+ [key: string]: any;
20
+ };
@@ -0,0 +1,118 @@
1
+ declare type LanguageNumber = {
2
+ en: number;
3
+ zh_CN: number;
4
+ zh_HK: number;
5
+ };
6
+ declare type LanguageString = {
7
+ en: string;
8
+ zh_CN: string;
9
+ zh_HK: string;
10
+ } | string;
11
+ /**
12
+ * 打印小票
13
+ */
14
+ declare type WebPrint0 = {
15
+ /**
16
+ * 打印类型
17
+ * 0: 小票
18
+ * 1:ITS备货单/划菜单
19
+ * 2:手环
20
+ */
21
+ type: "0";
22
+ data: {
23
+ /** 订单ID */
24
+ order_id: string;
25
+ };
26
+ /** 打印语言对应的数量 */
27
+ language: LanguageNumber;
28
+ };
29
+ /**
30
+ * 打印ITS备货单/划菜单
31
+ */
32
+ declare type WebPrint1 = {
33
+ /**
34
+ * 打印类型
35
+ * 0: 小票
36
+ * 1:ITS备货单/划菜单
37
+ * 2:手环
38
+ */
39
+ type: "1";
40
+ data: {
41
+ /** 0:备货 1:划单 */
42
+ mode: "0" | "1";
43
+ resource: LanguageString;
44
+ /** 订单备注 */
45
+ order_note: string;
46
+ /** 订单时间或商品下单时间 */
47
+ time: string;
48
+ /** 订单编号 */
49
+ order_number?: string;
50
+ /** 商品 */
51
+ products: {
52
+ /** 商品名称 */
53
+ product_title: LanguageString;
54
+ /** 商品规格 */
55
+ product_option_string: LanguageString;
56
+ /** 商品备注 */
57
+ product_note: string;
58
+ /** 商品数量 */
59
+ product_quantity: number;
60
+ /** 加菜标识 待定 */
61
+ is_append?: boolean;
62
+ /** 退菜标识 待定 */
63
+ is_removed?: boolean;
64
+ }[];
65
+ };
66
+ /** 打印语言对应的数量 */
67
+ language: LanguageNumber;
68
+ };
69
+ declare type WebPrint2 = {
70
+ /**
71
+ * 打印类型
72
+ * 0: 小票
73
+ * 1:ITS备货单/划菜单
74
+ * 2:手环
75
+ */
76
+ type: "2";
77
+ data: {
78
+ /** 0: 普通票 1:成人票 2:免费成人票 */
79
+ type: "0" | "1" | "2";
80
+ /** 发行编码 */
81
+ encoded: string;
82
+ /** 编码 */
83
+ code: string;
84
+ /** 到期时间 */
85
+ expire_date: string;
86
+ areas: {
87
+ /** 区域名字 */
88
+ area_name: string;
89
+ /** 区域代码 */
90
+ area_code: string;
91
+ /** 可用次数 */
92
+ limit_num: number;
93
+ /** 已用次数 */
94
+ used_num: number;
95
+ }[];
96
+ };
97
+ };
98
+ declare type WebPrintParams = WebPrint0 | WebPrint1 | WebPrint2;
99
+ /**
100
+ * webView页面中调用打印机打印
101
+ * 此api暂时只支持native app平台下ios手机
102
+ * @param params
103
+ * @param callback
104
+ */
105
+ export declare function webPrint(params: WebPrintParams, callback: (...arg: any) => void): void;
106
+ declare type DataManagerParams = {
107
+ module: "set" | "get";
108
+ key: string;
109
+ data?: any;
110
+ };
111
+ /**
112
+ * webView页面中调用APP内的数据
113
+ * 此api暂时只支持native app平台下ios手机
114
+ * @param params
115
+ * @param callback
116
+ */
117
+ export declare function dataManager(params: DataManagerParams, callback: (...arg: any) => void, onError: () => void): void;
118
+ export {};
@@ -68,10 +68,10 @@ function getComposedBridge(deviceType) {
68
68
  } catch (error) {
69
69
  console.log("error ".concat(apiName), error);
70
70
  }
71
- if (result.code || result.code === 0) {
72
- // 强转字符串,兼容安卓的number
73
- result.code = "".concat(result.code);
74
- }
71
+ // if (result.code || result.code === 0) {
72
+ // // 强转字符串,兼容安卓的number
73
+ // result.code = `${result.code}`;
74
+ // }
75
75
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
76
76
  args[_key - 1] = arguments[_key];
77
77
  }
@@ -0,0 +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;
12
+ };
@@ -0,0 +1,16 @@
1
+ interface MiniReduxProps<State, Namespace> {
2
+ namespace?: Namespace;
3
+ state?: State;
4
+ reducers?: any;
5
+ effects?: any;
6
+ }
7
+ export declare const miniRedux: <State extends Record<string, any>, Namespace extends string>({ namespace, state, reducers, effects, }: MiniReduxProps<State, Namespace>) => {
8
+ Context: React.Context<{ [K in Namespace]: State; } & {
9
+ dispatch: (params: {
10
+ type: string;
11
+ payload: any;
12
+ }) => void;
13
+ }>;
14
+ Provider: (ComponentUi: any) => any;
15
+ };
16
+ export {};
package/es/otherUtils.js CHANGED
@@ -20,23 +20,32 @@ export var detectIncognito = /*#__PURE__*/function () {
20
20
  return _regeneratorRuntime().wrap(function _callee$(_context) {
21
21
  while (1) switch (_context.prev = _context.next) {
22
22
  case 0:
23
+ _context.prev = 0;
23
24
  if (!navigator.userAgent.toLowerCase().includes('honor')) {
24
- _context.next = 2;
25
+ _context.next = 3;
25
26
  break;
26
27
  }
27
28
  return _context.abrupt("return", {
28
29
  isPrivate: false
29
30
  });
30
- case 2:
31
- _context.next = 4;
31
+ case 3:
32
+ _context.next = 5;
32
33
  return originDetectIncognito();
33
- case 4:
34
- return _context.abrupt("return", _context.sent);
35
34
  case 5:
35
+ return _context.abrupt("return", _context.sent);
36
+ case 8:
37
+ _context.prev = 8;
38
+ _context.t0 = _context["catch"](0);
39
+ // 当无法检测浏览器类型时,默认返回非隐私模式,确保支付流程可以继续
40
+ console.warn('detectIncognito failed:', _context.t0);
41
+ return _context.abrupt("return", {
42
+ isPrivate: false
43
+ });
44
+ case 12:
36
45
  case "end":
37
46
  return _context.stop();
38
47
  }
39
- }, _callee);
48
+ }, _callee, null, [[0, 8]]);
40
49
  }));
41
50
  return function detectIncognito() {
42
51
  return _ref.apply(this, arguments);
package/lib/index.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ export * from './otherUtils';
2
+ export * from './typeUtils';
3
+ export * from './document';
4
+ export * from './date';
5
+ export * from './platform';
6
+ export * from './log';
7
+ export * from './format';
8
+ export * from './escPosPrinter';
9
+ export * from './miniRedux';
10
+ export * from './jsBridge';
11
+ export * from './image';
12
+ export * from './locales';
13
+ export * from './arrayUtils';
14
+ export * from './walletValidity';
15
+ export declare const setPisellUtilsConfig: (config: {
16
+ [key: string]: any;
17
+ }) => void;
18
+ export declare const getPisellUtilsConfig: () => {
19
+ [key: string]: any;
20
+ };
@@ -0,0 +1,118 @@
1
+ declare type LanguageNumber = {
2
+ en: number;
3
+ zh_CN: number;
4
+ zh_HK: number;
5
+ };
6
+ declare type LanguageString = {
7
+ en: string;
8
+ zh_CN: string;
9
+ zh_HK: string;
10
+ } | string;
11
+ /**
12
+ * 打印小票
13
+ */
14
+ declare type WebPrint0 = {
15
+ /**
16
+ * 打印类型
17
+ * 0: 小票
18
+ * 1:ITS备货单/划菜单
19
+ * 2:手环
20
+ */
21
+ type: "0";
22
+ data: {
23
+ /** 订单ID */
24
+ order_id: string;
25
+ };
26
+ /** 打印语言对应的数量 */
27
+ language: LanguageNumber;
28
+ };
29
+ /**
30
+ * 打印ITS备货单/划菜单
31
+ */
32
+ declare type WebPrint1 = {
33
+ /**
34
+ * 打印类型
35
+ * 0: 小票
36
+ * 1:ITS备货单/划菜单
37
+ * 2:手环
38
+ */
39
+ type: "1";
40
+ data: {
41
+ /** 0:备货 1:划单 */
42
+ mode: "0" | "1";
43
+ resource: LanguageString;
44
+ /** 订单备注 */
45
+ order_note: string;
46
+ /** 订单时间或商品下单时间 */
47
+ time: string;
48
+ /** 订单编号 */
49
+ order_number?: string;
50
+ /** 商品 */
51
+ products: {
52
+ /** 商品名称 */
53
+ product_title: LanguageString;
54
+ /** 商品规格 */
55
+ product_option_string: LanguageString;
56
+ /** 商品备注 */
57
+ product_note: string;
58
+ /** 商品数量 */
59
+ product_quantity: number;
60
+ /** 加菜标识 待定 */
61
+ is_append?: boolean;
62
+ /** 退菜标识 待定 */
63
+ is_removed?: boolean;
64
+ }[];
65
+ };
66
+ /** 打印语言对应的数量 */
67
+ language: LanguageNumber;
68
+ };
69
+ declare type WebPrint2 = {
70
+ /**
71
+ * 打印类型
72
+ * 0: 小票
73
+ * 1:ITS备货单/划菜单
74
+ * 2:手环
75
+ */
76
+ type: "2";
77
+ data: {
78
+ /** 0: 普通票 1:成人票 2:免费成人票 */
79
+ type: "0" | "1" | "2";
80
+ /** 发行编码 */
81
+ encoded: string;
82
+ /** 编码 */
83
+ code: string;
84
+ /** 到期时间 */
85
+ expire_date: string;
86
+ areas: {
87
+ /** 区域名字 */
88
+ area_name: string;
89
+ /** 区域代码 */
90
+ area_code: string;
91
+ /** 可用次数 */
92
+ limit_num: number;
93
+ /** 已用次数 */
94
+ used_num: number;
95
+ }[];
96
+ };
97
+ };
98
+ declare type WebPrintParams = WebPrint0 | WebPrint1 | WebPrint2;
99
+ /**
100
+ * webView页面中调用打印机打印
101
+ * 此api暂时只支持native app平台下ios手机
102
+ * @param params
103
+ * @param callback
104
+ */
105
+ export declare function webPrint(params: WebPrintParams, callback: (...arg: any) => void): void;
106
+ declare type DataManagerParams = {
107
+ module: "set" | "get";
108
+ key: string;
109
+ data?: any;
110
+ };
111
+ /**
112
+ * webView页面中调用APP内的数据
113
+ * 此api暂时只支持native app平台下ios手机
114
+ * @param params
115
+ * @param callback
116
+ */
117
+ export declare function dataManager(params: DataManagerParams, callback: (...arg: any) => void, onError: () => void): void;
118
+ export {};
@@ -85,9 +85,6 @@ function getComposedBridge(deviceType) {
85
85
  } catch (error) {
86
86
  console.log(`error ${apiName}`, error);
87
87
  }
88
- if (result.code || result.code === 0) {
89
- result.code = `${result.code}`;
90
- }
91
88
  inCb(result, ...args);
92
89
  };
93
90
  if (deviceType === "iphone") {
@@ -0,0 +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;
12
+ };
@@ -0,0 +1,16 @@
1
+ interface MiniReduxProps<State, Namespace> {
2
+ namespace?: Namespace;
3
+ state?: State;
4
+ reducers?: any;
5
+ effects?: any;
6
+ }
7
+ export declare const miniRedux: <State extends Record<string, any>, Namespace extends string>({ namespace, state, reducers, effects, }: MiniReduxProps<State, Namespace>) => {
8
+ Context: React.Context<{ [K in Namespace]: State; } & {
9
+ dispatch: (params: {
10
+ type: string;
11
+ payload: any;
12
+ }) => void;
13
+ }>;
14
+ Provider: (ComponentUi: any) => any;
15
+ };
16
+ export {};
package/lib/otherUtils.js CHANGED
@@ -41,12 +41,19 @@ var import_md5 = __toESM(require("crypto-js/md5"));
41
41
  var import_enc_hex = __toESM(require("crypto-js/enc-hex"));
42
42
  var import_detectincognitojs = require("detectincognitojs");
43
43
  var detectIncognito = async () => {
44
- if (navigator.userAgent.toLowerCase().includes("honor")) {
44
+ try {
45
+ if (navigator.userAgent.toLowerCase().includes("honor")) {
46
+ return {
47
+ isPrivate: false
48
+ };
49
+ }
50
+ return await (0, import_detectincognitojs.detectIncognito)();
51
+ } catch (error) {
52
+ console.warn("detectIncognito failed:", error);
45
53
  return {
46
54
  isPrivate: false
47
55
  };
48
56
  }
49
- return await (0, import_detectincognitojs.detectIncognito)();
50
57
  };
51
58
  var getUniqueId = (prefix = "", maxLength = 11) => {
52
59
  return prefix + (Math.random() + "").replace(/\D/g, "").substring(0, maxLength);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/utils",
3
- "version": "3.0.3",
3
+ "version": "3.0.5",
4
4
  "sideEffects": false,
5
5
  "main": "./lib/index.js",
6
6
  "module": "./es/index.js",
@@ -1,7 +0,0 @@
1
- declare const webHookApi: {
2
- warning_log: {
3
- test: string;
4
- prod: string;
5
- };
6
- };
7
- export { webHookApi };
@@ -1,48 +0,0 @@
1
- /**
2
- * @title: 判断是否无痕模式
3
- * @description:
4
- * @return: *
5
- * @Author: shengjie.zuo
6
- * @Date: 2024-09-4 09:58:22
7
- */
8
- export declare const detectIncognito: () => Promise<{
9
- isPrivate: boolean;
10
- browserName: string;
11
- } | {
12
- isPrivate: boolean;
13
- }>;
14
- /**
15
- * @Description: 生成唯一id
16
- * @Author: wzw
17
- * @Date: 2020-12-01 14:20:29
18
- * @param {*}
19
- * @return {*}
20
- */
21
- export declare const getUniqueId: (prefix?: string, maxLength?: number) => string;
22
- /**
23
- * @title: 对数组进行增|删
24
- * @description: 用于多选选中和取消选中的处理
25
- * @param {any} list
26
- * @param {any} item
27
- * @param {string} key
28
- * @return {*}
29
- * @Author: zhiwei.Wang
30
- * @Date: 2023-12-19 16:44
31
- */
32
- export declare const changeArray: <T>(list: T[] | undefined, item: T, key?: string) => T[];
33
- /**
34
- * @title: 判断某个字段是否在列表内
35
- * @description:
36
- * @param {*} T
37
- * @param {boolean} param2
38
- * @return {*}
39
- * @Author: zhiwei.Wang
40
- * @Date: 2023-12-19 16:54
41
- */
42
- export declare const getItemByArray: <T>(list: T[] | undefined, item: T, key?: string) => boolean;
43
- export declare const createArray: (length: number, returnItem: any) => unknown[];
44
- /**
45
- * 根据对象内容生成唯一id
46
- * @param obj
47
- */
48
- export declare const generateUniqueIdByObj: (obj: Record<string, any>) => any;
@@ -1,7 +0,0 @@
1
- declare const webHookApi: {
2
- warning_log: {
3
- test: string;
4
- prod: string;
5
- };
6
- };
7
- export { webHookApi };
@@ -1,48 +0,0 @@
1
- /**
2
- * @title: 判断是否无痕模式
3
- * @description:
4
- * @return: *
5
- * @Author: shengjie.zuo
6
- * @Date: 2024-09-4 09:58:22
7
- */
8
- export declare const detectIncognito: () => Promise<{
9
- isPrivate: boolean;
10
- browserName: string;
11
- } | {
12
- isPrivate: boolean;
13
- }>;
14
- /**
15
- * @Description: 生成唯一id
16
- * @Author: wzw
17
- * @Date: 2020-12-01 14:20:29
18
- * @param {*}
19
- * @return {*}
20
- */
21
- export declare const getUniqueId: (prefix?: string, maxLength?: number) => string;
22
- /**
23
- * @title: 对数组进行增|删
24
- * @description: 用于多选选中和取消选中的处理
25
- * @param {any} list
26
- * @param {any} item
27
- * @param {string} key
28
- * @return {*}
29
- * @Author: zhiwei.Wang
30
- * @Date: 2023-12-19 16:44
31
- */
32
- export declare const changeArray: <T>(list: T[] | undefined, item: T, key?: string) => T[];
33
- /**
34
- * @title: 判断某个字段是否在列表内
35
- * @description:
36
- * @param {*} T
37
- * @param {boolean} param2
38
- * @return {*}
39
- * @Author: zhiwei.Wang
40
- * @Date: 2023-12-19 16:54
41
- */
42
- export declare const getItemByArray: <T>(list: T[] | undefined, item: T, key?: string) => boolean;
43
- export declare const createArray: (length: number, returnItem: any) => unknown[];
44
- /**
45
- * 根据对象内容生成唯一id
46
- * @param obj
47
- */
48
- export declare const generateUniqueIdByObj: (obj: Record<string, any>) => any;