@pisell/utils 1.0.68 → 1.0.71

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 (130) hide show
  1. package/README.md +2 -2
  2. package/es/arrayUtils.d.ts +1 -1
  3. package/es/common/index.d.ts +5 -5
  4. package/es/common/index.js +2 -2
  5. package/es/common/stateHelper.d.ts +18 -18
  6. package/es/common/stateHelper.js +15 -15
  7. package/es/common/types.d.ts +28 -28
  8. package/es/componentStorage.d.ts +36 -36
  9. package/es/componentStorage.js +7 -7
  10. package/es/constants/index.d.ts +7 -7
  11. package/es/date.d.ts +28 -28
  12. package/es/date.js +22 -22
  13. package/es/document.d.ts +13 -13
  14. package/es/document.js +7 -7
  15. package/es/escPosPrinter/index.d.ts +9 -9
  16. package/es/firebase/config/index.d.ts +13 -13
  17. package/es/firebase/index.d.ts +28 -28
  18. package/es/format.d.ts +28 -28
  19. package/es/format.js +14 -14
  20. package/es/image.d.ts +11 -11
  21. package/es/image.js +5 -5
  22. package/es/index.d.ts +25 -25
  23. package/es/jsBridge/index.d.ts +22 -22
  24. package/es/jsBridge/index.js +15 -15
  25. package/es/jsBridge/regDeviceApi.d.ts +15 -15
  26. package/es/jsBridge/regDeviceApi.js +3 -3
  27. package/es/jsBridge/types.d.ts +149 -149
  28. package/es/locales.d.ts +9 -9
  29. package/es/locales.js +40 -21
  30. package/es/log.d.ts +10 -10
  31. package/es/miniRedux.d.ts +16 -16
  32. package/es/number-input/hooks/index.d.ts +4 -4
  33. package/es/number-input/hooks/index.js +2 -2
  34. package/es/number-input/hooks/useNumberInputState.d.ts +25 -25
  35. package/es/number-input/hooks/useNumberInputState.js +39 -39
  36. package/es/number-input/index.d.ts +14 -14
  37. package/es/number-input/index.js +8 -8
  38. package/es/number-input/types.d.ts +96 -96
  39. package/es/number-input/utils/formatter.d.ts +53 -53
  40. package/es/number-input/utils/formatter.js +37 -37
  41. package/es/number-input/utils/index.d.ts +7 -7
  42. package/es/number-input/utils/index.js +2 -2
  43. package/es/number-input/utils/validation.d.ts +27 -27
  44. package/es/number-input/utils/validation.js +24 -24
  45. package/es/otherUtils.d.ts +48 -48
  46. package/es/otherUtils.js +32 -32
  47. package/es/platform.d.ts +9 -9
  48. package/es/select/hooks/index.d.ts +5 -5
  49. package/es/select/hooks/index.js +2 -2
  50. package/es/select/hooks/useDebouncedSearch.d.ts +20 -20
  51. package/es/select/hooks/useDebouncedSearch.js +17 -17
  52. package/es/select/hooks/useSelectState.d.ts +19 -19
  53. package/es/select/hooks/useSelectState.js +13 -13
  54. package/es/select/index.d.ts +8 -8
  55. package/es/select/index.js +3 -3
  56. package/es/select/types.d.ts +256 -256
  57. package/es/select/utils/filterOptions.d.ts +22 -22
  58. package/es/select/utils/filterOptions.js +16 -16
  59. package/es/select/utils/helpers.d.ts +42 -42
  60. package/es/select/utils/helpers.js +30 -30
  61. package/es/select/utils/index.d.ts +7 -7
  62. package/es/select/utils/index.js +2 -2
  63. package/es/select/utils/sortOptions.d.ts +12 -12
  64. package/es/select/utils/sortOptions.js +8 -8
  65. package/es/select/utils/tagAggregation.d.ts +25 -25
  66. package/es/select/utils/tagAggregation.js +21 -21
  67. package/es/text-input/hooks/index.d.ts +4 -4
  68. package/es/text-input/hooks/index.js +2 -2
  69. package/es/text-input/hooks/useTextInputState.d.ts +24 -24
  70. package/es/text-input/hooks/useTextInputState.js +38 -38
  71. package/es/text-input/index.d.ts +14 -14
  72. package/es/text-input/index.js +9 -9
  73. package/es/text-input/types.d.ts +56 -56
  74. package/es/text-input/utils/index.d.ts +5 -5
  75. package/es/text-input/utils/index.js +2 -2
  76. package/es/text-input/utils/validation.d.ts +23 -23
  77. package/es/text-input/utils/validation.js +20 -20
  78. package/es/typeUtils.d.ts +42 -42
  79. package/es/typeUtils.js +26 -26
  80. package/es/walletValidity.d.ts +44 -44
  81. package/es/walletValidity.js +85 -85
  82. package/lib/arrayUtils.d.ts +1 -1
  83. package/lib/common/index.d.ts +5 -5
  84. package/lib/common/stateHelper.d.ts +18 -18
  85. package/lib/common/types.d.ts +28 -28
  86. package/lib/componentStorage.d.ts +36 -36
  87. package/lib/constants/index.d.ts +7 -7
  88. package/lib/date.d.ts +28 -28
  89. package/lib/document.d.ts +13 -13
  90. package/lib/escPosPrinter/index.d.ts +9 -9
  91. package/lib/firebase/config/index.d.ts +13 -13
  92. package/lib/firebase/index.d.ts +28 -28
  93. package/lib/format.d.ts +28 -28
  94. package/lib/image.d.ts +11 -11
  95. package/lib/index.d.ts +25 -25
  96. package/lib/jsBridge/index.d.ts +22 -22
  97. package/lib/jsBridge/regDeviceApi.d.ts +15 -15
  98. package/lib/jsBridge/types.d.ts +149 -149
  99. package/lib/locales.d.ts +9 -9
  100. package/lib/locales.js +25 -6
  101. package/lib/log.d.ts +10 -10
  102. package/lib/miniRedux.d.ts +16 -16
  103. package/lib/number-input/hooks/index.d.ts +4 -4
  104. package/lib/number-input/hooks/useNumberInputState.d.ts +25 -25
  105. package/lib/number-input/index.d.ts +14 -14
  106. package/lib/number-input/types.d.ts +96 -96
  107. package/lib/number-input/utils/formatter.d.ts +53 -53
  108. package/lib/number-input/utils/index.d.ts +7 -7
  109. package/lib/number-input/utils/validation.d.ts +27 -27
  110. package/lib/otherUtils.d.ts +48 -48
  111. package/lib/platform.d.ts +9 -9
  112. package/lib/select/hooks/index.d.ts +5 -5
  113. package/lib/select/hooks/useDebouncedSearch.d.ts +20 -20
  114. package/lib/select/hooks/useSelectState.d.ts +19 -19
  115. package/lib/select/index.d.ts +8 -8
  116. package/lib/select/types.d.ts +256 -256
  117. package/lib/select/utils/filterOptions.d.ts +22 -22
  118. package/lib/select/utils/helpers.d.ts +42 -42
  119. package/lib/select/utils/index.d.ts +7 -7
  120. package/lib/select/utils/sortOptions.d.ts +12 -12
  121. package/lib/select/utils/tagAggregation.d.ts +25 -25
  122. package/lib/text-input/hooks/index.d.ts +4 -4
  123. package/lib/text-input/hooks/useTextInputState.d.ts +24 -24
  124. package/lib/text-input/index.d.ts +14 -14
  125. package/lib/text-input/types.d.ts +56 -56
  126. package/lib/text-input/utils/index.d.ts +5 -5
  127. package/lib/text-input/utils/validation.d.ts +23 -23
  128. package/lib/typeUtils.d.ts +42 -42
  129. package/lib/walletValidity.d.ts +44 -44
  130. package/package.json +1 -1
