@dune2/tools 1.0.5 → 1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dune2/tools",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "i18n"
@@ -33,17 +33,16 @@
33
33
  "src"
34
34
  ],
35
35
  "dependencies": {
36
+ "@tanstack/react-query": "^5",
36
37
  "bignumber.js": "^9.1.2",
37
38
  "es-toolkit": "^1",
38
39
  "js-cookie": "^3.0.5",
39
- "store2": "^2.14.3"
40
+ "store2": "^2.14.3",
41
+ "valtio": "^2"
40
42
  },
41
43
  "devDependencies": {
42
- "@tanstack/react-query": "5.51.11",
43
44
  "@types/js-cookie": "3.0.3",
44
- "axios": "^1.6.8",
45
- "react": "^19",
46
- "valtio": "^2"
45
+ "react": "^19"
47
46
  },
48
47
  "publishConfig": {
49
48
  "access": "public"
@@ -1,7 +1,5 @@
1
1
  import BigNumber from "bignumber.js";
2
- import { LocalesEnum } from "../i18n/enums";
3
- import { defaultCurrencies } from "./currencies";
4
- import type { CurrencyFormat, Format } from "./shared";
2
+ import type { Format } from "./shared";
5
3
  import { RoundingMode } from "./shared";
6
4
 
7
5
  export * from "./shared";
@@ -161,68 +159,6 @@ export class Numbro {
161
159
  }
162
160
  //#endregion
163
161
 
164
- //#region currency format
165
- /**
166
- * currency format default
167
- */
168
- static locale: string = LocalesEnum.id;
169
- static setLocale(locale: string) {
170
- // check locale is valid
171
- if (!(locale in Numbro.defaultCurrencies)) {
172
- throw new Error(`在 defaultCurrencies 中,找不到 ${locale},请先检查`);
173
- }
174
- Numbro.locale = locale;
175
- }
176
-
177
- /**
178
- * 默认的货币格式化配置
179
- * key: locale
180
- * value: currency format
181
- */
182
- static defaultCurrencies = defaultCurrencies;
183
- static setDefaultCurrencies(currencies: typeof defaultCurrencies) {
184
- Numbro.defaultCurrencies = currencies;
185
- }
186
- formatCurrency(format: CurrencyFormat = {}) {
187
- // 根据语言解析出来的默认格式
188
- const defaultCurrencyFormat =
189
- Numbro.defaultCurrencies[format.locale ?? Numbro.locale];
190
-
191
- format = {
192
- ...defaultCurrencyFormat,
193
- ...format,
194
- };
195
- let {
196
- position = "prefix",
197
- symbol,
198
- spaceSeparated,
199
-
200
- ...rest
201
- } = format;
202
- // 是否强制显示正负号
203
- const sign = this.getPrefixSign(rest.forceSign);
204
-
205
- let space = spaceSeparated ? " " : "";
206
- // 在 currency format 中,需要使用绝对值来格式化
207
- // 方便后续添加 正负号
208
- rest.absoluteValue = true;
209
- rest.forceSign = false;
210
- let formattedString = this.format(rest);
211
-
212
- //#region NaN 的 fallback
213
- const { NaNFormat } = this.combineFormatOptions(rest);
214
- if (formattedString === NaNFormat) {
215
- return formattedString;
216
- }
217
- //#endregion
218
-
219
- if (position === "prefix") {
220
- return `${sign}${symbol}${space}${formattedString}`;
221
- }
222
- return `${sign}${formattedString}${space}${symbol}`;
223
- }
224
- //#endregion
225
-
226
162
  private computeAverage(num: BigNumber) {
227
163
  const powers = {
228
164
  // 1t
@@ -1,5 +1,4 @@
1
1
  import BigNumber from "bignumber.js";
2
- import { LocalesEnum } from "../i18n/enums";
3
2
 
4
3
  export interface Format extends BigNumber.Format {
5
4
  output?: "percent";
@@ -73,30 +72,6 @@ export interface Format extends BigNumber.Format {
73
72
  absoluteValue?: boolean;
74
73
  }
75
74
 
76
- export interface CurrencyFormat extends Format {
77
- /**
78
- * 货币符号
79
- */
80
- symbol?: string;
81
-
82
- /**
83
- * 货币符号位置
84
- */
85
- position?: "prefix" | "postfix";
86
-
87
- /**
88
- * 按哪种语言格式化,会根据传入的语言去 currencies 里获取对应的配置项
89
- * 一般用在以下情况:
90
- * - 当前设置的语言是 en,但是需要格式化成 id 的货币
91
- */
92
- locale?: LocalesEnum | (string & {});
93
-
94
- /**
95
- * symbol 和 数字 之间是否需要空格
96
- */
97
- spaceSeparated?: boolean;
98
- }
99
-
100
75
  /**
101
76
  * 重新导出 BigNumber.RoundingMode
102
77
  * 由于项目不会使用太多的四舍五入模式,所以只导出常用的几个
@@ -46,7 +46,7 @@ export class RequestBuilder<Req = any, Res = any> {
46
46
  * useQuery、useMutation 内部会调用这个
47
47
  * 另外也可以直接调用这个函数来发送请求
48
48
  * @param params 请求参数 默认会根据请求方法来放到 url 上或者 body 里
49
- * @param config axios 的配置,一般不需要传,内部用
49
+ * @param config 请求的配置,一般不需要传,内部用
50
50
  */
51
51
  request<P extends Req, T = Res>(params?: P, config?: RequestConfig) {
52
52
  const method = this.options.method!;
@@ -77,7 +77,7 @@ export class RequestBuilder<Req = any, Res = any> {
77
77
  * useQuery、useMutation 内部会调用这个
78
78
  * 另外也可以直接调用这个函数来发送请求
79
79
  * @param params 请求参数 默认会根据请求方法来放到 url 上或者 body 里
80
- * @param config axios 的配置,一般不需要传,内部用
80
+ * @param config 请求的配置,一般不需要传,内部用
81
81
  */
82
82
  request<P extends Req, T = Res>(params?: P, config?: RequestConfig) {
83
83
  const method = this.options.method!;
@@ -29,7 +29,7 @@ export function createApi<Req, Res>(opts: Options<Req, Res>) {
29
29
  const { requestFn, ...rest } = opts;
30
30
  const api = new RequestBuilder<Req, Res>({
31
31
  url: opts.queryKey,
32
- // 给定 get 则 在 requestFn 中可以通过 params 获取到参数,否则是 data 字段。这是为了对齐 axios 的规则
32
+ // 给定 get 则 在 requestFn 中可以通过 params 获取到参数,否则是 data 字段
33
33
  method: "get",
34
34
  requestFn: (config) => {
35
35
  return requestFn(config.params) as never;
@@ -1,23 +0,0 @@
1
- import { LocalesEnum } from "../i18n/enums";
2
- import type { CurrencyFormat } from "./shared";
3
-
4
- export const defaultCurrencies: Record<
5
- string,
6
- Omit<CurrencyFormat, "locale">
7
- > = {
8
- [LocalesEnum.en]: {
9
- symbol: "$",
10
- position: "prefix",
11
- mantissa: 2,
12
- },
13
- [LocalesEnum.id]: {
14
- symbol: "Rp",
15
- position: "prefix",
16
- mantissa: 2,
17
- },
18
- [LocalesEnum.zh]: {
19
- symbol: "¥",
20
- position: "prefix",
21
- mantissa: 2,
22
- },
23
- };