nfx-ui 0.6.2 → 0.7.1

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 (116) hide show
  1. package/dist/animations.cjs +2 -2
  2. package/dist/animations.d.ts +0 -101
  3. package/dist/animations.mjs +9 -11
  4. package/dist/apis.cjs +2 -2
  5. package/dist/apis.cjs.map +1 -1
  6. package/dist/apis.d.ts +0 -6
  7. package/dist/apis.mjs +8 -9
  8. package/dist/apis.mjs.map +1 -1
  9. package/dist/{chunk-BounceLoading-B54QEw0n.mjs → chunk-BounceLoading-C5XE8DKc.mjs} +62 -65
  10. package/dist/{chunk-BounceLoading-B54QEw0n.mjs.map → chunk-BounceLoading-C5XE8DKc.mjs.map} +1 -1
  11. package/dist/chunk-BounceLoading-CwvDT5HF.cjs +11 -0
  12. package/dist/{chunk-BounceLoading-C6n4BZVJ.cjs.map → chunk-BounceLoading-CwvDT5HF.cjs.map} +1 -1
  13. package/dist/chunk-animations-CEZ01ALd.mjs +740 -0
  14. package/dist/chunk-animations-CEZ01ALd.mjs.map +1 -0
  15. package/dist/chunk-animations-CO7zKbti.cjs +3 -0
  16. package/dist/chunk-animations-CO7zKbti.cjs.map +1 -0
  17. package/dist/chunk-i18n-BCDF-skF.cjs +3 -0
  18. package/dist/{chunk-i18n-daHSL0Nm.cjs.map → chunk-i18n-BCDF-skF.cjs.map} +1 -1
  19. package/dist/{chunk-i18n-BBPhh6MT.mjs → chunk-i18n-BsyWvA9c.mjs} +44 -69
  20. package/dist/{chunk-i18n-BBPhh6MT.mjs.map → chunk-i18n-BsyWvA9c.mjs.map} +1 -1
  21. package/dist/{chunk-types-SD4MzUGp.mjs → chunk-language-B8sfGadQ.mjs} +2 -2
  22. package/dist/chunk-language-B8sfGadQ.mjs.map +1 -0
  23. package/dist/{chunk-types-BE3JCLff.cjs → chunk-language-Bqmpuf2W.cjs} +1 -1
  24. package/dist/chunk-language-Bqmpuf2W.cjs.map +1 -0
  25. package/dist/{chunk-types-DNPBKfmx.mjs → chunk-layout-C2uqDEMJ.mjs} +2 -2
  26. package/dist/chunk-layout-C2uqDEMJ.mjs.map +1 -0
  27. package/dist/{chunk-types-C_opkZGr.cjs → chunk-layout-D728gccQ.cjs} +1 -1
  28. package/dist/chunk-layout-D728gccQ.cjs.map +1 -0
  29. package/dist/{chunk-lucide-BhgnmTNo.mjs → chunk-lucide-C54WenI6.mjs} +2 -2
  30. package/dist/{chunk-lucide-BhgnmTNo.mjs.map → chunk-lucide-C54WenI6.mjs.map} +1 -1
  31. package/dist/chunk-preference-BWEpbZgC.mjs +50 -0
  32. package/dist/{chunk-preference-By58ZcJ_.mjs.map → chunk-preference-BWEpbZgC.mjs.map} +1 -1
  33. package/dist/chunk-preference-Dbugm0iQ.cjs +3 -0
  34. package/dist/{chunk-preference-C144GkCD.cjs.map → chunk-preference-Dbugm0iQ.cjs.map} +1 -1
  35. package/dist/chunk-theme-9dcwRKw8.mjs +17 -0
  36. package/dist/chunk-theme-9dcwRKw8.mjs.map +1 -0
  37. package/dist/chunk-theme-BFvDRCYS.cjs +3 -0
  38. package/dist/chunk-theme-BFvDRCYS.cjs.map +1 -0
  39. package/dist/components.cjs +3 -3
  40. package/dist/components.cjs.map +1 -1
  41. package/dist/components.d.ts +0 -412
  42. package/dist/components.mjs +628 -642
  43. package/dist/components.mjs.map +1 -1
  44. package/dist/constants.cjs +1 -1
  45. package/dist/constants.d.ts +0 -129
  46. package/dist/constants.mjs +1 -1
  47. package/dist/events.cjs +1 -1
  48. package/dist/events.d.ts +0 -60
  49. package/dist/events.mjs +1 -1
  50. package/dist/hooks.cjs +1 -1
  51. package/dist/hooks.d.ts +0 -315
  52. package/dist/hooks.mjs +1 -1
  53. package/dist/icons.cjs +2 -2
  54. package/dist/icons.d.ts +0 -217
  55. package/dist/icons.mjs +2 -2
  56. package/dist/languages.cjs +2 -2
  57. package/dist/languages.cjs.map +1 -1
  58. package/dist/languages.d.ts +0 -178
  59. package/dist/languages.mjs +4 -4
  60. package/dist/languages.mjs.map +1 -1
  61. package/dist/layouts.cjs +2 -2
  62. package/dist/layouts.cjs.map +1 -1
  63. package/dist/layouts.d.ts +0 -208
  64. package/dist/layouts.mjs +201 -210
  65. package/dist/layouts.mjs.map +1 -1
  66. package/dist/navigations.cjs +1 -1
  67. package/dist/navigations.d.ts +0 -71
  68. package/dist/navigations.mjs +1 -1
  69. package/dist/pixel-blast.cjs +192 -0
  70. package/dist/pixel-blast.cjs.map +1 -0
  71. package/dist/pixel-blast.d.ts +1 -0
  72. package/dist/pixel-blast.mjs +506 -0
  73. package/dist/pixel-blast.mjs.map +1 -0
  74. package/dist/preference.cjs +2 -2
  75. package/dist/preference.d.ts +0 -95
  76. package/dist/preference.mjs +8 -11
  77. package/dist/services.cjs +2 -2
  78. package/dist/services.cjs.map +1 -1
  79. package/dist/services.d.ts +0 -7
  80. package/dist/services.mjs +9 -10
  81. package/dist/services.mjs.map +1 -1
  82. package/dist/stores.cjs +2 -2
  83. package/dist/stores.cjs.map +1 -1
  84. package/dist/stores.d.ts +1 -101
  85. package/dist/stores.mjs +53 -53
  86. package/dist/stores.mjs.map +1 -1
  87. package/dist/themes.cjs +2 -2
  88. package/dist/themes.cjs.map +1 -1
  89. package/dist/themes.d.ts +0 -232
  90. package/dist/themes.mjs +888 -721
  91. package/dist/themes.mjs.map +1 -1
  92. package/dist/types.cjs +1 -1
  93. package/dist/types.d.ts +0 -180
  94. package/dist/types.mjs +1 -1
  95. package/dist/utils.cjs +2 -2
  96. package/dist/utils.cjs.map +1 -1
  97. package/dist/utils.d.ts +0 -485
  98. package/dist/utils.mjs +143 -156
  99. package/dist/utils.mjs.map +1 -1
  100. package/package.json +45 -29
  101. package/dist/chunk-BounceLoading-C6n4BZVJ.cjs +0 -11
  102. package/dist/chunk-animations-Brp-bsaE.mjs +0 -1243
  103. package/dist/chunk-animations-Brp-bsaE.mjs.map +0 -1
  104. package/dist/chunk-animations-e2F3zuP9.cjs +0 -190
  105. package/dist/chunk-animations-e2F3zuP9.cjs.map +0 -1
  106. package/dist/chunk-i18n-daHSL0Nm.cjs +0 -3
  107. package/dist/chunk-preference-By58ZcJ_.mjs +0 -51
  108. package/dist/chunk-preference-C144GkCD.cjs +0 -3
  109. package/dist/chunk-types-BE3JCLff.cjs.map +0 -1
  110. package/dist/chunk-types-BNUlgEkq.cjs +0 -3
  111. package/dist/chunk-types-BNUlgEkq.cjs.map +0 -1
  112. package/dist/chunk-types-BudGuDCK.mjs +0 -20
  113. package/dist/chunk-types-BudGuDCK.mjs.map +0 -1
  114. package/dist/chunk-types-C_opkZGr.cjs.map +0 -1
  115. package/dist/chunk-types-DNPBKfmx.mjs.map +0 -1
  116. package/dist/chunk-types-SD4MzUGp.mjs.map +0 -1