package/es/log.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- interface contentItem {
2
- key: string;
3
- value: string;
4
- }
5
- interface sendWebhookProps {
6
- title: string;
7
- content: contentItem[];
8
- }
9
- export declare const sendWarningLog: ({ title, content }: sendWebhookProps) => Promise<any>;
10
- export {};
1
+ interface contentItem {
2
+ key: string;
3
+ value: string;
4
+ }
5
+ interface sendWebhookProps {
6
+ title: string;
7
+ content: contentItem[];
8
+ }
9
+ export declare const sendWarningLog: ({ title, content }: sendWebhookProps) => Promise<any>;
10
+ export {};
package/es/miniRedux.d.ts CHANGED
@@ -1,16 +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 {};
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 {};
@@ -1,4 +1,4 @@
1
- /**
2
- * 数值输入 Hooks 导出
3
- */
4
- export { useNumberInputState } from './useNumberInputState';
1
+ /**
2
+ * 数值输入 Hooks 导出
3
+ */
4
+ export { useNumberInputState } from './useNumberInputState';
@@ -1,5 +1,5 @@
1
- /**
2
- * 数值输入 Hooks 导出
1
+ /**
2
+ * 数值输入 Hooks 导出
3
3
  */
4
4
 
5
5
  export { useNumberInputState } from "./useNumberInputState";
