@pisell/utils 3.0.4 → 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/format.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @title: 格式化金额
3
+ * @description:
4
+ * @param {number} amount 原金额
5
+ * @param {number} precision 小数位数
6
+ * @param {string} symbol 货币符号
7
+ * @return {*}
8
+ * @Author: zhiwei.Wang
9
+ * @Date: 2023-11-06 16:51
10
+ */
11
+ export declare const formatAmount: (amount?: number | string, precision?: number, symbol?: string) => string | number;
12
+ export declare type FormatOptions = {
13
+ /** 小数点后位数 默认是小数点后2位 */
14
+ precision?: number;
15
+ /** 显示货币符号 指的是 ¥$ 等货币符号等显隐,默认是展示 */
16
+ showCurrencySymbol?: boolean;
17
+ /** 千分位 指的是长金额的千分位逗号隔开,比如“123, 245, 315” 这种展现形式,默认是关闭 */
18
+ useThousandsSeparator?: boolean;
19
+ /** 整数位隐藏小数 指的是如果价格为整数,后面的".00" 将被省略以节省页面空间 */
20
+ hideDecimalForWholeNumbers?: boolean;
21
+ };
22
+ /**
23
+ * 根据配置格式化金额
24
+ * @param amount
25
+ * @param symbol
26
+ * @param options
27
+ */
28
+ export declare const formatAmountWithOptions: (amount: string | number | undefined, symbol: string | undefined, options: FormatOptions) => string | number;
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);
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @title: 格式化金额
3
+ * @description:
4
+ * @param {number} amount 原金额
5
+ * @param {number} precision 小数位数
6
+ * @param {string} symbol 货币符号
7
+ * @return {*}
8
+ * @Author: zhiwei.Wang
9
+ * @Date: 2023-11-06 16:51
10
+ */
11
+ export declare const formatAmount: (amount?: number | string, precision?: number, symbol?: string) => string | number;
12
+ export declare type FormatOptions = {
13
+ /** 小数点后位数 默认是小数点后2位 */
14
+ precision?: number;
15
+ /** 显示货币符号 指的是 ¥$ 等货币符号等显隐,默认是展示 */
16
+ showCurrencySymbol?: boolean;
17
+ /** 千分位 指的是长金额的千分位逗号隔开,比如“123, 245, 315” 这种展现形式,默认是关闭 */
18
+ useThousandsSeparator?: boolean;
19
+ /** 整数位隐藏小数 指的是如果价格为整数,后面的".00" 将被省略以节省页面空间 */
20
+ hideDecimalForWholeNumbers?: boolean;
21
+ };
22
+ /**
23
+ * 根据配置格式化金额
24
+ * @param amount
25
+ * @param symbol
26
+ * @param options
27
+ */
28
+ export declare const formatAmountWithOptions: (amount: string | number | undefined, symbol: string | undefined, options: FormatOptions) => string | number;
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.4",
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;