package/dist/utils.d.ts CHANGED
@@ -1,486 +1 @@
1
- import { Options } from 'async-retry';
2
-
3
- /** 错误响应。Error response. */
4
- declare interface ApiErrorBody {
5
- /** 状态码。Status code. */
6
- status?: number;
7
- /** 错误码。Error code. */
8
- errCode?: string;
9
- /** 消息。Message. */
10
- message?: string;
11
- /** 详情。Details. */
12
- details?: unknown;
13
- /** 追踪 ID。Trace ID. */
14
- traceId?: string;
15
- }
16
-
17
- /**
18
- * 数组类型。Array type.
19
- * @example Array<string> => string[]
20
- */
21
- declare type Array_2<T> = T[];
22
-
23
- /** 可实例化的构造函数类型。Instantiable constructor type. */
24
- declare type Constructor<T extends object = object> = new (...args: unknown[]) => T;
25
-
26
- /**
27
- * 从字符串列表创建键值映射对象;可选 valueMapper 指定值
28
- * Create record from string list; optional valueMapper for values.
29
- * @param list - 字符串数组(作为键)
30
- * @param valueMapper - 可选,(item, index) => value,缺省时值为键本身
31
- * @returns Record<list[number], V>
32
- * @example createMap(["a","b","c"]) // { a: "a", b: "b", c: "c" }
33
- * @example createMap(["a","b","c"], (_, i) => i) // { a: 0, b: 1, c: 2 }
34
- */
35
- export declare function createMap<T extends string, V = T>(list: ReadonlyArray<T>, valueMapper?: (item: T, index: number) => V): Record<T, V>;
36
-
37
- /**
38
- * 可为 null、undefined 或空字符串。Emptyable: T | null | undefined | "".
39
- * @example Emptyable<string> => string | null | undefined | ""
40
- */
41
- declare type Emptyable<T> = T | null | undefined | "";
42
-
43
- /**
44
- * 构造失败结果(非 Error 会包装为 Error)。Create a failed result; non-Error wrapped in Error.
45
- * @param e - 错误或任意值。Error or any value.
46
- * @returns [null, Error]
47
- * @example err(new Error("fail")) // [null, Error]
48
- */
49
- export declare const err: (e: unknown) => Result<never>;
50
-
51
- /**
52
- * 格式化日期仅年月日 (YYYY/MM/DD),用于生日等
53
- * Format date as year/month/day only.
54
- * @param dateString - 日期字符串,如 "2000-01-15" 或 ISO
55
- * @returns 格式化后的日期字符串,无效则返回原串
56
- */
57
- export declare const formatDate: (dateString: string) => string;
58
-
59
- /**
60
- * 格式化时间显示年月日时分 (YYYY/MM/DD HH:mm)
61
- * Format date-time as year/month/day hour:minute.
62
- * @param dateString - 时间字符串
63
- * @returns 格式化后的时间字符串,无效则返回原串
64
- */
65
- export declare const formatDateTime: (dateString: string) => string;
66
-
67
- /**
68
- * 格式化日期为 YYYY/MM/DD(空或无效返回 "")
69
- * Format date as YYYY/MM/DD; empty or invalid returns "".
70
- * @param dateString - 日期字符串
71
- * @returns 格式化后的日期字符串,无效则 ""
72
- */
73
- export declare const formatDisplayDate: (dateString: string | undefined | null) => string;
74
-
75
- /**
76
- * 格式化时间显示月日时分 (MM/DD HH:mm)
77
- * Format date-time as month/day hour:minute.
78
- * @param dateString - 时间字符串
79
- * @returns 格式化后的时间字符串,无效则返回原串
80
- */
81
- export declare const formatMonthDayTime: (dateString: string) => string;
82
-
83
- /**
84
- * 数字缩写显示(如 1.2k+、3.5M+、1.1B+)
85
- * Format number to abbreviated string (e.g. 1.2k+, 3.5M+, 1.1B+).
86
- * @param num - 数字
87
- * @returns 缩写字符串
88
- */
89
- export declare function formatNumberAbbreviated(num: number): string;
90
-
91
- /**
92
- * 格式化为相对时间(如 2 days ago, 3 months ago)
93
- * Format as relative time (e.g. 2 days ago, 3 months ago).
94
- * @param dateString - 日期字符串
95
- * @returns 相对时间字符串,无效为 "Invalid date",空为 "Unknown"
96
- */
97
- export declare const formatRelativeTime: (dateString: string | undefined | null) => string;
98
-
99
- /**
100
- * 格式化 ISO 日期为图表轴/提示用短格式(如:Jan 4, 02:30 PM)
101
- * Format ISO date for chart axis/tooltip (e.g. Jan 4, 02:30 PM).
102
- * @param iso - ISO 日期字符串
103
- * @returns 格式化字符串,解析失败则返回原串
104
- */
105
- export declare function formatTickDate(iso: string): string;
106
-
107
- /**
108
- * 格式化时间显示时分 (HH:mm)
109
- * Format time as hour:minute.
110
- * @param dateString - 时间字符串
111
- * @returns 格式化后的时间字符串,无效则返回原串
112
- */
113
- export declare const formatTime: (dateString: string) => string;
114
-
115
- /**
116
- * 仅当为后端错误(有 response.data)时解析为 ApiErrorBody,否则返回 null
117
- * Parse to ApiErrorBody only when response.data exists; otherwise null.
118
- * @param error - 通常为 Axios 错误或 unknown
119
- * @returns ApiErrorBody 或 null
120
- */
121
- export declare function getApiError(error: unknown): ApiErrorBody | null;
122
-
123
- /**
124
- * UI 展示用错误文案:优先 i18n errors 命名空间(errCode),其次 api.message,最后 fallback
125
- * Get display message: i18n errors namespace (by errCode) → api.message → fallback.
126
- * @param error - 通常为 Axios 错误
127
- * @param fallback - 无法解析时的默认文案
128
- * @returns 展示用字符串
129
- */
130
- export declare function getApiErrorMessage(error: unknown, fallback: string): string;
131
-
132
- /**
133
- * 从电话号码解析国家/地区码(基于 google-libphonenumber)
134
- * Get country code from phone number (google-libphonenumber).
135
- * @param phoneNumber - 电话号码字符串
136
- * @returns 国家码数字
137
- */
138
- export declare const getCountryCode: (phoneNumber: string) => number;
139
-
140
- export declare function getItem(key: string): Nilable<string>;
141
-
142
- /**
143
- * 将 HEX 颜色转换为 RGBA
144
- * @param hex - HEX 颜色字符串,格式: "#RRGGBB" 或 "#RGB"
145
- * @param alpha - 透明度,范围 0-1
146
- * @returns RGBA 颜色字符串,格式: "rgba(r, g, b, alpha)"
147
- *
148
- * @example
149
- * hexToRGBA("#FA1E16", 0.3) // "rgba(250, 30, 22, 0.3)"
150
- */
151
- export declare const hexToRGBA: (hex: string, alpha: number) => string;
152
-
153
- /**
154
- * 在两色之间按 factor 线性插值(支持 hex / rgb)
155
- * Linear color interpolation between start and end by factor (0–1); supports hex and rgb.
156
- * @param start - 起始颜色
157
- * @param end - 结束颜色
158
- * @param factor - 插值系数 0–1
159
- * @returns rgb(r, g, b) 字符串
160
- */
161
- export declare const interpolateColor: (start: string, end: string, factor: number) => string;
162
-
163
- /**
164
- * 校验邮箱格式是否有效(简单正则:含 @ 与点)
165
- * Check if email format is valid (simple regex: contains @ and dot).
166
- * @param email - 待校验的邮箱字符串
167
- * @returns 是否有效
168
- */
169
- export declare const isValidEmail: (email: string) => boolean;
170
-
171
- /**
172
- * 校验电话号码是否有效(基于 google-libphonenumber)
173
- * Check if phone number is valid (google-libphonenumber).
174
- * @param phoneNumber - 电话号码字符串
175
- * @returns 是否有效
176
- */
177
- export declare const isValidPhoneNumber: (phoneNumber: string) => boolean;
178
-
179
- /**
180
- * 可为 undefined。Maybe: T | undefined.
181
- * @example Maybe<number> => number | undefined
182
- */
183
- declare type Maybe<T> = T | undefined;
184
-
185
- /**
186
- * 按 id 将 items 合并进数组:insert 仅插入新 id,upsert 覆盖同 id 并插入新 id;可 prepend 或 append
187
- * Merge items into array by id: insert = only new ids, upsert = overwrite same id + insert new; place = prepend | append.
188
- * @param arr - 原数组
189
- * @param items - 待合并项
190
- * @param idOf - 取 id 的函数
191
- * @param place - 新项插入位置
192
- * @param mode - insert 不覆盖已有 id;upsert 覆盖同 id
193
- * @returns 合并后的新数组
194
- */
195
- export declare function mergeById<T>(arr: Array_2<T>, items: Array_2<T>, idOf: (x: T) => string, place: "prepend" | "append", mode: "insert" | "upsert"): Array_2<T>;
196
-
197
- /**
198
- * 可为 null 或 undefined。Nilable: T | null | undefined.
199
- * @example Nilable<boolean> => boolean | null | undefined
200
- */
201
- declare type Nilable<T> = T | null | undefined;
202
-
203
- /**
204
- * 可为 null 或 undefined。Nilable: T | null | undefined.
205
- * @example Nilable<boolean> => boolean | null | undefined
206
- */
207
- declare type Nilable_2<T> = T | null | undefined;
208
-
209
- /**
210
- * 规范化地址字符串:去除首尾空白并将连续空白合并为单个空格
211
- * Normalize address string: trim and collapse consecutive spaces to one.
212
- * @param address - 原始地址字符串
213
- * @returns 规范化后的地址
214
- */
215
- export declare function normalizeAddress(address: string): string;
216
-
217
- /**
218
- * 可为 null。Nullable: T | null.
219
- * @example Nullable<string> => string | null
220
- */
221
- declare type Nullable<T> = T | null;
222
-
223
- /**
224
- * 构造成功结果。Create a successful result.
225
- * @param v - 结果值。Result value.
226
- * @returns [v, null]
227
- * @example ok(42) // [42, null]
228
- */
229
- export declare const ok: <T>(v: T) => Result<T>;
230
-
231
- /**
232
- * 从对象中剔除指定键,返回新对象(不修改原对象)
233
- * Omit specified keys from object and return a new object.
234
- * @param obj - 源对象
235
- * @param keys - 要剔除的键(数组或单个键,可再接多个键)
236
- * @returns 剔除后的新对象
237
- * @example omit({ a: 1, b: 2, c: 3 }, ['a', 'c']) // { b: 2 }
238
- * @example omit({ a: 1, b: 2, c: 3 }, 'a', 'b') // { c: 3 }
239
- */
240
- export declare function omit<Obj extends object, Key extends keyof Obj>(obj: Obj, keys: Key[] | Key, ...restKeys: Key[]): Omit<Obj, Key>;
241
-
242
- /**
243
- * 包装为「仅执行一次」的异步函数(重复调用返回同一 Promise)。
244
- * Wrap async function so it runs only once; repeated calls return the same promise.
245
- * @param fn - 要执行的异步函数。Async function to run once.
246
- * @returns 包装后的函数,多次调用只执行一次。Wrapped function; only first call runs.
247
- * @example const loadOnce = onceAsync(() => fetch("/api/config")); loadOnce(); loadOnce(); // 只请求一次
248
- */
249
- export declare function onceAsync<T, Args extends unknown[]>(fn: (...args: Args) => Promise<T>): (...args: Args) => Promise<T>;
250
-
251
- /**
252
- * 按 key 仅执行一次的异步函数(同一 key 重复调用返回同一 Promise)。
253
- * Async function that runs only once per key; same key returns same promise.
254
- * @param fn - 要执行的异步函数。Async function to run.
255
- * @param keyExtractor - 从参数中提取 key 的函数。Function to extract key from args.
256
- * @returns 包装后的函数。Wrapped function.
257
- * @example const fetchUser = onceAsyncByKey((id: string) => api.getUser(id), (id) => id); fetchUser("1"); fetchUser("1"); // 同 id 只请求一次
258
- */
259
- export declare function onceAsyncByKey<T, Args extends unknown[]>(fn: (...args: Args) => Promise<T>, keyExtractor: (...args: Args) => string): (...args: Args) => Promise<T>;
260
-
261
- /**
262
- * 轮询直到 isOK(data) 为 true(内部用 withRetryResult 重试)。
263
- * Poll until fetcher returns data that satisfies isOK; uses withRetryResult.
264
- * @param fetcher - 拉取数据的函数。Function that fetches data.
265
- * @param isOK - 判断数据是否满足条件。Predicate to check if data is OK.
266
- * @param opts - 重试选项。Retry options.
267
- * @returns Promise<Result<T>>
268
- * @example const [job] = await pollUntil(() => getJob(id), (j) => j.status === "done", { retries: 10 });
269
- */
270
- export declare function pollUntil<T>(fetcher: () => Promise<T>, isOK: (data: T) => boolean, opts?: WithRetryOptions): Promise<Result<T>>;
271
-
272
- /**
273
- * 从数组中移除 id 在集合 ids 中的项,返回新数组
274
- * Remove elements whose id is in the given set; return new array.
275
- * @param arr - 原数组
276
- * @param ids - 要移除的 id 集合
277
- * @param idOf - 取 id 的函数
278
- * @returns 若无变化返回原数组,否则返回新数组
279
- */
280
- export declare function pruneArray<T>(arr: Array_2<T>, ids: ReadonlySet<string>, idOf: (x: T) => string): Array_2<T>;
281
-
282
- export declare function removeItem(key: string): void;
283
-
284
- /**
285
- * 结果类型:成功为 [T, null],失败为 [null, Error]。
286
- * Result type: success [T, null], failure [null, Error].
287
- * @template T - 成功时的值类型。Value type on success.
288
- * @example const [data, err] = await withRetryResult(() => fetchData()); if (err) return; use(data);
289
- */
290
- export declare type Result<T> = [T, null] | [null, Error];
291
-
292
- /**
293
- * 将 RGB 颜色转换为 RGBA
294
- * @param rgb - RGB 颜色字符串,格式: "rgb(r, g, b)"
295
- * @param alpha - 透明度,范围 0-1
296
- * @returns RGBA 颜色字符串,格式: "rgba(r, g, b, alpha)"
297
- *
298
- * @example
299
- * rgbToRgba("rgb(250, 30, 22)", 0.3) // "rgba(250, 30, 22, 0.3)"
300
- */
301
- export declare const rgbToRgba: (rgb: string, alpha: number) => string;
302
-
303
- /**
304
- * 将 Nilable 数组规范为数组:null/undefined 转为 [] 或 defaultValue。返回类型 Array&lt;T&gt;(即 T[])。
305
- * Normalize Nilable array to array: null/undefined to [] or defaultValue. Returns Array&lt;T&gt; (i.e. T[]).
306
- * @param value - 可能为 null 或 undefined 的数组 (array that may be null or undefined)
307
- * @param defaultValue - 可选,当 value 为 null/undefined 时使用;缺省为 [] (optional default when value is null/undefined; default is [])
308
- * @returns value ?? defaultValue ?? [] (never null/undefined)
309
- * @example safeArray(product.tags) // product.tags ?? []
310
- * @example safeArray(product.tags, ['default'])
311
- */
312
- export declare function safeArray<T>(value: Nilable_2<Array_2<T>>, defaultValue?: Array_2<T>): Array_2<T>;
313
-
314
- /**
315
- * 将 Nilable 规范为 Maybe:null 转为 undefined,undefined 与 T 原样返回。返回类型 Maybe&lt;T&gt;。等同 value ?? undefined。
316
- * Normalize Nilable to Maybe: convert null to undefined; undefined and T unchanged. Returns Maybe&lt;T&gt;. Same as value ?? undefined.
317
- * @param value - 可能为 null 或 undefined 的值 (value that may be null or undefined)
318
- * @returns 若为 null 或 undefined 则 undefined,否则原值 (undefined if null/undefined, otherwise value)
319
- * @example safeMaybe(product.price) // 代替 product.price ?? undefined
320
- */
321
- export declare function safeMaybe<T>(value: Nilable_2<T>): Maybe<T>;
322
-
323
- /**
324
- * 将 Emptyable 字符串规范为 Nilable:空字符串转为 undefined,null/undefined/非空串原样。返回类型 Nilable&lt;T&gt;。常用于表单、接口字段。
325
- * Normalize Emptyable string to Nilable: "" to undefined; null, undefined, non-empty string unchanged. Returns Nilable&lt;T&gt;. For form/API fields.
326
- * @param value - 可能为 null、undefined 或空字符串 (value that may be null, undefined or "")
327
- * @returns 若为 "" 则 undefined,否则原值 (undefined if "", otherwise value)
328
- * @example safeNilable(product.remark) // "" 也视为「无值」
329
- */
330
- export declare function safeNilable<T extends string>(value: Emptyable<T>): Nilable_2<T>;
331
-
332
- /**
333
- * 将 Nilable 规范为 Nullable:undefined 转为 null,null 与 T 原样返回。返回类型 Nullable&lt;T&gt;。
334
- * Normalize Nilable to Nullable: convert undefined to null; null and T unchanged. Returns Nullable&lt;T&gt;.
335
- * @param value - 可能为 null 或 undefined 的值 (value that may be null or undefined)
336
- * @returns 若为 undefined 则 null,否则原值 (null if undefined, otherwise value)
337
- * @example safeNullable(apiResponse.data) // undefined → null,便于区分「未设置」与「空」
338
- */
339
- export declare function safeNullable<T>(value: Nilable_2<T>): Nullable<T>;
340
-
341
- /**
342
- * 安全取数字:null/undefined/NaN 转为 undefined,合法数字原样。返回类型 Maybe&lt;number&gt;。
343
- * Safe number: null/undefined/NaN to undefined; valid number unchanged. Returns Maybe&lt;number&gt;.
344
- * @param value - 可能为 null、undefined 或非数字 (value that may be null, undefined or NaN)
345
- * @returns 若为 null、undefined 或 NaN 则 undefined,否则数字 (undefined if null/undefined/NaN, otherwise number)
346
- * @example safeNum(product.price) // 用于严格「有值才用」的场景
347
- */
348
- export declare function safeNum(value: Nilable_2<number>): Maybe<number>;
349
-
350
- /**
351
- * 若值为 null/undefined 则返回默认值,否则返回原值。等同 value ?? defaultValue。
352
- * Return defaultValue when value is null/undefined, otherwise value. Same as value ?? defaultValue.
353
- * @param value - 可能为 null 或 undefined 的值 (value that may be null or undefined)
354
- * @param defaultValue - 默认值 (default value)
355
- * @returns value ?? defaultValue
356
- * @example safeOr(product.stock, 0)
357
- * @example safeOr(product.name, '')
358
- */
359
- export declare function safeOr<T, D>(value: Nilable_2<T>, defaultValue: D): T | D;
360
-
361
- /**
362
- * 将 Emptyable 字符串规范为 Stringable:null/undefined/"" 转为 ""。返回类型 Stringable&lt;string&gt;(即 string,"" 为兜底)。
363
- * Normalize Emptyable string to Stringable: null/undefined/"" to "". Returns Stringable&lt;string&gt; (string with "" as fallback).
364
- * @param value - 可能为 null、undefined 或空字符串 (value that may be null, undefined or "")
365
- * @returns 若为 null、undefined 或 "" 则 "",否则原值 ("" if null/undefined/"", otherwise value)
366
- * @example safeStringable(product.name) // 代替 product.name ?? ""
367
- */
368
- export declare function safeStringable<T extends string>(value: Emptyable<T>): Stringable<T>;
369
-
370
- /**
371
- * 将 Nilable 数值规范为 Zeroable:null/undefined 转为 0。返回类型 Zeroable&lt;number&gt;(即 number,0 为兜底)。
372
- * Normalize Nilable number to Zeroable: null/undefined to 0. Returns Zeroable&lt;number&gt; (number with 0 as fallback).
373
- * @param value - 可能为 null 或 undefined 的数值 (number that may be null or undefined)
374
- * @returns value ?? 0 (never null/undefined)
375
- * @example safeZeroable(product.stock) // 代替 product.stock ?? 0
376
- */
377
- export declare function safeZeroable(value: Nilable_2<number>): Zeroable<number>;
378
-
379
- export declare function setItem(key: string, value: string): void;
380
-
381
- /**
382
- * 单例工厂:将传入的构造函数包装为单例模式;Proxy 拦截 construct,多次 new 返回同一实例。
383
- * Singleton factory: wrap constructor so that multiple new calls return the same instance.
384
- *
385
- * @template T - 实例类型(需为 object)。Instance type (must be object).
386
- * @param className - 被包装的构造函数(class)。Constructor (class) to wrap.
387
- * @returns 代理后的构造函数,调用时始终返回同一实例。Proxied constructor returning same instance.
388
- *
389
- * @example
390
- * ```ts
391
- * class MyService { ... }
392
- * const SingletonService = singleton(MyService);
393
- * const a = new SingletonService();
394
- * const b = new SingletonService();
395
- * console.log(a === b); // true
396
- * ```
397
- */
398
- export declare const singleton: <T extends object>(className: Constructor<T>) => Constructor<T>;
399
-
400
- /**
401
- * 可为空字符串的类型。Stringable: T | "",T 为 string 子类型。
402
- * @example Stringable<string> => string | ""
403
- */
404
- declare type Stringable<T extends string> = T | "";
405
-
406
- /**
407
- * 若值为 null/undefined 则抛出 Promise 使 React Suspense 挂起,否则返回该值。
408
- * If value is null/undefined, throw a promise to suspend (React Suspense); otherwise return value.
409
- * @param value - 待检查的值。Value to check.
410
- * @param delay - 重试前的延迟(毫秒)。Delay in ms before retry.
411
- * @returns 非空时的 value。Value when non-null.
412
- * @example const data = suspenseIfNull(resource); // 在 Suspense 边界内,data 非空时才渲染
413
- */
414
- export declare function suspenseIfNull<T>(value: Nilable_2<T>, delay?: number): T;
415
-
416
- /**
417
- * 显示价格 → 数据库价格(分)。用于提交到后端、保存草稿等
418
- * Display price to database price (cents). For submit/save.
419
- * @param displayPrice - 展示用价格(元)
420
- * @returns 数据库存储价格(分)
421
- */
422
- export declare function toDatabasePrice(displayPrice: number): number;
423
-
424
- /**
425
- * 数据库价格(分)→ 显示价格字符串(两位小数)
426
- * Database price (cents) to display string (2 decimal places).
427
- * @param databasePrice - 数据库价格(分)
428
- * @returns 如 "12.34"
429
- */
430
- export declare function toDisplayPrice(databasePrice: number): string;
431
-
432
- /**
433
- * 数据库价格(分)→ 显示价格数字。用于表单、计算等
434
- * Database price (cents) to display number.
435
- * @param databasePrice - 数据库价格(分)
436
- * @returns 数字(元)
437
- */
438
- export declare function toDisplayPriceNumber(databasePrice: number): number;
439
-
440
- /**
441
- * 将任意值转为数字输入框可用的字符串(用于表单回显)
442
- * Convert any value to a string suitable for number input (e.g. form display).
443
- * @param value - 任意值
444
- * @returns 字符串;null/undefined → "";非有限数字 → "";数组取首项
445
- */
446
- export declare function toNumberInputValue(value: unknown): string;
447
-
448
- /**
449
- * 将任意颜色统一为指定透明度的 RGBA(rgb/rgba/hex 均用新 alpha 覆盖)
450
- * Convert any color to RGBA with given alpha (overwrites existing alpha).
451
- * @param color - rgb / rgba / hex 字符串
452
- * @param alpha - 透明度 0–1
453
- * @returns rgba(r, g, b, alpha) 字符串
454
- */
455
- export declare const toRgbaWithAlpha: (color: string, alpha: number) => string;
456
-
457
- /**
458
- * 将任意值转为文本输入框可用的字符串(用于表单回显)
459
- * Convert any value to a string suitable for text input (e.g. form display).
460
- * @param value - 任意值
461
- * @returns 字符串;null/undefined → "";数组 → 逗号拼接;对象 → JSON 字符串
462
- */
463
- export declare function toTextInputValue(value: unknown): string;
464
-
465
- export declare type WithRetryOptions = Options & {
466
- /** 若返回 true 则不再重试,直接 bail。If true, do not retry and bail. */
467
- isNonRetryable?: (e: Error) => boolean;
468
- };
469
-
470
- /**
471
- * 带重试执行异步函数,成功返回 ok(value),失败返回 err(error)。
472
- * Retry async function until success or max attempts; returns Result.
473
- * @param fn - 可接收 bail 与 attempt 的异步函数。Async function receiving bail and attempt.
474
- * @param opts - async-retry 选项及 isNonRetryable。async-retry options and isNonRetryable.
475
- * @returns Promise<Result<T>>
476
- * @example const [data, err] = await withRetryResult(() => fetchData(), { retries: 3 });
477
- */
478
- export declare function withRetryResult<T>(fn: (bail: (e: Error) => void, attempt: number) => Promise<T>, opts?: WithRetryOptions): Promise<Result<T>>;
479
-
480
- /**
481
- * 可为 0 的数值类型。Zeroable: T | 0,T 为 number 子类型。
482
- * @example Zeroable<number> => number | 0
483
- */
484
- declare type Zeroable<T extends number> = T | 0;
485
-
486
1
  export { }