@@ -1,25 +1,25 @@
1
- import type { BaseNumberInputProps, NumberInputState } from '../types';
2
- /**
3
- * 数值输入状态管理 Hook
4
- *
5
- * 管理组件的内部状态,包括:
6
- * - 值管理(受控/非受控模式)
7
- * - 校验状态管理
8
- * - 事件处理函数封装
9
- *
10
- * 支持受控和非受控两种模式:
11
- * - 受控模式:value 由外部传入,组件不维护内部状态
12
- * - 非受控模式:使用 defaultValue,组件维护内部状态
13
- *
14
- * @param props 组件 Props(包含校验配置)
15
- * @returns 数值输入状态对象
16
- *
17
- * @example
18
- * // 受控模式
19
- * const state = useNumberInputState({ value: 10, onChange: (v) => console.log(v) });
20
- *
21
- * @example
22
- * // 非受控模式
23
- * const state = useNumberInputState({ defaultValue: 10, min: 0, max: 100 });
24
- */
25
- export declare function useNumberInputState(props: BaseNumberInputProps): NumberInputState;
1
+ import type { BaseNumberInputProps, NumberInputState } from '../types';
2
+ /**
3
+ * 数值输入状态管理 Hook
4
+ *
5
+ * 管理组件的内部状态,包括:
6
+ * - 值管理(受控/非受控模式)
7
+ * - 校验状态管理
8
+ * - 事件处理函数封装
9
+ *
10
+ * 支持受控和非受控两种模式:
11
+ * - 受控模式:value 由外部传入,组件不维护内部状态
12
+ * - 非受控模式:使用 defaultValue,组件维护内部状态
13
+ *
14
+ * @param props 组件 Props(包含校验配置)
15
+ * @returns 数值输入状态对象
16
+ *
17
+ * @example
18
+ * // 受控模式
19
+ * const state = useNumberInputState({ value: 10, onChange: (v) => console.log(v) });
20
+ *
21
+ * @example
22
+ * // 非受控模式
23
+ * const state = useNumberInputState({ defaultValue: 10, min: 0, max: 100 });
24
+ */
25
+ export declare function useNumberInputState(props: BaseNumberInputProps): NumberInputState;
@@ -6,28 +6,28 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
7
  import { useState, useCallback } from 'react';
8
8
  import { validateValue } from "../utils/validation";
9
- /**
10
- * 数值输入状态管理 Hook
11
- *
12
- * 管理组件的内部状态,包括:
13
- * - 值管理(受控/非受控模式)
14
- * - 校验状态管理
15
- * - 事件处理函数封装
16
- *
17
- * 支持受控和非受控两种模式:
18
- * - 受控模式:value 由外部传入,组件不维护内部状态
19
- * - 非受控模式:使用 defaultValue,组件维护内部状态
20
- *
21
- * @param props 组件 Props(包含校验配置)
22
- * @returns 数值输入状态对象
23
- *
24
- * @example
25
- * // 受控模式
26
- * const state = useNumberInputState({ value: 10, onChange: (v) => console.log(v) });
27
- *
28
- * @example
29
- * // 非受控模式
30
- * const state = useNumberInputState({ defaultValue: 10, min: 0, max: 100 });
9
+ /**
10
+ * 数值输入状态管理 Hook
11
+ *
12
+ * 管理组件的内部状态,包括:
13
+ * - 值管理(受控/非受控模式)
14
+ * - 校验状态管理
15
+ * - 事件处理函数封装
16
+ *
17
+ * 支持受控和非受控两种模式:
18
+ * - 受控模式:value 由外部传入,组件不维护内部状态
19
+ * - 非受控模式:使用 defaultValue,组件维护内部状态
20
+ *
21
+ * @param props 组件 Props(包含校验配置)
22
+ * @returns 数值输入状态对象
23
+ *
24
+ * @example
25
+ * // 受控模式
26
+ * const state = useNumberInputState({ value: 10, onChange: (v) => console.log(v) });
27
+ *
28
+ * @example
29
+ * // 非受控模式
30
+ * const state = useNumberInputState({ defaultValue: 10, min: 0, max: 100 });
31
31
  */
32
32
  export function useNumberInputState(props) {
33
33
  var _props$defaultValue;
@@ -55,12 +55,12 @@ export function useNumberInputState(props) {
55
55
  // 当前值(受控模式优先使用 props.value)
56
56
  var currentValue = isControlled ? props.value : innerValue;
57
57
 
58
- /**
59
- * 值变更处理函数
60
- *
61
- * 1. 更新内部状态(非受控模式)
62
- * 2. 根据 validateTrigger 决定是否立即校验
63
- * 3. 触发外部 onChange 回调
58
+ /**
59
+ * 值变更处理函数
60
+ *
61
+ * 1. 更新内部状态(非受控模式)
62
+ * 2. 根据 validateTrigger 决定是否立即校验
63
+ * 3. 触发外部 onChange 回调
64
64
  */
65
65
  var handleChange = useCallback(function (newValue) {
66
66
  var _props$onChange;
@@ -83,12 +83,12 @@ export function useNumberInputState(props) {
83
83
  (_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, newValue);
84
84
  }, [isControlled, props]);
85
85
 
86
- /**
87
- * 失焦处理函数
88
- *
89
- * 1. 标记为已触摸
90
- * 2. 执行失焦时的校验(根据 validateTrigger)
91
- * 3. 触发外部 onBlur 回调
86
+ /**
87
+ * 失焦处理函数
88
+ *
89
+ * 1. 标记为已触摸
90
+ * 2. 执行失焦时的校验(根据 validateTrigger)
91
+ * 3. 触发外部 onBlur 回调
92
92
  */
93
93
  var handleBlur = useCallback(function () {
94
94
  var _props$onBlur;
@@ -106,11 +106,11 @@ export function useNumberInputState(props) {
106
106
  (_props$onBlur = props.onBlur) === null || _props$onBlur === void 0 || _props$onBlur.call(props, currentValue !== null && currentValue !== void 0 ? currentValue : null);
107
107
  }, [currentValue, props]);
108
108
 
109
- /**
110
- * 聚焦处理函数
111
- *
112
- * 1. 标记为已触摸
113
- * 2. 触发外部 onFocus 回调
109
+ /**
110
+ * 聚焦处理函数
111
+ *
112
+ * 1. 标记为已触摸
113
+ * 2. 触发外部 onFocus 回调
114
114
  */
115
115
  var handleFocus = useCallback(function () {
116
116
  var _props$onFocus;
@@ -1,14 +1,14 @@
1
- /**
2
- * 数值输入组件公共逻辑导出
3
- *
4
- * 供以下组件使用:
5
- * - PisellNumber
6
- * - PisellCurrency
7
- * - PisellPercent
8
- * - 其他数值输入组件
9
- */
10
- export type { DisplayState, ValidationResult, NumberInputState, BaseNumberInputProps, } from './types';
11
- export { useNumberInputState } from './hooks';
12
- export { getDisplayState, formatNumber, addThousandsSeparator, formatPrecision, } from './utils';
13
- export { validateValue as validateNumberValue } from './utils';
14
- export type { NumberFormatOptions } from './utils';
1
+ /**
2
+ * 数值输入组件公共逻辑导出
3
+ *
4
+ * 供以下组件使用:
5
+ * - PisellNumber
6
+ * - PisellCurrency
7
+ * - PisellPercent
8
+ * - 其他数值输入组件
9
+ */
10
+ export type { DisplayState, ValidationResult, NumberInputState, BaseNumberInputProps, } from './types';
11
+ export { useNumberInputState } from './hooks';
12
+ export { getDisplayState, formatNumber, addThousandsSeparator, formatPrecision, } from './utils';
13
+ export { validateValue as validateNumberValue } from './utils';
14
+ export type { NumberFormatOptions } from './utils';
@@ -1,11 +1,11 @@
1
- /**
2
- * 数值输入组件公共逻辑导出
3
- *
4
- * 供以下组件使用:
5
- * - PisellNumber
6
- * - PisellCurrency
7
- * - PisellPercent
8
- * - 其他数值输入组件
1
+ /**
2
+ * 数值输入组件公共逻辑导出
3
+ *
4
+ * 供以下组件使用:
5
+ * - PisellNumber
6
+ * - PisellCurrency
7
+ * - PisellPercent
8
+ * - 其他数值输入组件
9
9
  */
10
10
 
11
11
  // 类型
@@ -1,96 +1,96 @@
1
- /**
2
- * 数值输入组件公共类型定义
3
- * 供 PisellNumber、PisellCurrency、PisellPercent 等组件使用
4
- */
5
- export type { DisplayState, ValidationResult } from '../common';
6
- /**
7
- * 数值输入状态 Hook 返回值
8
- */
9
- export interface NumberInputState {
10
- /**
11
- * 当前值
12
- */
13
- value: number | null | undefined;
14
- /**
15
- * 是否已被触摸(交互过)
16
- */
17
- isTouched: boolean;
18
- /**
19
- * 是否校验通过
20
- */
21
- isValid: boolean;
22
- /**
23
- * 错误信息数组
24
- */
25
- errors: string[];
26
- /**
27
- * 值变更处理函数
28
- */
29
- handleChange: (value: number | null) => void;
30
- /**
31
- * 失焦处理函数
32
- */
33
- handleBlur: () => void;
34
- /**
35
- * 聚焦处理函数
36
- */
37
- handleFocus: () => void;
38
- }
39
- /**
40
- * 基础数值输入 Props(供校验和状态管理使用)
41
- */
42
- export interface BaseNumberInputProps {
43
- /**
44
- * 当前值(受控)
45
- */
46
- value?: number | null;
47
- /**
48
- * 默认值(非受控)
49
- */
50
- defaultValue?: number | null;
51
- /**
52
- * 是否必填
53
- */
54
- required?: boolean;
55
- /**
56
- * 最小值
57
- */
58
- min?: number;
59
- /**
60
- * 最大值
61
- */
62
- max?: number;
63
- /**
64
- * 自定义校验函数
65
- * @param value 当前值
66
- * @returns true 表示通过,false 或错误信息字符串表示不通过
67
- */
68
- validator?: (value: number | null) => boolean | string;
69
- /**
70
- * 校验触发时机
71
- * - onChange: 输入时即时校验
72
- * - onBlur: 失焦时校验
73
- * - both: 输入和失焦时都校验
74
- */
75
- validateTrigger?: 'onChange' | 'onBlur' | 'both';
76
- /**
77
- * 自定义错误提示信息
78
- */
79
- errorMessage?: string;
80
- /**
81
- * 值变更回调
82
- */
83
- onChange?: (value: number | null) => void;
84
- /**
85
- * 失焦回调
86
- */
87
- onBlur?: (value: number | null) => void;
88
- /**
89
- * 聚焦回调
90
- */
91
- onFocus?: () => void;
92
- /**
93
- * 校验回调
94
- */
95
- onValidate?: (isValid: boolean, errors: string[]) => void;
96
- }
1
+ /**
2
+ * 数值输入组件公共类型定义
3
+ * 供 PisellNumber、PisellCurrency、PisellPercent 等组件使用
4
+ */
5
+ export type { DisplayState, ValidationResult } from '../common';
6
+ /**
7
+ * 数值输入状态 Hook 返回值
8
+ */
9
+ export interface NumberInputState {
10
+ /**
11
+ * 当前值
12
+ */
13
+ value: number | null | undefined;
14
+ /**
15
+ * 是否已被触摸(交互过)
16
+ */
17
+ isTouched: boolean;
18
+ /**
19
+ * 是否校验通过
20
+ */
21
+ isValid: boolean;
22
+ /**
23
+ * 错误信息数组
24
+ */
25
+ errors: string[];
26
+ /**
27
+ * 值变更处理函数
28
+ */
29
+ handleChange: (value: number | null) => void;
30
+ /**
31
+ * 失焦处理函数
32
+ */
33
+ handleBlur: () => void;
34
+ /**
35
+ * 聚焦处理函数
36
+ */
37
+ handleFocus: () => void;
38
+ }
39
+ /**
40
+ * 基础数值输入 Props(供校验和状态管理使用)
41
+ */
42
+ export interface BaseNumberInputProps {
43
+ /**
44
+ * 当前值(受控)
45
+ */
46
+ value?: number | null;
47
+ /**
48
+ * 默认值(非受控)
49
+ */
50
+ defaultValue?: number | null;
51
+ /**
52
+ * 是否必填
53
+ */
54
+ required?: boolean;
55
+ /**
56
+ * 最小值
57
+ */
58
+ min?: number;
59
+ /**
60
+ * 最大值
61
+ */
62
+ max?: number;
63
+ /**
64
+ * 自定义校验函数
65
+ * @param value 当前值
66
+ * @returns true 表示通过,false 或错误信息字符串表示不通过
67
+ */
68
+ validator?: (value: number | null) => boolean | string;
69
+ /**
70
+ * 校验触发时机
71
+ * - onChange: 输入时即时校验
72
+ * - onBlur: 失焦时校验
73
+ * - both: 输入和失焦时都校验
74
+ */
75
+ validateTrigger?: 'onChange' | 'onBlur' | 'both';
76
+ /**
77
+ * 自定义错误提示信息
78
+ */
79
+ errorMessage?: string;
80
+ /**
81
+ * 值变更回调
82
+ */
83
+ onChange?: (value: number | null) => void;
84
+ /**
85
+ * 失焦回调
86
+ */
87
+ onBlur?: (value: number | null) => void;
88
+ /**
89
+ * 聚焦回调
90
+ */
91
+ onFocus?: () => void;
92
+ /**
93
+ * 校验回调
94
+ */
95
+ onValidate?: (isValid: boolean, errors: string[]) => void;
96
+ }
@@ -1,53 +1,53 @@
1
- /**
2
- * 数值格式化工具函数
3
- */
4
- /**
5
- * 格式化选项
6
- */
7
- export interface NumberFormatOptions {
8
- /** 小数精度 */
9
- precision?: number;
10
- /** 是否使用千分位分隔符 */
11
- useGrouping?: boolean;
12
- /** 自定义格式化函数 */
13
- formatter?: (value: number | null) => string;
14
- }
15
- /**
16
- * 格式化数值
17
- *
18
- * @param value 数值
19
- * @param options 格式化选项
20
- * @returns 格式化后的字符串,null 时返回 null
21
- *
22
- * @example
23
- * formatNumber(1234.567, { precision: 2, useGrouping: true })
24
- * // 返回: "1,234.57"
25
- *
26
- * @example
27
- * formatNumber(1234, { precision: 0, useGrouping: true })
28
- * // 返回: "1,234"
29
- */
30
- export declare function formatNumber(value: number | null | undefined, options?: NumberFormatOptions): string | null;
31
- /**
32
- * 添加千分位分隔符
33
- *
34
- * @param value 数值
35
- * @returns 添加千分位后的字符串
36
- *
37
- * @example
38
- * addThousandsSeparator(1234567)
39
- * // 返回: "1,234,567"
40
- */
41
- export declare function addThousandsSeparator(value: number): string;
42
- /**
43
- * 格式化精度
44
- *
45
- * @param value 数值
46
- * @param precision 小数位数
47
- * @returns 格式化后的数值
48
- *
49
- * @example
50
- * formatPrecision(1.2345, 2)
51
- * // 返回: 1.23
52
- */
53
- export declare function formatPrecision(value: number, precision: number): number;
1
+ /**
2
+ * 数值格式化工具函数
3
+ */
4
+ /**
5
+ * 格式化选项
6
+ */
7
+ export interface NumberFormatOptions {
8
+ /** 小数精度 */
9
+ precision?: number;
10
+ /** 是否使用千分位分隔符 */
11
+ useGrouping?: boolean;
12
+ /** 自定义格式化函数 */
13
+ formatter?: (value: number | null) => string;
14
+ }
15
+ /**
16
+ * 格式化数值
17
+ *
18
+ * @param value 数值
19
+ * @param options 格式化选项
20
+ * @returns 格式化后的字符串,null 时返回 null
21
+ *
22
+ * @example
23
+ * formatNumber(1234.567, { precision: 2, useGrouping: true })
24
+ * // 返回: "1,234.57"
25
+ *
26
+ * @example
27
+ * formatNumber(1234, { precision: 0, useGrouping: true })
28
+ * // 返回: "1,234"
29
+ */
30
+ export declare function formatNumber(value: number | null | undefined, options?: NumberFormatOptions): string | null;
31
+ /**
32
+ * 添加千分位分隔符
33
+ *
34
+ * @param value 数值
35
+ * @returns 添加千分位后的字符串
36
+ *
37
+ * @example
38
+ * addThousandsSeparator(1234567)
39
+ * // 返回: "1,234,567"
40
+ */
41
+ export declare function addThousandsSeparator(value: number): string;
42
+ /**
43
+ * 格式化精度
44
+ *
45
+ * @param value 数值
46
+ * @param precision 小数位数
47
+ * @returns 格式化后的数值
48
+ *
49
+ * @example
50
+ * formatPrecision(1.2345, 2)
51
+ * // 返回: 1.23
52
+ */
53
+ export declare function formatPrecision(value: number, precision: number): number;
@@ -1,25 +1,25 @@
1
- /**
2
- * 数值格式化工具函数
1
+ /**
2
+ * 数值格式化工具函数
3
3
  */
4
4
 
5
- /**
6
- * 格式化选项
5
+ /**
6
+ * 格式化选项
7
7
  */
8
8
 
9
- /**
10
- * 格式化数值
11
- *
12
- * @param value 数值
13
- * @param options 格式化选项
14
- * @returns 格式化后的字符串,null 时返回 null
15
- *
16
- * @example
17
- * formatNumber(1234.567, { precision: 2, useGrouping: true })
18
- * // 返回: "1,234.57"
19
- *
20
- * @example
21
- * formatNumber(1234, { precision: 0, useGrouping: true })
22
- * // 返回: "1,234"
9
+ /**
10
+ * 格式化数值
11
+ *
12
+ * @param value 数值
13
+ * @param options 格式化选项
14
+ * @returns 格式化后的字符串,null 时返回 null
15
+ *
16
+ * @example
17
+ * formatNumber(1234.567, { precision: 2, useGrouping: true })
18
+ * // 返回: "1,234.57"
19
+ *
20
+ * @example
21
+ * formatNumber(1234, { precision: 0, useGrouping: true })
22
+ * // 返回: "1,234"
23
23
  */
24
24
  export function formatNumber(value) {
25
25
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -50,15 +50,15 @@ export function formatNumber(value) {
50
50
  return String(value);
51
51
  }
52
52
 
53
- /**
54
- * 添加千分位分隔符
55
- *
56
- * @param value 数值
57
- * @returns 添加千分位后的字符串
58
- *
59
- * @example
60
- * addThousandsSeparator(1234567)
61
- * // 返回: "1,234,567"
53
+ /**
54
+ * 添加千分位分隔符
55
+ *
56
+ * @param value 数值
57
+ * @returns 添加千分位后的字符串
58
+ *
59
+ * @example
60
+ * addThousandsSeparator(1234567)
61
+ * // 返回: "1,234,567"
62
62
  */
63
63
  export function addThousandsSeparator(value) {
64
64
  return value.toLocaleString('zh-CN', {
@@ -66,16 +66,16 @@ export function addThousandsSeparator(value) {
66
66
  });
67
67
  }
68
68
 
69
- /**
70
- * 格式化精度
71
- *
72
- * @param value 数值
73
- * @param precision 小数位数
74
- * @returns 格式化后的数值
75
- *
76
- * @example
77
- * formatPrecision(1.2345, 2)
78
- * // 返回: 1.23
69
+ /**
70
+ * 格式化精度
71
+ *
72
+ * @param value 数值
73
+ * @param precision 小数位数
74
+ * @returns 格式化后的数值
75
+ *
76
+ * @example
77
+ * formatPrecision(1.2345, 2)
78
+ * // 返回: 1.23
79
79
  */
80
80
  export function formatPrecision(value, precision) {
81
81
  return Number(value.toFixed(precision));