@fast-china/utils 2.1.10 → 2.1.11
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/CHANGELOG.md +22 -0
- package/README.md +5 -2
- package/README.zh.md +5 -2
- package/dist/array/index.mjs +21 -21
- package/dist/array/index.mjs.map +1 -1
- package/dist/async/index.mjs +32 -32
- package/dist/async/index.mjs.map +1 -1
- package/dist/base64/index.mjs +44 -51
- package/dist/base64/index.mjs.map +1 -1
- package/dist/color/index.mjs +33 -33
- package/dist/color/index.mjs.map +1 -1
- package/dist/crypto/index.mjs +153 -155
- package/dist/crypto/index.mjs.map +1 -1
- package/dist/date/index.mjs +79 -46
- package/dist/date/index.mjs.map +1 -1
- package/dist/dom/style.mjs +7 -7
- package/dist/dom/style.mjs.map +1 -1
- package/dist/env/index.mjs +9 -14
- package/dist/env/index.mjs.map +1 -1
- package/dist/function/index.mjs +4 -4
- package/dist/function/index.mjs.map +1 -1
- package/dist/identity/index.mjs +7 -7
- package/dist/identity/index.mjs.map +1 -1
- package/dist/index.d.mts +371 -366
- package/dist/index.global.min.js +2 -2
- package/dist/index.global.min.js.map +1 -1
- package/dist/internal/text.mjs +70 -26
- package/dist/internal/text.mjs.map +1 -1
- package/dist/logger/index.mjs +12 -13
- package/dist/logger/index.mjs.map +1 -1
- package/dist/number/index.mjs +63 -42
- package/dist/number/index.mjs.map +1 -1
- package/dist/object/index.mjs +32 -31
- package/dist/object/index.mjs.map +1 -1
- package/dist/storage/index.mjs +58 -63
- package/dist/storage/index.mjs.map +1 -1
- package/dist/string/index.mjs +60 -64
- package/dist/string/index.mjs.map +1 -1
- package/dist/vue/breakpoints.mjs +14 -10
- package/dist/vue/breakpoints.mjs.map +1 -1
- package/dist/vue/element-size.mjs +4 -4
- package/dist/vue/element-size.mjs.map +1 -1
- package/dist/vue/emits.mjs +7 -7
- package/dist/vue/emits.mjs.map +1 -1
- package/dist/vue/event-listener.mjs +5 -5
- package/dist/vue/event-listener.mjs.map +1 -1
- package/dist/vue/expose.mjs +3 -3
- package/dist/vue/expose.mjs.map +1 -1
- package/dist/vue/func.mjs +2 -2
- package/dist/vue/func.mjs.map +1 -1
- package/dist/vue/install.mjs +24 -24
- package/dist/vue/install.mjs.map +1 -1
- package/dist/vue/now.mjs +4 -5
- package/dist/vue/now.mjs.map +1 -1
- package/dist/vue/props.mjs +5 -5
- package/dist/vue/props.mjs.map +1 -1
- package/dist/vue/render.mjs +2 -2
- package/dist/vue/render.mjs.map +1 -1
- package/dist/vue/resize-observer.mjs +4 -6
- package/dist/vue/resize-observer.mjs.map +1 -1
- package/dist/vue/slots.mjs.map +1 -1
- package/dist/vue/transition.mjs +5 -7
- package/dist/vue/transition.mjs.map +1 -1
- package/dist/vue/window-size.mjs +2 -4
- package/dist/vue/window-size.mjs.map +1 -1
- package/dist/vue/with.mjs +1 -1
- package/dist/vue/with.mjs.map +1 -1
- package/package.json +2 -1
- package/dist/internal/runtime.mjs +0 -32
- package/dist/internal/runtime.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { App, ComputedRef, MaybeRefOrGetter, PropType, ShallowRef, SlotsType, VNode } from "vue";
|
|
2
2
|
//#region src/array/index.d.ts
|
|
3
|
-
/**
|
|
3
|
+
/** 从数组项中提取可比较键的函数 */
|
|
4
4
|
export type KeySelector<Item, Key> = (item: Item, index: number) => Key;
|
|
5
5
|
/**
|
|
6
6
|
* 将只读数组按固定大小分组。
|
|
7
7
|
*
|
|
8
|
-
* @typeParam Item -
|
|
9
|
-
* @param items -
|
|
8
|
+
* @typeParam Item - 数组项类型
|
|
9
|
+
* @param items - 不会被修改的输入数组
|
|
10
10
|
* @param size - 每组最多包含的项目数,必须是正安全整数。
|
|
11
11
|
* @returns 新建的二维数组;最后一组可能小于 `size`。
|
|
12
12
|
* @throws `RangeError` 当 `size` 不是正安全整数。
|
|
@@ -15,69 +15,69 @@ export declare function chunk<Item>(items: readonly Item[], size: number): Item[
|
|
|
15
15
|
/**
|
|
16
16
|
* 删除数组中的 `null` 与 `undefined`,保留 `false`、`0` 和空字符串。
|
|
17
17
|
*
|
|
18
|
-
* @param items -
|
|
19
|
-
* @returns
|
|
18
|
+
* @param items - 可包含空值的只读数组
|
|
19
|
+
* @returns 保持原顺序的新数组
|
|
20
20
|
*/
|
|
21
21
|
export declare function removeNullishValues<Item>(items: readonly (Item | null | undefined)[]): Item[];
|
|
22
22
|
/**
|
|
23
23
|
* 使用 JavaScript `Set` 的 SameValueZero 语义去重。
|
|
24
24
|
*
|
|
25
|
-
* @param items -
|
|
25
|
+
* @param items - 不会被修改的输入数组
|
|
26
26
|
* @returns 保留每个值首次出现顺序的新数组;稀疏数组空位被忽略。
|
|
27
27
|
*/
|
|
28
28
|
export declare function unique<Item>(items: readonly Item[]): Item[];
|
|
29
29
|
/**
|
|
30
30
|
* 按选择器返回的键去重。
|
|
31
31
|
*
|
|
32
|
-
* @param items -
|
|
33
|
-
* @param selectKey -
|
|
32
|
+
* @param items - 不会被修改的输入数组
|
|
33
|
+
* @param selectKey - 接收项目与索引并返回去重键的函数
|
|
34
34
|
* @returns 保留每个键首次出现项目的新数组;稀疏数组空位被忽略。
|
|
35
35
|
*/
|
|
36
36
|
export declare function uniqueBy<Item, Key>(items: readonly Item[], selectKey: KeySelector<Item, Key>): Item[];
|
|
37
37
|
/**
|
|
38
38
|
* 按选择器结果分组。
|
|
39
39
|
*
|
|
40
|
-
* @param items -
|
|
41
|
-
* @param selectKey - 返回任意 `Map`
|
|
40
|
+
* @param items - 不会被修改的输入数组
|
|
41
|
+
* @param selectKey - 返回任意 `Map` 键的函数
|
|
42
42
|
* @returns 按键首次出现顺序排列的 `Map`;每个分组保持输入顺序,稀疏空位被忽略。
|
|
43
43
|
*/
|
|
44
44
|
export declare function groupBy<Item, Key>(items: readonly Item[], selectKey: KeySelector<Item, Key>): Map<Key, Item[]>;
|
|
45
45
|
/**
|
|
46
46
|
* 按谓词把数组拆分为匹配项和非匹配项。
|
|
47
47
|
*
|
|
48
|
-
* @param items -
|
|
49
|
-
* @param predicate -
|
|
48
|
+
* @param items - 不会被修改的输入数组
|
|
49
|
+
* @param predicate - 接收项目与索引的判断函数
|
|
50
50
|
* @returns 二元组:第一项匹配谓词,第二项不匹配;两组都保持原顺序并忽略稀疏空位。
|
|
51
51
|
*/
|
|
52
52
|
export declare function partition<Item>(items: readonly Item[], predicate: (item: Item, index: number) => boolean): [matched: Item[], unmatched: Item[]];
|
|
53
53
|
/**
|
|
54
54
|
* 返回只出现在左侧数组中的不同值。
|
|
55
55
|
*
|
|
56
|
-
* @param left -
|
|
57
|
-
* @param right -
|
|
56
|
+
* @param left - 主输入数组
|
|
57
|
+
* @param right - 需要排除的值
|
|
58
58
|
* @returns 保留左侧首次出现顺序的去重结果;两侧稀疏空位都被忽略。
|
|
59
59
|
*/
|
|
60
60
|
export declare function difference<Item>(left: readonly Item[], right: readonly Item[]): Item[];
|
|
61
61
|
/**
|
|
62
62
|
* 返回两个数组共有的不同值。
|
|
63
63
|
*
|
|
64
|
-
* @param left -
|
|
65
|
-
* @param right -
|
|
64
|
+
* @param left - 决定结果顺序的数组
|
|
65
|
+
* @param right - 用于成员判断的数组
|
|
66
66
|
* @returns 保留左侧首次出现顺序的去重结果;两侧稀疏空位都被忽略。
|
|
67
67
|
*/
|
|
68
68
|
export declare function intersection<Item>(left: readonly Item[], right: readonly Item[]): Item[];
|
|
69
69
|
/**
|
|
70
70
|
* 返回只存在于其中一个数组的不同值。
|
|
71
71
|
*
|
|
72
|
-
* @param left -
|
|
73
|
-
* @param right -
|
|
72
|
+
* @param left - 决定左侧结果顺序的数组
|
|
73
|
+
* @param right - 决定右侧结果顺序的数组
|
|
74
74
|
* @returns 先按左侧、再按右侧首次出现顺序排列的对称差集;使用 SameValueZero 比较并忽略稀疏空位。
|
|
75
75
|
*/
|
|
76
76
|
export declare function symmetricDifference<Item>(left: readonly Item[], right: readonly Item[]): Item[];
|
|
77
77
|
/**
|
|
78
78
|
* 判断选择器产生的键是否重复。
|
|
79
79
|
*
|
|
80
|
-
* @param items -
|
|
80
|
+
* @param items - 不会被修改的输入数组
|
|
81
81
|
* @param selectKey - 返回比较键的函数;键使用 SameValueZero 语义比较。
|
|
82
82
|
* @returns 存在至少一个重复键时返回 `true`。
|
|
83
83
|
*/
|
|
@@ -86,8 +86,8 @@ export declare function hasDuplicatesBy<Item, Key>(items: readonly Item[], selec
|
|
|
86
86
|
* 判断所有项目是否具有相同的选择器结果。
|
|
87
87
|
*
|
|
88
88
|
* @remarks 空数组、只有稀疏空位的数组和单项数组按数学惯例返回 `true`;空位不会调用选择器。
|
|
89
|
-
* @param items -
|
|
90
|
-
* @param selectKey -
|
|
89
|
+
* @param items - 不会被修改的输入数组
|
|
90
|
+
* @param selectKey - 返回比较键的函数
|
|
91
91
|
* @returns 所有键都满足 SameValueZero 相等时返回 `true`。
|
|
92
92
|
*/
|
|
93
93
|
export declare function allEqualBy<Item, Key>(items: readonly Item[], selectKey: KeySelector<Item, Key>): boolean;
|
|
@@ -95,24 +95,24 @@ export declare function allEqualBy<Item, Key>(items: readonly Item[], selectKey:
|
|
|
95
95
|
//#region src/async/index.d.ts
|
|
96
96
|
/** 统一同步返回值与 PromiseLike 返回值的内部回调签名。 */
|
|
97
97
|
type AsyncCallback<Arguments extends unknown[], Result> = (...arguments_: Arguments) => Result | PromiseLike<Result>;
|
|
98
|
-
/**
|
|
98
|
+
/** 可接收取消信号的通用选项 */
|
|
99
99
|
export interface AbortOptions {
|
|
100
100
|
/** 已取消时立即失败;运行期间取消时停止等待并拒绝 Promise。 */
|
|
101
101
|
signal?: AbortSignal;
|
|
102
102
|
}
|
|
103
|
-
/** {@link withTimeout}
|
|
103
|
+
/** {@link withTimeout} 的行为选项 */
|
|
104
104
|
export interface TimeoutOptions extends AbortOptions {
|
|
105
105
|
/** 超时时使用的开发者消息 */
|
|
106
106
|
message?: string;
|
|
107
107
|
}
|
|
108
|
-
/**
|
|
108
|
+
/** 每次重试操作接收的上下文 */
|
|
109
109
|
export interface RetryContext {
|
|
110
|
-
/** 从 1
|
|
110
|
+
/** 从 1 开始的当前尝试次数 */
|
|
111
111
|
attempt: number;
|
|
112
|
-
/**
|
|
112
|
+
/** 调用方提供的取消信号 */
|
|
113
113
|
signal?: AbortSignal;
|
|
114
114
|
}
|
|
115
|
-
/** {@link retry}
|
|
115
|
+
/** {@link retry} 的策略选项 */
|
|
116
116
|
export interface RetryOptions extends AbortOptions {
|
|
117
117
|
/** 最大尝试次数,包含首次调用;默认 `3`。 */
|
|
118
118
|
attempts?: number;
|
|
@@ -124,18 +124,18 @@ export interface RetryOptions extends AbortOptions {
|
|
|
124
124
|
maxDelayMs?: number;
|
|
125
125
|
/**
|
|
126
126
|
* 决定当前失败后是否继续下一次尝试;默认重试所有尚未到达上限的错误。
|
|
127
|
-
* @param error -
|
|
128
|
-
* @param context -
|
|
127
|
+
* @param error - 当前操作抛出或拒绝的原始值
|
|
128
|
+
* @param context - 当前尝试次数和调用方取消信号
|
|
129
129
|
* @returns `false` 时立即原样抛出当前错误;支持同步值或 PromiseLike。
|
|
130
130
|
*/
|
|
131
131
|
shouldRetry?: (error: unknown, context: RetryContext) => boolean | PromiseLike<boolean>;
|
|
132
132
|
}
|
|
133
|
-
/** {@link mapConcurrent}
|
|
133
|
+
/** {@link mapConcurrent} 的执行选项 */
|
|
134
134
|
export interface ConcurrentMapOptions {
|
|
135
135
|
/** 已取消时停止调度新任务;已经开始的映射器需要自行响应同一信号。 */
|
|
136
136
|
signal?: AbortSignal;
|
|
137
137
|
}
|
|
138
|
-
/** Promise
|
|
138
|
+
/** Promise 感知的防抖函数 */
|
|
139
139
|
export interface DebouncedFunction<Arguments extends unknown[], Result> {
|
|
140
140
|
/**
|
|
141
141
|
* 调度一次调用;同一等待窗口内的调用共享最后一组参数对应的结果。
|
|
@@ -156,12 +156,12 @@ export interface DebouncedFunction<Arguments extends unknown[], Result> {
|
|
|
156
156
|
/** @returns 当前存在尚未开始的批次时返回 `true`;正在执行但没有等待批次时返回 `false`。 */
|
|
157
157
|
pending: () => boolean;
|
|
158
158
|
}
|
|
159
|
-
/** Promise
|
|
159
|
+
/** Promise 感知的前缘节流函数 */
|
|
160
160
|
export interface ThrottledFunction<Arguments extends unknown[], Result> {
|
|
161
161
|
/**
|
|
162
162
|
* 在空闲时立即调用原始回调;执行期和冷却期内的调用共享首次调用的 Promise。
|
|
163
163
|
* @param arguments_ - 仅窗口内首次调用的参数会传给原始回调。
|
|
164
|
-
* @returns 当前执行窗口共享的 Promise
|
|
164
|
+
* @returns 当前执行窗口共享的 Promise
|
|
165
165
|
*/
|
|
166
166
|
(...arguments_: Arguments): Promise<Result>;
|
|
167
167
|
/** 提前结束冷却期;已经开始的操作不会被取消,结束前仍禁止并发重入。 */
|
|
@@ -172,9 +172,9 @@ export interface ThrottledFunction<Arguments extends unknown[], Result> {
|
|
|
172
172
|
/**
|
|
173
173
|
* 等待指定时间,并支持 `AbortSignal`。
|
|
174
174
|
*
|
|
175
|
-
* @param milliseconds - 0 至 2,147,483,647
|
|
176
|
-
* @param options -
|
|
177
|
-
* @returns 到期后完成的 Promise
|
|
175
|
+
* @param milliseconds - 0 至 2,147,483,647 的有限毫秒数
|
|
176
|
+
* @param options - 可选取消信号
|
|
177
|
+
* @returns 到期后完成的 Promise
|
|
178
178
|
* @throws 参数非法时同步抛出 `RangeError`;信号已取消时同步抛出 `AbortError`。运行期间取消则拒绝返回的 Promise。
|
|
179
179
|
*/
|
|
180
180
|
export declare function sleep(milliseconds: number, options?: AbortOptions): Promise<void>;
|
|
@@ -184,19 +184,19 @@ export declare function sleep(milliseconds: number, options?: AbortOptions): Pro
|
|
|
184
184
|
* @remarks 超时或取消只停止等待,不能自动取消底层操作;需要真正取消时应同时把
|
|
185
185
|
* 同一个 `AbortSignal` 传给底层 API。
|
|
186
186
|
* @param promise - 需要等待的 Promise 或 PromiseLike。
|
|
187
|
-
* @param timeoutMs - 0 至 2,147,483,647
|
|
188
|
-
* @param options -
|
|
189
|
-
* @returns 底层 Promise
|
|
187
|
+
* @param timeoutMs - 0 至 2,147,483,647 的有限等待时间
|
|
188
|
+
* @param options - 取消信号与自定义消息
|
|
189
|
+
* @returns 底层 Promise 的结果
|
|
190
190
|
* @throws 等待时间非法或信号已取消时同步抛错;运行期间的超时、取消及源 Promise 失败通过返回的 Promise 拒绝。
|
|
191
191
|
*/
|
|
192
192
|
export declare function withTimeout<Result>(promise: PromiseLike<Result>, timeoutMs: number, options?: TimeoutOptions): Promise<Result>;
|
|
193
193
|
/**
|
|
194
194
|
* 使用有上限的指数退避重试操作。
|
|
195
195
|
*
|
|
196
|
-
* @typeParam Result -
|
|
196
|
+
* @typeParam Result - 操作结果类型
|
|
197
197
|
* @param operation - 每次尝试都会调用的函数;`attempt` 从 1 开始。
|
|
198
|
-
* @param options -
|
|
199
|
-
* @returns
|
|
198
|
+
* @param options - 尝试次数、退避和取消策略
|
|
199
|
+
* @returns 首次成功结果
|
|
200
200
|
* @throws 最后一次操作错误、`shouldRetry` 错误或名称为 `AbortError` 的取消错误;策略参数非法时抛出 `RangeError`。
|
|
201
201
|
*/
|
|
202
202
|
export declare function retry<Result>(operation: (context: RetryContext) => Result | PromiseLike<Result>, options?: RetryOptions): Promise<Awaited<Result>>;
|
|
@@ -205,10 +205,10 @@ export declare function retry<Result>(operation: (context: RetryContext) => Resu
|
|
|
205
205
|
*
|
|
206
206
|
* @remarks 任一映射失败后不会再调度新项目,但已经开始的映射无法自动取消;映射器
|
|
207
207
|
* 应使用传入的 `signal` 取消底层工作。
|
|
208
|
-
* @param items -
|
|
208
|
+
* @param items - 不会被修改的输入数组
|
|
209
209
|
* @param concurrency - 同时运行的最大任务数,必须为正安全整数。
|
|
210
|
-
* @param mapper -
|
|
211
|
-
* @param options -
|
|
210
|
+
* @param mapper - 接收项目、索引和取消信号的映射函数
|
|
211
|
+
* @param options - 可选取消信号
|
|
212
212
|
* @returns 与输入长度和顺序一致的结果数组;稀疏空位保持为空位且不会调用映射器。
|
|
213
213
|
* @throws `RangeError` 当 `concurrency` 不是正安全整数;取消时抛出名称为 `AbortError` 的 `Error`。
|
|
214
214
|
*/
|
|
@@ -218,9 +218,9 @@ export declare function mapConcurrent<Item, Result>(items: readonly Item[], conc
|
|
|
218
218
|
*
|
|
219
219
|
* @remarks 同一窗口内的所有调用都会等待最后一组参数对应的执行结果;回调错误会原样
|
|
220
220
|
* 拒绝该批次的全部调用,不会留下永久 pending 的 Promise。
|
|
221
|
-
* @param callback -
|
|
221
|
+
* @param callback - 同步或异步回调
|
|
222
222
|
* @param delayMs - 0 至 2,147,483,647 的有限等待时间,默认 300 毫秒。
|
|
223
|
-
* @returns
|
|
223
|
+
* @returns 具有取消、立即执行和状态方法的防抖函数
|
|
224
224
|
* @throws `RangeError` 当延迟不在平台计时器支持范围内。
|
|
225
225
|
*/
|
|
226
226
|
export declare function debounce<Arguments extends unknown[], Result>(callback: AsyncCallback<Arguments, Result>, delayMs?: number): DebouncedFunction<Arguments, Awaited<Result>>;
|
|
@@ -229,15 +229,15 @@ export declare function debounce<Arguments extends unknown[], Result>(callback:
|
|
|
229
229
|
*
|
|
230
230
|
* @remarks 窗口内的调用共享首次调用结果。若回调执行时间超过窗口,后续调用仍会等待
|
|
231
231
|
* 当前回调,避免异步操作重入;该函数不安排尾缘调用。
|
|
232
|
-
* @param callback -
|
|
232
|
+
* @param callback - 同步或异步回调
|
|
233
233
|
* @param delayMs - 0 至 2,147,483,647 的有限冷却时间,默认 300 毫秒。
|
|
234
|
-
* @returns
|
|
234
|
+
* @returns 具有取消和状态方法的前缘节流函数
|
|
235
235
|
* @throws `RangeError` 当延迟不在平台计时器支持范围内。
|
|
236
236
|
*/
|
|
237
237
|
export declare function throttle<Arguments extends unknown[], Result>(callback: AsyncCallback<Arguments, Result>, delayMs?: number): ThrottledFunction<Arguments, Awaited<Result>>;
|
|
238
238
|
//#endregion
|
|
239
239
|
//#region src/internal/text.d.ts
|
|
240
|
-
/**
|
|
240
|
+
/** 解码或解密后的字符串扩展 */
|
|
241
241
|
interface DecodedTextExtension {
|
|
242
242
|
/**
|
|
243
243
|
* 显式把原始文本解析为 JSON 值。
|
|
@@ -254,72 +254,72 @@ type DecodedText = string & DecodedTextExtension;
|
|
|
254
254
|
/**
|
|
255
255
|
* 将任意字节编码为标准 Base64。
|
|
256
256
|
*
|
|
257
|
-
* @param bytes -
|
|
258
|
-
* @returns 带标准 `=` 填充的 Base64
|
|
257
|
+
* @param bytes - 不会被修改的字节序列
|
|
258
|
+
* @returns 带标准 `=` 填充的 Base64 文本
|
|
259
259
|
*/
|
|
260
260
|
export declare function encodeBase64Bytes(bytes: Uint8Array): string;
|
|
261
261
|
/**
|
|
262
262
|
* 解码标准 Base64。
|
|
263
263
|
*
|
|
264
264
|
* @remarks 允许省略填充和包含 ASCII 空白,但拒绝非规范尾部位。
|
|
265
|
-
* @param value - Base64
|
|
266
|
-
* @returns
|
|
265
|
+
* @param value - Base64 文本
|
|
266
|
+
* @returns 新建的字节数组
|
|
267
267
|
* @throws 输入非法时抛出 `TypeError`。
|
|
268
268
|
*/
|
|
269
269
|
export declare function decodeBase64Bytes(value: string): Uint8Array;
|
|
270
270
|
/**
|
|
271
271
|
* 将 UTF-8 文本编码为标准 Base64。
|
|
272
272
|
*
|
|
273
|
-
* @param value - 任意 Unicode
|
|
274
|
-
* @returns 带标准填充的 Base64
|
|
275
|
-
* @
|
|
273
|
+
* @param value - 任意 Unicode 字符串
|
|
274
|
+
* @returns 带标准填充的 Base64 文本
|
|
275
|
+
* @remarks 使用内部 UTF-8 编码,不依赖平台 Encoding API。
|
|
276
276
|
*/
|
|
277
277
|
export declare function encodeBase64(value: string): string;
|
|
278
278
|
/**
|
|
279
279
|
* 将标准 Base64 解码为 UTF-8 文本。
|
|
280
280
|
*
|
|
281
|
-
* @param value - Base64
|
|
281
|
+
* @param value - Base64 文本
|
|
282
282
|
* @returns 可直接使用或显式调用 `.parseJson<Value>()` 的原始 Unicode 字符串。
|
|
283
|
-
* @throws Base64 或 UTF-8 非法时抛出 `TypeError
|
|
283
|
+
* @throws Base64 或 UTF-8 非法时抛出 `TypeError`。
|
|
284
284
|
*/
|
|
285
285
|
export declare function decodeBase64(value: string): DecodedText;
|
|
286
286
|
/**
|
|
287
287
|
* 将任意字节编码为无填充 Base64URL。
|
|
288
288
|
*
|
|
289
|
-
* @param bytes -
|
|
290
|
-
* @returns 仅使用 URL
|
|
289
|
+
* @param bytes - 不会被修改的字节序列
|
|
290
|
+
* @returns 仅使用 URL 安全字母表的文本
|
|
291
291
|
*/
|
|
292
292
|
export declare function encodeBase64UrlBytes(bytes: Uint8Array): string;
|
|
293
293
|
/**
|
|
294
294
|
* 解码 Base64URL 字节。
|
|
295
295
|
*
|
|
296
296
|
* @remarks 接受带填充和无填充形式,不接受空白或标准 Base64 的 `+`、`/`。
|
|
297
|
-
* @param value - Base64URL
|
|
298
|
-
* @returns
|
|
297
|
+
* @param value - Base64URL 文本
|
|
298
|
+
* @returns 新建的字节数组
|
|
299
299
|
* @throws 输入非法时抛出 `TypeError`。
|
|
300
300
|
*/
|
|
301
301
|
export declare function decodeBase64UrlBytes(value: string): Uint8Array;
|
|
302
302
|
/**
|
|
303
303
|
* 将 UTF-8 文本编码为无填充 Base64URL。
|
|
304
304
|
*
|
|
305
|
-
* @param value - 任意 Unicode
|
|
306
|
-
* @returns 仅使用 URL
|
|
307
|
-
* @
|
|
305
|
+
* @param value - 任意 Unicode 字符串
|
|
306
|
+
* @returns 仅使用 URL 安全字母表的文本
|
|
307
|
+
* @remarks 使用内部 UTF-8 编码,不依赖平台 Encoding API。
|
|
308
308
|
*/
|
|
309
309
|
export declare function encodeBase64Url(value: string): string;
|
|
310
310
|
/**
|
|
311
311
|
* 将 Base64URL 解码为 UTF-8 文本。
|
|
312
312
|
*
|
|
313
|
-
* @param value - 带填充或无填充的 Base64URL
|
|
313
|
+
* @param value - 带填充或无填充的 Base64URL 文本
|
|
314
314
|
* @returns 可直接使用或显式调用 `.parseJson<Value>()` 的原始 Unicode 字符串。
|
|
315
|
-
* @throws Base64URL 或 UTF-8 非法时抛出 `TypeError
|
|
315
|
+
* @throws Base64URL 或 UTF-8 非法时抛出 `TypeError`。
|
|
316
316
|
*/
|
|
317
317
|
export declare function decodeBase64Url(value: string): DecodedText;
|
|
318
318
|
/**
|
|
319
319
|
* 把 Latin-1 文本编码为标准 Base64。
|
|
320
320
|
*
|
|
321
321
|
* @param value - 每个 UTF-16 码元都必须位于 0–255 的文本。
|
|
322
|
-
* @returns 带标准填充的 Base64
|
|
322
|
+
* @returns 带标准填充的 Base64 文本
|
|
323
323
|
* @throws `TypeError` 当文本包含 Latin-1 范围外的码元。
|
|
324
324
|
*/
|
|
325
325
|
export declare function encodeLatin1Base64(value: string): string;
|
|
@@ -337,8 +337,8 @@ export declare function decodeLatin1Base64(value: string): DecodedText;
|
|
|
337
337
|
* @remarks 给定相同的 6 字符前缀时,默认输出与旧有效载荷逐字符兼容。旧字典在 101–124 字符载荷中引用越界;这里复制末字符作为单字符回退,
|
|
338
338
|
* 使旧删除字典流程仍能解码。传入 `0` 会同时关闭随机前缀与字典插入。
|
|
339
339
|
* 该格式只是可逆编码,不提供加密、完整性或身份认证。
|
|
340
|
-
* @param value - 任意可由 `encodeURIComponent` 处理的 Unicode
|
|
341
|
-
* @param prefixLength - 随机字母前缀长度;默认 `6
|
|
340
|
+
* @param value - 任意可由 `encodeURIComponent` 处理的 Unicode 文本
|
|
341
|
+
* @param prefixLength - 随机字母前缀长度;默认 `6`
|
|
342
342
|
* @returns 带随机前缀和兼容字典字符的 Base64 文本;空输入返回空字符串。
|
|
343
343
|
* @throws `RangeError` 当前缀长度不是非负安全整数;输入包含孤立代理项时保留平台错误。
|
|
344
344
|
*/
|
|
@@ -354,7 +354,7 @@ export declare function encodeSecureBase64(value: string, prefixLength?: number)
|
|
|
354
354
|
export declare function decodeSecureBase64(value: string, prefixLength?: number): DecodedText;
|
|
355
355
|
//#endregion
|
|
356
356
|
//#region src/color/index.d.ts
|
|
357
|
-
/** 0 至 255 范围的 RGB
|
|
357
|
+
/** 0 至 255 范围的 RGB 颜色 */
|
|
358
358
|
export interface RgbColor {
|
|
359
359
|
/** 蓝色通道;必须是闭区间 `[0, 255]` 内的有限数,格式化时舍入到整数。 */
|
|
360
360
|
blue: number;
|
|
@@ -363,7 +363,7 @@ export interface RgbColor {
|
|
|
363
363
|
/** 红色通道;必须是闭区间 `[0, 255]` 内的有限数,格式化时舍入到整数。 */
|
|
364
364
|
red: number;
|
|
365
365
|
}
|
|
366
|
-
/** 带 0 至 1 Alpha 通道的 RGB
|
|
366
|
+
/** 带 0 至 1 Alpha 通道的 RGB 颜色 */
|
|
367
367
|
export interface RgbaColor extends RgbColor {
|
|
368
368
|
/** 不透明度;必须是闭区间 `[0, 1]` 内的有限数,`0` 完全透明,`1` 完全不透明。 */
|
|
369
369
|
alpha: number;
|
|
@@ -371,7 +371,7 @@ export interface RgbaColor extends RgbColor {
|
|
|
371
371
|
/**
|
|
372
372
|
* 解析可带可不带 `#` 的 `rgb`、`rgba`、`rrggbb` 或 `rrggbbaa`。
|
|
373
373
|
*
|
|
374
|
-
* @param value -
|
|
374
|
+
* @param value - 十六进制颜色文本
|
|
375
375
|
* @returns 标准化的 RGBA 对象;省略 Alpha 时为 1。
|
|
376
376
|
* @throws 输入非法时抛出 `TypeError`。
|
|
377
377
|
*/
|
|
@@ -381,16 +381,16 @@ export declare function parseHexColor(value: string): RgbaColor;
|
|
|
381
381
|
*
|
|
382
382
|
* @param color - 颜色通道;RGB 会四舍五入到最近整数。
|
|
383
383
|
* @param includeAlpha - 是否输出 Alpha;默认只在传入 Alpha 且小于 1 时输出。
|
|
384
|
-
* @returns 小写 `#rrggbb` 或 `#rrggbbaa`
|
|
384
|
+
* @returns 小写 `#rrggbb` 或 `#rrggbbaa` 文本
|
|
385
385
|
* @throws 通道或 Alpha 非法时抛出 `RangeError`。
|
|
386
386
|
*/
|
|
387
387
|
export declare function formatHexColor(color: RgbColor | RgbaColor, includeAlpha?: boolean): string;
|
|
388
388
|
/**
|
|
389
389
|
* 线性混合两种十六进制颜色,包括 Alpha 通道。
|
|
390
390
|
*
|
|
391
|
-
* @param first - `amount = 0`
|
|
392
|
-
* @param second - `amount = 1`
|
|
393
|
-
* @param amount - 0 至 1
|
|
391
|
+
* @param first - `amount = 0` 时的颜色
|
|
392
|
+
* @param second - `amount = 1` 时的颜色
|
|
393
|
+
* @param amount - 0 至 1 的混合比例
|
|
394
394
|
* @returns 小写十六进制颜色;任一输入含透明度时保留 Alpha。
|
|
395
395
|
* @throws 颜色非法时抛出 `TypeError`;比例非法时抛出 `RangeError`。
|
|
396
396
|
*/
|
|
@@ -398,16 +398,16 @@ export declare function mixHexColors(first: string, second: string, amount: numb
|
|
|
398
398
|
/**
|
|
399
399
|
* 按比例向黑色混合。
|
|
400
400
|
*
|
|
401
|
-
* @param color -
|
|
402
|
-
* @param amount - 0 至 1
|
|
401
|
+
* @param color - 合法十六进制颜色
|
|
402
|
+
* @param amount - 0 至 1 的混合比例
|
|
403
403
|
* @returns 混入黑色后的十六进制颜色;参数与异常语义见 {@link mixHexColors}。
|
|
404
404
|
*/
|
|
405
405
|
export declare function mixHexColorWithBlack(color: string, amount: number): string;
|
|
406
406
|
/**
|
|
407
407
|
* 按比例向白色混合。
|
|
408
408
|
*
|
|
409
|
-
* @param color -
|
|
410
|
-
* @param amount - 0 至 1
|
|
409
|
+
* @param color - 合法十六进制颜色
|
|
410
|
+
* @param amount - 0 至 1 的混合比例
|
|
411
411
|
* @returns 混入白色后的十六进制颜色;参数与异常语义见 {@link mixHexColors}。
|
|
412
412
|
*/
|
|
413
413
|
export declare function mixHexColorWithWhite(color: string, amount: number): string;
|
|
@@ -415,8 +415,8 @@ export declare function mixHexColorWithWhite(color: string, amount: number): str
|
|
|
415
415
|
* 计算 WCAG sRGB 相对亮度。
|
|
416
416
|
*
|
|
417
417
|
* @remarks Alpha 通道不会参与计算;半透明颜色应先与实际背景混合。
|
|
418
|
-
* @param color -
|
|
419
|
-
* @returns 0 至 1
|
|
418
|
+
* @param color - 合法十六进制颜色
|
|
419
|
+
* @returns 0 至 1 的相对亮度
|
|
420
420
|
* @throws 输入非法时抛出 `TypeError`。
|
|
421
421
|
*/
|
|
422
422
|
export declare function relativeLuminance(color: string): number;
|
|
@@ -424,18 +424,18 @@ export declare function relativeLuminance(color: string): number;
|
|
|
424
424
|
* 计算两种不透明颜色的 WCAG 对比度,范围 1 至 21。
|
|
425
425
|
*
|
|
426
426
|
* @remarks 返回比值本身,不代表特定字号或 WCAG 等级必然通过。
|
|
427
|
-
* @param first -
|
|
428
|
-
* @param second -
|
|
429
|
-
* @returns
|
|
427
|
+
* @param first - 第一种十六进制颜色
|
|
428
|
+
* @param second - 第二种十六进制颜色
|
|
429
|
+
* @returns 较亮颜色与较暗颜色的对比度
|
|
430
430
|
* @throws 输入非法时抛出 `TypeError`。
|
|
431
431
|
*/
|
|
432
432
|
export declare function contrastRatio(first: string, second: string): number;
|
|
433
433
|
/**
|
|
434
434
|
* 从两个候选颜色中选择与背景对比度更高的一项。
|
|
435
435
|
*
|
|
436
|
-
* @param background -
|
|
437
|
-
* @param first -
|
|
438
|
-
* @param second -
|
|
436
|
+
* @param background - 实际不透明背景色
|
|
437
|
+
* @param first - 第一候选,默认黑色
|
|
438
|
+
* @param second - 第二候选,默认白色
|
|
439
439
|
* @returns 对比度较高的原始候选字符串;相同时返回 `first`。
|
|
440
440
|
* @throws 任一颜色非法时抛出 `TypeError`。
|
|
441
441
|
*/
|
|
@@ -446,7 +446,7 @@ export declare function pickHigherContrastColor(background: string, first?: stri
|
|
|
446
446
|
export type AesCipherMode = "CBC" | "ECB";
|
|
447
447
|
/** AES 填充模式;与 .NET `PaddingMode` 中可由 CryptoJS 互操作的成员对应。 */
|
|
448
448
|
export type AesPaddingMode = "None" | "PKCS7" | "Zeros" | "ANSIX923" | "ISO10126";
|
|
449
|
-
/** Web Crypto 导出的 PEM
|
|
449
|
+
/** Web Crypto 导出的 PEM 公私钥对 */
|
|
450
450
|
export interface PemKeyPair {
|
|
451
451
|
/** 未加密的 PKCS#8 PEM 私钥,包含标准 `PRIVATE KEY` 头尾和 64 字符换行。 */
|
|
452
452
|
privateKey: string;
|
|
@@ -459,8 +459,8 @@ export type EcNamedCurve = "P-256" | "P-384" | "P-521";
|
|
|
459
459
|
* 生成随机字节。
|
|
460
460
|
*
|
|
461
461
|
* @remarks 优先使用 Web Crypto;平台缺少安全随机能力时回退到 `Math.random()`。
|
|
462
|
-
* @param length - 0 至 65,536
|
|
463
|
-
* @returns 新建的 `Uint8Array
|
|
462
|
+
* @param length - 0 至 65,536 的安全整数
|
|
463
|
+
* @returns 新建的 `Uint8Array`
|
|
464
464
|
* @throws 参数非法时抛出 `RangeError`。
|
|
465
465
|
*/
|
|
466
466
|
export declare function GenerateRandomBytes(length: number): Uint8Array;
|
|
@@ -469,8 +469,8 @@ export declare function GenerateRandomBytes(length: number): Uint8Array;
|
|
|
469
469
|
*
|
|
470
470
|
* @remarks JavaScript 引擎不保证严格常量时间;该函数只避免显式短路,不能替代服务端
|
|
471
471
|
* 密码学库提供的 timing-safe primitive。长度是否相同仍属于可观察信息。
|
|
472
|
-
* @param left -
|
|
473
|
-
* @param right -
|
|
472
|
+
* @param left - 第一字节序列
|
|
473
|
+
* @param right - 第二字节序列
|
|
474
474
|
* @returns 长度和每个字节均相同时返回 `true`。
|
|
475
475
|
*/
|
|
476
476
|
export declare function FixedTimeEquals(left: Uint8Array, right: Uint8Array): boolean;
|
|
@@ -478,102 +478,102 @@ export declare function FixedTimeEquals(left: Uint8Array, right: Uint8Array): bo
|
|
|
478
478
|
* 计算 MD5 摘要并返回小写十六进制文本。
|
|
479
479
|
*
|
|
480
480
|
* @remarks MD5 仅用于非安全的普通校验,不得用于密码、签名或抗碰撞场景。
|
|
481
|
-
* @param value - UTF-8
|
|
482
|
-
* @returns 32
|
|
481
|
+
* @param value - UTF-8 文本
|
|
482
|
+
* @returns 32 字符小写十六进制摘要
|
|
483
483
|
*/
|
|
484
484
|
export declare function MD5Encrypt(value: string): string;
|
|
485
485
|
/**
|
|
486
486
|
* 计算 SHA-1 摘要并返回大写十六进制文本。
|
|
487
487
|
*
|
|
488
488
|
* @remarks SHA-1 仅用于非安全的普通校验,不得用于密码、签名或抗碰撞场景。
|
|
489
|
-
* @param value - UTF-8
|
|
490
|
-
* @returns 40
|
|
489
|
+
* @param value - UTF-8 文本
|
|
490
|
+
* @returns 40 字符大写十六进制摘要
|
|
491
491
|
*/
|
|
492
492
|
export declare function SHA1Encrypt(value: string): string;
|
|
493
493
|
/**
|
|
494
494
|
* 计算 SHA-256 摘要。
|
|
495
495
|
*
|
|
496
496
|
* @remarks SHA-256 是快速摘要,不适合直接存储或校验密码。
|
|
497
|
-
* @param value - UTF-8
|
|
498
|
-
* @returns 32
|
|
499
|
-
* @throws 缺少 Web Crypto
|
|
497
|
+
* @param value - UTF-8 字符串或原始字节
|
|
498
|
+
* @returns 32 字节摘要
|
|
499
|
+
* @throws 缺少 Web Crypto 时抛出 `Error`。
|
|
500
500
|
*/
|
|
501
501
|
export declare function SHA256Bytes(value: string): Promise<Uint8Array>;
|
|
502
502
|
/**
|
|
503
503
|
* 计算 SHA-256 并格式化为十六进制。
|
|
504
504
|
*
|
|
505
|
-
* @param value - UTF-8
|
|
506
|
-
* @returns 64
|
|
507
|
-
* @throws 缺少 Web Crypto
|
|
505
|
+
* @param value - UTF-8 字符串或原始字节
|
|
506
|
+
* @returns 64 字符大写十六进制文本
|
|
507
|
+
* @throws 缺少 Web Crypto 时抛出 `Error`。
|
|
508
508
|
*/
|
|
509
509
|
export declare function SHA256Encrypt(value: string): Promise<string>;
|
|
510
510
|
/**
|
|
511
511
|
* 计算 SHA-384 摘要。
|
|
512
512
|
*
|
|
513
|
-
* @param value - UTF-8
|
|
514
|
-
* @returns 48
|
|
513
|
+
* @param value - UTF-8 文本或原始字节
|
|
514
|
+
* @returns 48 字节摘要
|
|
515
515
|
*/
|
|
516
516
|
export declare function SHA384Bytes(value: string): Promise<Uint8Array>;
|
|
517
517
|
/**
|
|
518
518
|
* 计算 SHA-384 并格式化为十六进制文本。
|
|
519
519
|
*
|
|
520
|
-
* @param value - UTF-8
|
|
521
|
-
* @returns 96
|
|
520
|
+
* @param value - UTF-8 文本或原始字节
|
|
521
|
+
* @returns 96 个大写十六进制字符组成的摘要
|
|
522
522
|
*/
|
|
523
523
|
export declare function SHA384Encrypt(value: string): Promise<string>;
|
|
524
524
|
/**
|
|
525
525
|
* 计算 SHA-512 摘要。
|
|
526
526
|
*
|
|
527
|
-
* @param value - UTF-8
|
|
528
|
-
* @returns 64
|
|
527
|
+
* @param value - UTF-8 文本或原始字节
|
|
528
|
+
* @returns 64 字节摘要
|
|
529
529
|
*/
|
|
530
530
|
export declare function SHA512Bytes(value: string): Promise<Uint8Array>;
|
|
531
531
|
/**
|
|
532
532
|
* 计算 SHA-512 并格式化为十六进制文本。
|
|
533
533
|
*
|
|
534
|
-
* @param value - UTF-8
|
|
535
|
-
* @returns 128
|
|
534
|
+
* @param value - UTF-8 文本或原始字节
|
|
535
|
+
* @returns 128 个大写十六进制字符组成的摘要
|
|
536
536
|
*/
|
|
537
537
|
export declare function SHA512Encrypt(value: string): Promise<string>;
|
|
538
538
|
/**
|
|
539
539
|
* 使用 HMAC-SHA-256 认证文本,并返回十六进制标签。
|
|
540
540
|
*
|
|
541
|
-
* @param value - 要认证的 UTF-8
|
|
542
|
-
* @param key - 非空的 UTF-8
|
|
543
|
-
* @returns 64
|
|
541
|
+
* @param value - 要认证的 UTF-8 文本或原始字节
|
|
542
|
+
* @param key - 非空的 UTF-8 文本密钥或原始密钥字节
|
|
543
|
+
* @returns 64 个小写十六进制字符组成的认证标签
|
|
544
544
|
*/
|
|
545
545
|
export declare function HMACSHA256Encrypt(value: string, key: string): Promise<string>;
|
|
546
546
|
/**
|
|
547
547
|
* 使用 HMAC-SHA-384 认证文本或字节,并返回十六进制标签。
|
|
548
548
|
*
|
|
549
|
-
* @param value - 要认证的 UTF-8
|
|
550
|
-
* @param key - 非空的 UTF-8
|
|
551
|
-
* @returns 96
|
|
549
|
+
* @param value - 要认证的 UTF-8 文本或原始字节
|
|
550
|
+
* @param key - 非空的 UTF-8 文本密钥或原始密钥字节
|
|
551
|
+
* @returns 96 个小写十六进制字符组成的认证标签
|
|
552
552
|
*/
|
|
553
553
|
export declare function HMACSHA384Encrypt(value: string, key: string): Promise<string>;
|
|
554
554
|
/**
|
|
555
555
|
* 使用 HMAC-SHA-512 认证文本或字节,并返回十六进制标签。
|
|
556
556
|
*
|
|
557
|
-
* @param value - 要认证的 UTF-8
|
|
558
|
-
* @param key - 非空的 UTF-8
|
|
559
|
-
* @returns 128
|
|
557
|
+
* @param value - 要认证的 UTF-8 文本或原始字节
|
|
558
|
+
* @param key - 非空的 UTF-8 文本密钥或原始密钥字节
|
|
559
|
+
* @returns 128 个小写十六进制字符组成的认证标签
|
|
560
560
|
*/
|
|
561
561
|
export declare function HMACSHA512Encrypt(value: string, key: string): Promise<string>;
|
|
562
562
|
/**
|
|
563
563
|
* 使用 PBKDF2-HMAC-SHA-256 从密码派生密钥。
|
|
564
564
|
*
|
|
565
|
-
* @param password - 1 至 1,024 UTF-8
|
|
566
|
-
* @param salt - 至少 8
|
|
565
|
+
* @param password - 1 至 1,024 UTF-8 字节的密码
|
|
566
|
+
* @param salt - 至少 8 字节的盐
|
|
567
567
|
* @param iterations - 迭代次数,范围为 100,000 至 5,000,000。
|
|
568
|
-
* @param outputLength - 输出长度,范围为 1 至 1,024
|
|
569
|
-
* @returns
|
|
568
|
+
* @param outputLength - 输出长度,范围为 1 至 1,024 字节
|
|
569
|
+
* @returns 指定长度的派生密钥
|
|
570
570
|
* @throws 参数超过协议边界时抛出 `TypeError` 或 `RangeError`。
|
|
571
571
|
*/
|
|
572
572
|
export declare function PBKDF2SHA256(password: string, salt: Uint8Array, iterations?: number, outputLength?: number): Promise<Uint8Array>;
|
|
573
573
|
/**
|
|
574
574
|
* 生成可持久化的随机盐 PBKDF2-HMAC-SHA-256 密码哈希。
|
|
575
575
|
*
|
|
576
|
-
* @param password - 1 至 1,024 UTF-8
|
|
576
|
+
* @param password - 1 至 1,024 UTF-8 字节的密码
|
|
577
577
|
* @param iterations - 迭代次数,范围为 100,000 至 5,000,000。
|
|
578
578
|
* @returns 包含版本、迭代次数、16 字节随机盐和 32 字节派生密钥的自描述字符串。
|
|
579
579
|
*/
|
|
@@ -581,7 +581,7 @@ export declare function HashPasswordPBKDF2SHA256(password: string, iterations?:
|
|
|
581
581
|
/**
|
|
582
582
|
* 验证 {@link HashPasswordPBKDF2SHA256} 生成的密码哈希。
|
|
583
583
|
*
|
|
584
|
-
* @param password -
|
|
584
|
+
* @param password - 要验证的密码
|
|
585
585
|
* @param passwordHash - 自描述的 PBKDF2-HMAC-SHA-256 密码哈希。
|
|
586
586
|
* @returns 格式有效且密码匹配时返回 `true`;格式无效或密码错误时返回 `false`。
|
|
587
587
|
*/
|
|
@@ -591,9 +591,9 @@ export declare function VerifyPasswordPBKDF2SHA256(password: string, passwordHas
|
|
|
591
591
|
*
|
|
592
592
|
* @param inputKeyMaterial - 输入密钥材料,例如 ECDH 原始共享秘密。
|
|
593
593
|
* @param salt - 可选盐;空值按 RFC 5869 的零盐语义处理。
|
|
594
|
-
* @param info -
|
|
595
|
-
* @param outputLength - 输出长度,范围为 1 至 8,160
|
|
596
|
-
* @returns 与 `salt` 和 `info`
|
|
594
|
+
* @param info - 应用、协议和密钥用途上下文
|
|
595
|
+
* @param outputLength - 输出长度,范围为 1 至 8,160 字节
|
|
596
|
+
* @returns 与 `salt` 和 `info` 绑定的派生密钥
|
|
597
597
|
*/
|
|
598
598
|
export declare function HKDFSHA256(inputKeyMaterial: Uint8Array, salt?: Uint8Array, info?: Uint8Array, outputLength?: number): Promise<Uint8Array>;
|
|
599
599
|
/**
|
|
@@ -602,10 +602,10 @@ export declare function HKDFSHA256(inputKeyMaterial: Uint8Array, salt?: Uint8Arr
|
|
|
602
602
|
* @remarks 密钥和 IV 分别补字符 `f` 或截断到 32、16 个 UTF-16 Code Unit,与 .NET
|
|
603
603
|
* `AESEncrypt` 保持一致。CBC/ECB 不提供完整性认证,密文可能被篡改。
|
|
604
604
|
* @param dataStr - 要加密的 UTF-8 文本;空白文本返回 `null`。
|
|
605
|
-
* @param key -
|
|
605
|
+
* @param key - 非空白的密钥文本
|
|
606
606
|
* @param vector - 非空白的初始化向量文本;ECB 模式仍要求传入该参数以对齐 .NET 签名。
|
|
607
|
-
* @param cipherMode - AES 分组模式,默认 `CBC
|
|
608
|
-
* @param paddingMode - AES 填充模式,默认 `PKCS7
|
|
607
|
+
* @param cipherMode - AES 分组模式,默认 `CBC`
|
|
608
|
+
* @param paddingMode - AES 填充模式,默认 `PKCS7`
|
|
609
609
|
* @returns Base64 密文;输入、密钥或 IV 为空白时返回 `null`。
|
|
610
610
|
* @throws 模式或填充不受支持时抛出 `RangeError`。
|
|
611
611
|
*/
|
|
@@ -615,10 +615,10 @@ export declare function AESEncrypt(dataStr: string, key: string, vector: string,
|
|
|
615
615
|
*
|
|
616
616
|
* @remarks 参数归一化规则与 {@link AESEncrypt} 以及 .NET `AESDecrypt` 相同。
|
|
617
617
|
* @param dataStr - Base64 密文;空白文本返回 `null`。
|
|
618
|
-
* @param key -
|
|
619
|
-
* @param vector -
|
|
620
|
-
* @param cipherMode - AES 分组模式,默认 `CBC
|
|
621
|
-
* @param paddingMode - AES 填充模式,默认 `PKCS7
|
|
618
|
+
* @param key - 加密时使用的密钥文本
|
|
619
|
+
* @param vector - 加密时使用的初始化向量文本
|
|
620
|
+
* @param cipherMode - AES 分组模式,默认 `CBC`
|
|
621
|
+
* @param paddingMode - AES 填充模式,默认 `PKCS7`
|
|
622
622
|
* @returns 可直接使用或显式调用 `.parseJson<Value>()` 的原始 UTF-8 字符串;输入、密钥或 IV 为空白时返回 `null`。
|
|
623
623
|
* @throws 模式、填充、Base64、密钥或密文无效时抛出错误。
|
|
624
624
|
*/
|
|
@@ -627,9 +627,9 @@ export declare function AESDecrypt(dataStr: string, key: string, vector: string,
|
|
|
627
627
|
* 使用 SHA-256 归一化文本密钥,再以 AES-256-GCM 认证加密 UTF-8 文本。
|
|
628
628
|
*
|
|
629
629
|
* @remarks 输出与 .NET `AESEncryptAuthenticated` 的 v1 Base64 二进制载荷完全一致。
|
|
630
|
-
* @param plaintext - 要加密的 UTF-8
|
|
630
|
+
* @param plaintext - 要加密的 UTF-8 文本
|
|
631
631
|
* @param key - 非空的 UTF-8 文本密钥;内部归一化为 32 字节 SHA-256 摘要。
|
|
632
|
-
* @returns Base64 编码的 v1 AES-GCM
|
|
632
|
+
* @returns Base64 编码的 v1 AES-GCM 认证载荷
|
|
633
633
|
* @throws 密钥为空或运行时缺少 Web Crypto 时抛出错误。
|
|
634
634
|
*/
|
|
635
635
|
export declare function AESEncryptAuthenticated(plaintext: string, key: string): Promise<string>;
|
|
@@ -637,7 +637,7 @@ export declare function AESEncryptAuthenticated(plaintext: string, key: string):
|
|
|
637
637
|
* 解密并认证 .NET `AESEncryptAuthenticated` 或 {@link AESEncryptAuthenticated} 生成的载荷。
|
|
638
638
|
*
|
|
639
639
|
* @param payload - Base64 编码的 v1 AES-GCM 二进制载荷。
|
|
640
|
-
* @param key - 加密时使用的非空 UTF-8
|
|
640
|
+
* @param key - 加密时使用的非空 UTF-8 文本密钥
|
|
641
641
|
* @returns 可直接使用或显式调用 `.parseJson<Value>()` 的原始 UTF-8 字符串。
|
|
642
642
|
* @throws 载荷格式无效、密钥错误或认证失败时抛出错误。
|
|
643
643
|
*/
|
|
@@ -648,18 +648,18 @@ export declare function AESDecryptAuthenticated(payload: string, key: string): P
|
|
|
648
648
|
* @remarks 每次调用生成独立 16 字节盐与 12 字节 IV。输出是与 .NET `AESEncryptWithPassword`
|
|
649
649
|
* 一致的 v1 自描述载荷,不应由业务代码手动拆分或修改。密码加密不替代密钥管理。
|
|
650
650
|
* @param plaintext - 原始文本,不进行 JSON 推断;UTF-8 编码后最大 8 MiB。
|
|
651
|
-
* @param password - 1 至 1024 UTF-8
|
|
652
|
-
* @param iterations - PBKDF2 工作因子,默认 600,000
|
|
651
|
+
* @param password - 1 至 1024 UTF-8 字节的秘密口令
|
|
652
|
+
* @param iterations - PBKDF2 工作因子,默认 600,000
|
|
653
653
|
* @returns 认证密文字符串;相同输入每次产生不同结果。
|
|
654
654
|
* @throws 口令非法时抛出 `TypeError` 或 `RangeError`;明文过大时抛出 `RangeError`;
|
|
655
|
-
* 运行时缺少 Web Crypto
|
|
655
|
+
* 运行时缺少 Web Crypto 时抛出 `Error`。
|
|
656
656
|
*/
|
|
657
657
|
export declare function AESEncryptWithPassword(plaintext: string, password: string, iterations?: number): Promise<string>;
|
|
658
658
|
/**
|
|
659
659
|
* 解密 {@link AESEncryptWithPassword} 生成的 v1 认证载荷。
|
|
660
660
|
*
|
|
661
|
-
* @param payload - 未修改的 v1 载荷,最大约 16 MiB
|
|
662
|
-
* @param password -
|
|
661
|
+
* @param payload - 未修改的 v1 载荷,最大约 16 MiB 文本
|
|
662
|
+
* @param password - 加密时使用的口令
|
|
663
663
|
* @returns 可直接使用或显式调用 `.parseJson<Value>()` 的原始 UTF-8 字符串。
|
|
664
664
|
* @throws 格式或字段非法时抛出 `TypeError`,载荷过大时抛出 `RangeError`,认证或密码
|
|
665
665
|
* 失败及缺少平台能力时抛出 `Error`。
|
|
@@ -678,15 +678,15 @@ export declare function GenerateRSAKeyPair(modulusLength?: number): Promise<PemK
|
|
|
678
678
|
*
|
|
679
679
|
* @param plaintext - 要加密的 UTF-8 文本;长度必须满足 RSA-OAEP 模数限制。
|
|
680
680
|
* @param publicKeyPem - SubjectPublicKeyInfo PEM 公钥。
|
|
681
|
-
* @returns Base64 编码的 RSA
|
|
681
|
+
* @returns Base64 编码的 RSA 密文
|
|
682
682
|
* @throws 公钥格式无效或明文超过 RSA-OAEP 容量时抛出错误。
|
|
683
683
|
*/
|
|
684
684
|
export declare function RSAEncryptOAEP(plaintext: string, publicKeyPem: string): Promise<string>;
|
|
685
685
|
/**
|
|
686
686
|
* 使用 RSA-OAEP/SHA-256 私钥解密 Base64 密文。
|
|
687
687
|
*
|
|
688
|
-
* @param ciphertext - Base64 编码的 RSA
|
|
689
|
-
* @param privateKeyPem - 未加密的 PKCS#8 PEM
|
|
688
|
+
* @param ciphertext - Base64 编码的 RSA 密文
|
|
689
|
+
* @param privateKeyPem - 未加密的 PKCS#8 PEM 私钥
|
|
690
690
|
* @returns 可直接使用或显式调用 `.parseJson<Value>()` 的原始 UTF-8 字符串。
|
|
691
691
|
* @throws 私钥、Base64 或密文无效时抛出错误。
|
|
692
692
|
*/
|
|
@@ -694,8 +694,8 @@ export declare function RSADecryptOAEP(ciphertext: string, privateKeyPem: string
|
|
|
694
694
|
/**
|
|
695
695
|
* 使用 RSA-PSS/SHA-256 私钥签名文本或字节。
|
|
696
696
|
*
|
|
697
|
-
* @param value - 要签名的 UTF-8
|
|
698
|
-
* @param privateKeyPem - 未加密的 PKCS#8 PEM
|
|
697
|
+
* @param value - 要签名的 UTF-8 文本或原始字节
|
|
698
|
+
* @param privateKeyPem - 未加密的 PKCS#8 PEM 私钥
|
|
699
699
|
* @returns Base64 编码的 RSA-PSS 签名;盐长度固定为 32 字节。
|
|
700
700
|
* @throws 私钥格式无效或签名失败时抛出错误。
|
|
701
701
|
*/
|
|
@@ -703,8 +703,8 @@ export declare function RSASignPSS(value: string, privateKeyPem: string): Promis
|
|
|
703
703
|
/**
|
|
704
704
|
* 使用 RSA-PSS/SHA-256 公钥验证 Base64 签名。
|
|
705
705
|
*
|
|
706
|
-
* @param value - 签名时使用的 UTF-8
|
|
707
|
-
* @param signature - Base64 编码的 RSA-PSS
|
|
706
|
+
* @param value - 签名时使用的 UTF-8 文本或原始字节
|
|
707
|
+
* @param signature - Base64 编码的 RSA-PSS 签名
|
|
708
708
|
* @param publicKeyPem - SubjectPublicKeyInfo PEM 公钥。
|
|
709
709
|
* @returns 签名与内容、公钥匹配时返回 `true`。
|
|
710
710
|
* @throws 公钥或 Base64 格式无效时抛出错误。
|
|
@@ -721,19 +721,19 @@ export declare function GenerateECDSAKeyPair(namedCurve?: EcNamedCurve): Promise
|
|
|
721
721
|
* 使用 ECDSA 私钥签名文本或字节。
|
|
722
722
|
*
|
|
723
723
|
* @remarks Web Crypto 返回 IEEE P1363 固定字段拼接格式,与 .NET 实现一致。
|
|
724
|
-
* @param value - 要签名的 UTF-8
|
|
725
|
-
* @param privateKeyPem - 未加密的 EC PKCS#8 PEM
|
|
726
|
-
* @param namedCurve - 私钥使用的 NIST
|
|
724
|
+
* @param value - 要签名的 UTF-8 文本或原始字节
|
|
725
|
+
* @param privateKeyPem - 未加密的 EC PKCS#8 PEM 私钥
|
|
726
|
+
* @param namedCurve - 私钥使用的 NIST 曲线
|
|
727
727
|
* @returns Base64 编码的 IEEE P1363 ECDSA 签名。
|
|
728
728
|
*/
|
|
729
729
|
export declare function ECDSASign(value: string, privateKeyPem: string, namedCurve?: EcNamedCurve): Promise<string>;
|
|
730
730
|
/**
|
|
731
731
|
* 使用 ECDSA 公钥验证 Base64 签名。
|
|
732
732
|
*
|
|
733
|
-
* @param value - 签名时使用的 UTF-8
|
|
733
|
+
* @param value - 签名时使用的 UTF-8 文本或原始字节
|
|
734
734
|
* @param signature - Base64 编码的 IEEE P1363 ECDSA 签名。
|
|
735
735
|
* @param publicKeyPem - EC SubjectPublicKeyInfo PEM 公钥。
|
|
736
|
-
* @param namedCurve - 公钥使用的 NIST
|
|
736
|
+
* @param namedCurve - 公钥使用的 NIST 曲线
|
|
737
737
|
* @returns 签名与内容、公钥和曲线匹配时返回 `true`。
|
|
738
738
|
*/
|
|
739
739
|
export declare function ECDSAVerify(value: string, signature: string, publicKeyPem: string, namedCurve?: EcNamedCurve): Promise<boolean>;
|
|
@@ -748,74 +748,74 @@ export declare function GenerateECDHKeyPair(namedCurve?: EcNamedCurve): Promise<
|
|
|
748
748
|
* 使用本方 ECDH 私钥与对方 ECDH 公钥派生共享秘密。
|
|
749
749
|
*
|
|
750
750
|
* @remarks 返回值仍需经过合适的 KDF 后才能作为对称密钥,不应直接长期存储。
|
|
751
|
-
* @param privateKeyPem - 本方未加密的 EC PKCS#8 PEM
|
|
751
|
+
* @param privateKeyPem - 本方未加密的 EC PKCS#8 PEM 私钥
|
|
752
752
|
* @param publicKeyPem - 对方的 EC SubjectPublicKeyInfo PEM 公钥。
|
|
753
|
-
* @param namedCurve - 双方密钥使用的 NIST
|
|
754
|
-
* @returns 曲线字段长度的原始 ECDH
|
|
753
|
+
* @param namedCurve - 双方密钥使用的 NIST 曲线
|
|
754
|
+
* @returns 曲线字段长度的原始 ECDH 共享秘密
|
|
755
755
|
*/
|
|
756
756
|
export declare function DeriveECDHSecret(privateKeyPem: string, publicKeyPem: string, namedCurve?: EcNamedCurve): Promise<Uint8Array>;
|
|
757
757
|
/**
|
|
758
758
|
* 使用 ECDH 后以 SHA-256 派生共享密钥。
|
|
759
759
|
*
|
|
760
760
|
* @remarks 相比直接使用原始共享秘密,此入口与 .NET `DeriveECDHKeySHA256` 一致并固定输出 32 字节。
|
|
761
|
-
* @param privateKeyPem - 本方未加密的 EC PKCS#8 PEM
|
|
761
|
+
* @param privateKeyPem - 本方未加密的 EC PKCS#8 PEM 私钥
|
|
762
762
|
* @param publicKeyPem - 对方的 EC SubjectPublicKeyInfo PEM 公钥。
|
|
763
|
-
* @param namedCurve - 双方密钥使用的 NIST
|
|
764
|
-
* @returns 32
|
|
763
|
+
* @param namedCurve - 双方密钥使用的 NIST 曲线
|
|
764
|
+
* @returns 32 字节共享密钥
|
|
765
765
|
*/
|
|
766
766
|
export declare function DeriveECDHKeySHA256(privateKeyPem: string, publicKeyPem: string, namedCurve?: EcNamedCurve): Promise<Uint8Array>;
|
|
767
767
|
//#endregion
|
|
768
768
|
//#region src/date/index.d.ts
|
|
769
769
|
/** 可转换为日期的输入;数字始终按 Unix 毫秒时间戳处理。 */
|
|
770
770
|
export type DateInput = Date | number | string;
|
|
771
|
-
/** {@link formatRelativeTime}
|
|
771
|
+
/** {@link formatRelativeTime} 的语言与基准时间选项 */
|
|
772
772
|
export interface RelativeTimeOptions {
|
|
773
|
-
/**
|
|
773
|
+
/** 显式语言交给 Intl.RelativeTimeFormat;省略时内部输出简体中文。 */
|
|
774
774
|
locale?: string | readonly string[];
|
|
775
|
-
/**
|
|
775
|
+
/** 比较基准,默认当前时间 */
|
|
776
776
|
now?: DateInput;
|
|
777
777
|
/** 是否允许“昨天”“明天”等文本;默认 `auto`。 */
|
|
778
778
|
numeric?: Intl.RelativeTimeFormatNumeric;
|
|
779
|
-
/** 输出长度;默认 `long
|
|
779
|
+
/** 输出长度;默认 `long` */
|
|
780
780
|
style?: Intl.RelativeTimeFormatStyle;
|
|
781
781
|
}
|
|
782
782
|
/**
|
|
783
783
|
* 转换并克隆有效日期。
|
|
784
784
|
*
|
|
785
785
|
* @remarks 数字不进行秒/毫秒猜测;字符串遵循运行时 `Date` 解析规则,跨平台代码应传带显式时区的完整 ISO 8601。
|
|
786
|
-
* @param value - Date、Unix
|
|
787
|
-
* @returns 与输入不共享可变状态的新 Date
|
|
786
|
+
* @param value - Date、Unix 毫秒时间戳或运行时可解析字符串
|
|
787
|
+
* @returns 与输入不共享可变状态的新 Date
|
|
788
788
|
* @throws 输入无效时抛出 `TypeError`。
|
|
789
789
|
*/
|
|
790
790
|
export declare function toDate(value: DateInput): Date;
|
|
791
791
|
/**
|
|
792
792
|
* 判断输入能否转换为有效日期。
|
|
793
793
|
*
|
|
794
|
-
* @param value -
|
|
794
|
+
* @param value - 任意待检查值
|
|
795
795
|
* @returns 仅 Date、数字或字符串且时间戳有限时返回 `true`。
|
|
796
796
|
*/
|
|
797
797
|
export declare function isValidDate(value: unknown): value is DateInput;
|
|
798
798
|
/**
|
|
799
799
|
* 返回输入日期所在本地时区日期的 `00:00:00.000`,不修改输入。
|
|
800
800
|
*
|
|
801
|
-
* @param value -
|
|
802
|
-
* @returns
|
|
801
|
+
* @param value - 有效日期输入
|
|
802
|
+
* @returns 新建的本地日开始时间
|
|
803
803
|
* @throws 输入无效时抛出 `TypeError`。
|
|
804
804
|
*/
|
|
805
805
|
export declare function startOfDay(value: DateInput): Date;
|
|
806
806
|
/**
|
|
807
807
|
* 返回输入日期所在本地时区日期的 `23:59:59.999`,不修改输入。
|
|
808
808
|
*
|
|
809
|
-
* @param value -
|
|
810
|
-
* @returns
|
|
809
|
+
* @param value - 有效日期输入
|
|
810
|
+
* @returns 新建的本地日结束时间
|
|
811
811
|
* @throws 输入无效时抛出 `TypeError`。
|
|
812
812
|
*/
|
|
813
813
|
export declare function endOfDay(value: DateInput): Date;
|
|
814
814
|
/**
|
|
815
815
|
* 按本地日历增加整数天,不修改输入。
|
|
816
816
|
*
|
|
817
|
-
* @param value -
|
|
818
|
-
* @param amount -
|
|
817
|
+
* @param value - 基准日期
|
|
818
|
+
* @param amount - 可为负数的安全整数日数
|
|
819
819
|
* @returns 本地日历运算后的新 Date;夏令时变化可能使实际毫秒差不等于 24 小时。
|
|
820
820
|
* @throws 日期无效时抛出 `TypeError`;数量或结果非法时抛出 `RangeError`。
|
|
821
821
|
*/
|
|
@@ -824,26 +824,26 @@ export declare function addDays(value: DateInput, amount: number): Date;
|
|
|
824
824
|
* 按本地日历增加整数月,并把不存在的日期夹到目标月末。
|
|
825
825
|
*
|
|
826
826
|
* @example 1 月 31 日增加一个月会落在 2 月最后一天。
|
|
827
|
-
* @param value -
|
|
828
|
-
* @param amount -
|
|
829
|
-
* @returns 月份运算后的新 Date
|
|
827
|
+
* @param value - 基准日期
|
|
828
|
+
* @param amount - 可为负数的安全整数月数
|
|
829
|
+
* @returns 月份运算后的新 Date
|
|
830
830
|
* @throws 日期无效时抛出 `TypeError`;数量或结果非法时抛出 `RangeError`。
|
|
831
831
|
*/
|
|
832
832
|
export declare function addMonths(value: DateInput, amount: number): Date;
|
|
833
833
|
/**
|
|
834
834
|
* 按本地日历增加整数年,并沿用 {@link addMonths} 的月末夹取规则。
|
|
835
835
|
*
|
|
836
|
-
* @param value -
|
|
837
|
-
* @param amount -
|
|
838
|
-
* @returns 年份运算后的新 Date
|
|
836
|
+
* @param value - 基准日期
|
|
837
|
+
* @param amount - 可为负数的安全整数年数
|
|
838
|
+
* @returns 年份运算后的新 Date
|
|
839
839
|
* @throws 日期无效时抛出 `TypeError`;数量或结果非法时抛出 `RangeError`。
|
|
840
840
|
*/
|
|
841
841
|
export declare function addYears(value: DateInput, amount: number): Date;
|
|
842
842
|
/**
|
|
843
843
|
* 判断两个输入是否属于同一本地日历日。
|
|
844
844
|
*
|
|
845
|
-
* @param left -
|
|
846
|
-
* @param right -
|
|
845
|
+
* @param left - 第一日期
|
|
846
|
+
* @param right - 第二日期
|
|
847
847
|
* @returns 本地年、月、日均相同时返回 `true`。
|
|
848
848
|
* @throws 任一输入无效时抛出 `TypeError`。
|
|
849
849
|
*/
|
|
@@ -851,8 +851,8 @@ export declare function isSameDay(left: DateInput, right: DateInput): boolean;
|
|
|
851
851
|
/**
|
|
852
852
|
* 判断时间是否晚于基准时间。
|
|
853
853
|
*
|
|
854
|
-
* @param value -
|
|
855
|
-
* @param now -
|
|
854
|
+
* @param value - 待比较时间
|
|
855
|
+
* @param now - 比较基准,默认调用时的当前时刻
|
|
856
856
|
* @returns `value` 严格晚于基准时返回 `true`。
|
|
857
857
|
* @throws 任一输入无效时抛出 `TypeError`。
|
|
858
858
|
*/
|
|
@@ -860,32 +860,33 @@ export declare function isFuture(value: DateInput, now?: DateInput): boolean;
|
|
|
860
860
|
/**
|
|
861
861
|
* 返回指定基准所在本地日历日的完整闭区间。
|
|
862
862
|
*
|
|
863
|
-
* @param value -
|
|
864
|
-
* @returns
|
|
863
|
+
* @param value - 日期基准,默认调用时当前日期
|
|
864
|
+
* @returns 新建的本地日开始和结束时间二元组
|
|
865
865
|
* @throws 输入无效时抛出 `TypeError`。
|
|
866
866
|
*/
|
|
867
867
|
export declare function getLocalDayBounds(value?: DateInput): [start: Date, end: Date];
|
|
868
868
|
/**
|
|
869
869
|
* 判断日期是否位于包含首尾的时间区间。
|
|
870
870
|
*
|
|
871
|
-
* @param value -
|
|
872
|
-
* @param start -
|
|
873
|
-
* @param end -
|
|
871
|
+
* @param value - 待检查日期
|
|
872
|
+
* @param start - 包含的起点
|
|
873
|
+
* @param end - 包含的终点
|
|
874
874
|
* @returns 时间戳位于闭区间内时返回 `true`。
|
|
875
875
|
* @throws 无效日期抛出 `TypeError`;首尾反向时抛出 `RangeError`。
|
|
876
876
|
*/
|
|
877
877
|
export declare function isWithinInterval(value: DateInput, start: DateInput, end: DateInput): boolean;
|
|
878
878
|
/**
|
|
879
|
-
*
|
|
879
|
+
* 生成人类可读相对时间;默认中文使用内部实现,显式语言使用 Intl.RelativeTimeFormat。
|
|
880
880
|
*
|
|
881
881
|
* @remarks 秒、分钟、小时、天、周、月和年按固定时长阈值选择;这适合展示,不适合计费或日历运算。
|
|
882
|
-
* @param value -
|
|
883
|
-
* @param options -
|
|
884
|
-
* @returns
|
|
882
|
+
* @param value - 目标时间
|
|
883
|
+
* @param options - 语言、样式与比较基准
|
|
884
|
+
* @returns 相对时间文本
|
|
885
885
|
* @throws 日期无效时抛出 `TypeError`;Locale 或 Intl 选项非法时抛出 `RangeError`。
|
|
886
|
+
* 显式指定语言且缺少 Intl.RelativeTimeFormat 时抛出 `Error`。
|
|
886
887
|
*/
|
|
887
888
|
export declare function formatRelativeTime(value: DateInput, options?: RelativeTimeOptions): string;
|
|
888
|
-
/**
|
|
889
|
+
/** 日期选择器单日期快捷项 */
|
|
889
890
|
export interface DateShortcut {
|
|
890
891
|
/** 面向中文日期选择器的显示文本;调用方可直接用于菜单标签。 */
|
|
891
892
|
text: string;
|
|
@@ -895,7 +896,7 @@ export interface DateShortcut {
|
|
|
895
896
|
*/
|
|
896
897
|
value: () => Date;
|
|
897
898
|
}
|
|
898
|
-
/**
|
|
899
|
+
/** 日期选择器范围快捷项 */
|
|
899
900
|
export interface DateRangeShortcut {
|
|
900
901
|
/** 面向中文日期范围选择器的显示文本;调用方可直接用于菜单标签。 */
|
|
901
902
|
text: string;
|
|
@@ -909,7 +910,7 @@ export interface DateRangeShortcut {
|
|
|
909
910
|
* 把日期转换为固定中文相对时间文本。
|
|
910
911
|
*
|
|
911
912
|
* @remarks 10 位以内数字按 Unix 秒处理,其余数字按毫秒处理;月份与年份按本地日历月差计算。
|
|
912
|
-
* @param value - Date
|
|
913
|
+
* @param value - Date、时间戳、可解析字符串或空值
|
|
913
914
|
* @returns 例如“3分钟前”“半年后”;非法或空输入返回空字符串。
|
|
914
915
|
*/
|
|
915
916
|
export declare function formatChineseRelativeTime(value: Date | number | string | null | undefined): string;
|
|
@@ -923,14 +924,14 @@ export declare function createOneMonthRangeFromToday(towardFuture?: boolean): [s
|
|
|
923
924
|
/**
|
|
924
925
|
* 判断日期是否晚于调用时的当前时刻。
|
|
925
926
|
*
|
|
926
|
-
* @param time -
|
|
927
|
+
* @param time - 待比较日期
|
|
927
928
|
* @returns 时间戳严格晚于 `Date.now()` 时返回 `true`。
|
|
928
929
|
*/
|
|
929
930
|
export declare function isDateAfterNow(time: Date): boolean;
|
|
930
931
|
/**
|
|
931
932
|
* 根据浏览器本地小时返回固定中文问候语。
|
|
932
933
|
*
|
|
933
|
-
* @returns
|
|
934
|
+
* @returns 与当前时段对应的中文欢迎文本
|
|
934
935
|
*/
|
|
935
936
|
export declare function getLocalTimeGreeting(): string;
|
|
936
937
|
/**
|
|
@@ -950,22 +951,22 @@ export declare function createDateShortcuts(towardFuture?: boolean): DateShortcu
|
|
|
950
951
|
/**
|
|
951
952
|
* 返回今天的本地零点。
|
|
952
953
|
*
|
|
953
|
-
* @returns 新建的 `00:00:00.000` Date
|
|
954
|
+
* @returns 新建的 `00:00:00.000` Date
|
|
954
955
|
*/
|
|
955
956
|
export declare function getStartOfToday(): Date;
|
|
956
957
|
//#endregion
|
|
957
958
|
//#region src/dom/style.d.ts
|
|
958
|
-
/** 可序列化为内联 CSS
|
|
959
|
+
/** 可序列化为内联 CSS 的单个值 */
|
|
959
960
|
export type StyleValue = number | string | null | undefined;
|
|
960
|
-
/** camelCase、kebab-case 或 CSS
|
|
961
|
+
/** camelCase、kebab-case 或 CSS 自定义属性组成的只读样式对象 */
|
|
961
962
|
export type StyleObject = Readonly<Record<string, StyleValue>>;
|
|
962
|
-
/**
|
|
963
|
+
/** 字符串、样式对象、嵌套数组或空值 */
|
|
963
964
|
export type StyleInput = string | StyleObject | readonly StyleInput[] | null | undefined;
|
|
964
965
|
/**
|
|
965
966
|
* 为数值或纯数字字符串添加 CSS 单位。
|
|
966
967
|
*
|
|
967
968
|
* @param value - 数字、数字字符串或已有单位的 CSS 值;空值返回空字符串。
|
|
968
|
-
* @param unit - 非零数字使用的单位,默认 `px
|
|
969
|
+
* @param unit - 非零数字使用的单位,默认 `px`
|
|
969
970
|
* @returns 零统一返回 `"0"`;非数字字符串保持原样。
|
|
970
971
|
* @throws `RangeError` 当数字非有限或单位为空。
|
|
971
972
|
*/
|
|
@@ -977,13 +978,13 @@ export declare function addCssUnit(value?: string | number | null, unit?: string
|
|
|
977
978
|
* 实际渲染上下文验证,尤其不能允许用户控制属性名、`url()` 或自定义属性内容。
|
|
978
979
|
* 数字不会自动附加单位;需要长度单位时应先调用 {@link addCssUnit}。
|
|
979
980
|
* @param styles - 可嵌套样式输入;后出现的声明由 CSS 层叠规则覆盖先前声明。
|
|
980
|
-
* @returns 以分号结束、以空格分隔的 CSS
|
|
981
|
+
* @returns 以分号结束、以空格分隔的 CSS 声明字符串
|
|
981
982
|
* @throws `RangeError` 当对象中包含 `NaN` 或无穷数字。
|
|
982
983
|
*/
|
|
983
984
|
export declare function serializeStyle(styles: StyleInput): string;
|
|
984
985
|
//#endregion
|
|
985
986
|
//#region src/env/index.d.ts
|
|
986
|
-
/** 可识别的主要 JavaScript
|
|
987
|
+
/** 可识别的主要 JavaScript 运行环境 */
|
|
987
988
|
export type RuntimeKind = "browser" | "node" | "unknown" | "worker";
|
|
988
989
|
/**
|
|
989
990
|
* 判断当前运行时是否具有浏览器 `window` 与 `document`。
|
|
@@ -1008,7 +1009,7 @@ export declare function isNode(): boolean;
|
|
|
1008
1009
|
/**
|
|
1009
1010
|
* 判断当前运行时是否暴露 uni-app 的 `uni` 运行时对象。
|
|
1010
1011
|
*
|
|
1011
|
-
* @returns `uni`
|
|
1012
|
+
* @returns `uni` 标识符存在时返回 `true`;不调用任何平台 API。
|
|
1012
1013
|
*/
|
|
1013
1014
|
export declare function isUniApp(): boolean;
|
|
1014
1015
|
/**
|
|
@@ -1050,14 +1051,14 @@ export declare function isTabletUserAgent(userAgent?: string, maxTouchPoints?: n
|
|
|
1050
1051
|
* @remarks 首次成功返回后,后续调用返回同一结果;Promise 会保持引用不变。首次同步抛错时缓存错误,后续调用重新抛出同一错误。
|
|
1051
1052
|
* 包装函数使用首次调用时的参数和 `this`,之后传入的参数不会再次执行原函数。
|
|
1052
1053
|
* 首次调用尚未返回时同步重入会抛出 `Error`,不会重复执行原函数;该错误如向外传播,会作为首次错误缓存。
|
|
1053
|
-
* @param callback -
|
|
1054
|
-
* @returns
|
|
1054
|
+
* @param callback - 只允许执行一次的函数
|
|
1055
|
+
* @returns 保持原参数与返回类型的包装函数
|
|
1055
1056
|
* @throws `TypeError` 当 `callback` 不是函数。
|
|
1056
1057
|
*/
|
|
1057
1058
|
export declare function once<This, Arguments extends unknown[], Result>(callback: (this: This, ...arguments_: Arguments) => Result): (this: This, ...arguments_: Arguments) => Result;
|
|
1058
1059
|
//#endregion
|
|
1059
1060
|
//#region src/identity/index.d.ts
|
|
1060
|
-
/** {@link configureInstallationIdentity}
|
|
1061
|
+
/** {@link configureInstallationIdentity} 接收的安装标识配置 */
|
|
1061
1062
|
export interface InstallationIdentityConfiguration {
|
|
1062
1063
|
/**
|
|
1063
1064
|
* `Local` 中使用的业务键,默认 `identity:installation-id`。
|
|
@@ -1066,7 +1067,7 @@ export interface InstallationIdentityConfiguration {
|
|
|
1066
1067
|
*/
|
|
1067
1068
|
cacheKey?: string;
|
|
1068
1069
|
}
|
|
1069
|
-
/** 浏览器或 uni-app
|
|
1070
|
+
/** 浏览器或 uni-app 当前安装实例标识 */
|
|
1070
1071
|
export interface InstallationIdentity {
|
|
1071
1072
|
/**
|
|
1072
1073
|
* `Local` 中使用的业务键。
|
|
@@ -1126,39 +1127,39 @@ export declare const installationIdentity: InstallationIdentity;
|
|
|
1126
1127
|
* 返回已有安装标识,否则创建并持久化一个 UUID v4。
|
|
1127
1128
|
*
|
|
1128
1129
|
* @param installationId - 可选的显式安装标识;传入时会校验并覆盖当前持久化值。
|
|
1129
|
-
* @returns
|
|
1130
|
+
* @returns 显式值、内存值、持久化值或新生成值中的最终安装标识
|
|
1130
1131
|
* @throws `TypeError` 当显式值或持久化值不是 UUID v4。
|
|
1131
1132
|
* @throws `Error` 当当前平台存储不可用。
|
|
1132
1133
|
*/
|
|
1133
1134
|
export declare function getOrCreateInstallationId(installationId?: string): string;
|
|
1134
1135
|
//#endregion
|
|
1135
1136
|
//#region src/logger/index.d.ts
|
|
1136
|
-
/**
|
|
1137
|
+
/** 日志严重级别,按从低到高排列 */
|
|
1137
1138
|
export type LogLevel = "debug" | "log" | "warn" | "error";
|
|
1138
|
-
/**
|
|
1139
|
+
/** 日志输出目标需要实现的最小控制台接口 */
|
|
1139
1140
|
export interface LoggerSink {
|
|
1140
1141
|
/**
|
|
1141
1142
|
* 接收通过级别过滤后的调试参数。
|
|
1142
|
-
* @param data -
|
|
1143
|
+
* @param data - 已格式化的品牌、作用域、消息以及保持原始类型的附加值
|
|
1143
1144
|
*/
|
|
1144
1145
|
debug: (...data: unknown[]) => void;
|
|
1145
1146
|
/**
|
|
1146
1147
|
* 接收通过级别过滤后的普通日志参数;对应 Logger 的 `log` 级别。
|
|
1147
|
-
* @param data -
|
|
1148
|
+
* @param data - 已格式化的品牌、作用域、消息以及保持原始类型的附加值
|
|
1148
1149
|
*/
|
|
1149
1150
|
log: (...data: unknown[]) => void;
|
|
1150
1151
|
/**
|
|
1151
1152
|
* 接收通过级别过滤后的警告参数。
|
|
1152
|
-
* @param data -
|
|
1153
|
+
* @param data - 已格式化的品牌、作用域、消息以及保持原始类型的附加值
|
|
1153
1154
|
*/
|
|
1154
1155
|
warn: (...data: unknown[]) => void;
|
|
1155
1156
|
/**
|
|
1156
1157
|
* 接收通过级别过滤后的错误参数。
|
|
1157
|
-
* @param data -
|
|
1158
|
+
* @param data - 已格式化的品牌、作用域、消息以及保持原始类型的附加值
|
|
1158
1159
|
*/
|
|
1159
1160
|
error: (...data: unknown[]) => void;
|
|
1160
1161
|
}
|
|
1161
|
-
/** {@link createLogger}
|
|
1162
|
+
/** {@link createLogger} 的不可变配置 */
|
|
1162
1163
|
export interface LoggerOptions {
|
|
1163
1164
|
/** 最低输出级别,默认 `debug`;低于该优先级的消息不会传给 Sink。 */
|
|
1164
1165
|
level?: LogLevel;
|
|
@@ -1169,32 +1170,32 @@ export interface LoggerOptions {
|
|
|
1169
1170
|
/** uni-app App-Plus/HBuilderX 中把附加参数逐条转成单行文本输出,默认 `false`;其他平台忽略。 */
|
|
1170
1171
|
uniAppPlusSplit?: boolean;
|
|
1171
1172
|
}
|
|
1172
|
-
/**
|
|
1173
|
+
/** 配置隔离的轻量日志器 */
|
|
1173
1174
|
export interface Logger {
|
|
1174
1175
|
/**
|
|
1175
1176
|
* 输出指定作用域的调试信息或数据。
|
|
1176
|
-
* @param scope -
|
|
1177
|
+
* @param scope - 模块、组件或业务来源名称
|
|
1177
1178
|
* @param content - 可选的消息与附加值;非字符串值保持原始类型。
|
|
1178
1179
|
* @throws `TypeError` 或 `RangeError` 当作用域不是无外围空白的非空字符串。
|
|
1179
1180
|
*/
|
|
1180
1181
|
debug: (scope: string, ...content: unknown[]) => void;
|
|
1181
1182
|
/**
|
|
1182
1183
|
* 输出指定作用域的普通信息或数据。
|
|
1183
|
-
* @param scope -
|
|
1184
|
+
* @param scope - 模块、组件或业务来源名称
|
|
1184
1185
|
* @param content - 可选的消息与附加值;非字符串值保持原始类型。
|
|
1185
1186
|
* @throws `TypeError` 或 `RangeError` 当作用域不是无外围空白的非空字符串。
|
|
1186
1187
|
*/
|
|
1187
1188
|
log: (scope: string, ...content: unknown[]) => void;
|
|
1188
1189
|
/**
|
|
1189
1190
|
* 输出指定作用域的警告信息或数据。
|
|
1190
|
-
* @param scope -
|
|
1191
|
+
* @param scope - 模块、组件或业务来源名称
|
|
1191
1192
|
* @param content - 可选的消息与附加值;非字符串值保持原始类型。
|
|
1192
1193
|
* @throws `TypeError` 或 `RangeError` 当作用域不是无外围空白的非空字符串。
|
|
1193
1194
|
*/
|
|
1194
1195
|
warn: (scope: string, ...content: unknown[]) => void;
|
|
1195
1196
|
/**
|
|
1196
1197
|
* 输出指定作用域的错误信息或数据。
|
|
1197
|
-
* @param scope -
|
|
1198
|
+
* @param scope - 模块、组件或业务来源名称
|
|
1198
1199
|
* @param content - 可选的消息与附加值;非字符串值保持原始类型。
|
|
1199
1200
|
* @throws `TypeError` 或 `RangeError` 当作用域不是无外围空白的非空字符串。
|
|
1200
1201
|
*/
|
|
@@ -1205,7 +1206,7 @@ export interface Logger {
|
|
|
1205
1206
|
*
|
|
1206
1207
|
* @remarks 本库其他模块不会自动记录、吞掉或转换异常。日志内容可能进入持久化平台,
|
|
1207
1208
|
* 调用方不得传入密码、令牌、密钥或完整个人数据。
|
|
1208
|
-
* @param options - 级别、前缀、输出目标和 uni-app App-Plus
|
|
1209
|
+
* @param options - 级别、前缀、输出目标和 uni-app App-Plus 拆分选项
|
|
1209
1210
|
* @returns 不会修改全局控制台或其他日志器配置的新实例。
|
|
1210
1211
|
* @throws `RangeError` 当级别未知,或前缀、作用域不是有效的非空字符串。
|
|
1211
1212
|
*/
|
|
@@ -1222,21 +1223,21 @@ export declare function configureLogger(options?: LoggerOptions): void;
|
|
|
1222
1223
|
export declare const logger: Logger;
|
|
1223
1224
|
//#endregion
|
|
1224
1225
|
//#region src/number/index.d.ts
|
|
1225
|
-
/** {@link formatBytes}
|
|
1226
|
+
/** {@link formatBytes} 的格式化选项 */
|
|
1226
1227
|
export interface FormatBytesOptions {
|
|
1227
1228
|
/** 计量基数。`1000` 生成 SI 单位,`1024` 生成 IEC 单位;默认 `1024`。 */
|
|
1228
1229
|
base?: 1000 | 1024;
|
|
1229
|
-
/** 小数位数,范围 0 至 20;默认 `2
|
|
1230
|
+
/** 小数位数,范围 0 至 20;默认 `2` */
|
|
1230
1231
|
decimals?: number;
|
|
1231
|
-
/**
|
|
1232
|
+
/** 显式语言交给 Intl.NumberFormat;省略时内部按 en-US 数字格式输出。 */
|
|
1232
1233
|
locale?: string | readonly string[];
|
|
1233
1234
|
}
|
|
1234
1235
|
/**
|
|
1235
1236
|
* 把数字限制在闭区间内。
|
|
1236
1237
|
*
|
|
1237
|
-
* @param value -
|
|
1238
|
-
* @param minimum -
|
|
1239
|
-
* @param maximum -
|
|
1238
|
+
* @param value - 需要限制的数字
|
|
1239
|
+
* @param minimum - 闭区间下界
|
|
1240
|
+
* @param maximum - 闭区间上界
|
|
1240
1241
|
* @returns `minimum <= result <= maximum` 的值。
|
|
1241
1242
|
* @throws `RangeError` 当参数为 `NaN` 或下界大于上界。
|
|
1242
1243
|
*/
|
|
@@ -1244,9 +1245,9 @@ export declare function clamp(value: number, minimum: number, maximum: number):
|
|
|
1244
1245
|
/**
|
|
1245
1246
|
* 判断数字是否位于指定区间。
|
|
1246
1247
|
*
|
|
1247
|
-
* @param value -
|
|
1248
|
-
* @param minimum -
|
|
1249
|
-
* @param maximum -
|
|
1248
|
+
* @param value - 待检查数字
|
|
1249
|
+
* @param minimum - 包含的下界
|
|
1250
|
+
* @param maximum - 上界
|
|
1250
1251
|
* @param includeMaximum - 是否包含上界;默认使用半开区间 `[minimum, maximum)`。
|
|
1251
1252
|
* @returns 数字满足区间边界时返回 `true`。
|
|
1252
1253
|
* @throws `RangeError` 当参数为 `NaN` 或下界大于上界。
|
|
@@ -1256,16 +1257,16 @@ export declare function inRange(value: number, minimum: number, maximum: number,
|
|
|
1256
1257
|
* 按十进制位数四舍五入。
|
|
1257
1258
|
*
|
|
1258
1259
|
* @remarks IEEE-754 浮点数仍可能存在不可表示误差;财务金额应使用十进制定点方案。
|
|
1259
|
-
* @param value -
|
|
1260
|
+
* @param value - 有限数字
|
|
1260
1261
|
* @param digits - 小数位数;负数表示十位、百位等,范围 -15 至 15。
|
|
1261
|
-
* @returns 按 `Math.round`
|
|
1262
|
+
* @returns 按 `Math.round` 语义舍入后的数字
|
|
1262
1263
|
* @throws `RangeError` 当值非有限或位数超出范围。
|
|
1263
1264
|
*/
|
|
1264
1265
|
export declare function roundTo(value: number, digits?: number): number;
|
|
1265
1266
|
/**
|
|
1266
1267
|
* 对有限数字求和。
|
|
1267
1268
|
*
|
|
1268
|
-
* @param values -
|
|
1269
|
+
* @param values - 不会被修改的数字数组
|
|
1269
1270
|
* @returns 算术和;空数组返回 `0`。
|
|
1270
1271
|
* @throws `RangeError` 当任一值非有限或累计结果溢出。
|
|
1271
1272
|
*/
|
|
@@ -1273,7 +1274,7 @@ export declare function sum(values: readonly number[]): number;
|
|
|
1273
1274
|
/**
|
|
1274
1275
|
* 计算有限数字的算术平均值。
|
|
1275
1276
|
*
|
|
1276
|
-
* @param values -
|
|
1277
|
+
* @param values - 不会被修改的数字数组
|
|
1277
1278
|
* @returns 空数组或只有稀疏空位的数组返回 `undefined`;空位不参与分母。
|
|
1278
1279
|
* @throws `RangeError` 当任一值非有限。
|
|
1279
1280
|
*/
|
|
@@ -1282,19 +1283,21 @@ export declare function average(values: readonly number[]): number | undefined;
|
|
|
1282
1283
|
* 在两个数字间做线性插值。
|
|
1283
1284
|
*
|
|
1284
1285
|
* @remarks `amount` 不限制在 0 至 1;区间外的值会执行线性外推。
|
|
1285
|
-
* @param start - `amount = 0`
|
|
1286
|
-
* @param end - `amount = 1`
|
|
1287
|
-
* @param amount -
|
|
1288
|
-
* @returns
|
|
1286
|
+
* @param start - `amount = 0` 时的起点
|
|
1287
|
+
* @param end - `amount = 1` 时的终点
|
|
1288
|
+
* @param amount - 插值或外推比例
|
|
1289
|
+
* @returns 线性计算结果
|
|
1289
1290
|
* @throws `RangeError` 当任一参数非有限或结果超出有限数字范围。
|
|
1290
1291
|
*/
|
|
1291
1292
|
export declare function lerp(start: number, end: number, amount: number): number;
|
|
1292
1293
|
/**
|
|
1293
1294
|
* 将非负字节数格式化为 SI 或 IEC 单位。
|
|
1294
1295
|
*
|
|
1295
|
-
* @param bytes -
|
|
1296
|
-
* @param options -
|
|
1297
|
-
* @returns 例如 `1.5 KiB
|
|
1296
|
+
* @param bytes - 非负有限字节数
|
|
1297
|
+
* @param options - 基数、小数位和语言选项
|
|
1298
|
+
* @returns 例如 `1.5 KiB`
|
|
1299
|
+
* @remarks 默认数字格式使用内部实现;显式指定语言时使用 Intl.NumberFormat。
|
|
1300
|
+
* @throws `Error` 当显式指定语言且环境不支持 `Intl.NumberFormat`。
|
|
1298
1301
|
* @throws `RangeError` 当字节数为负或非有限、基数不是 1000/1024、小数位非法,或 Locale 无效。
|
|
1299
1302
|
*/
|
|
1300
1303
|
export declare function formatBytes(bytes: number, options?: FormatBytesOptions): string;
|
|
@@ -1302,9 +1305,9 @@ export declare function formatBytes(bytes: number, options?: FormatBytesOptions)
|
|
|
1302
1305
|
* 在半开区间内生成随机整数。
|
|
1303
1306
|
*
|
|
1304
1307
|
* @remarks 优先使用 Web Crypto;平台缺少安全随机能力时回退到 `Math.random()`。
|
|
1305
|
-
* @param minimum -
|
|
1308
|
+
* @param minimum - 包含的安全整数下界
|
|
1306
1309
|
* @param maximumExclusive - 不包含的安全整数上界;区间宽度最大为 2^32。
|
|
1307
|
-
* @returns 位于 `[minimum, maximumExclusive)`
|
|
1310
|
+
* @returns 位于 `[minimum, maximumExclusive)` 的随机整数
|
|
1308
1311
|
* @throws 参数非法时抛出 `RangeError`。
|
|
1309
1312
|
*/
|
|
1310
1313
|
export declare function randomInt(minimum: number, maximumExclusive: number): number;
|
|
@@ -1314,7 +1317,7 @@ export declare function randomInt(minimum: number, maximumExclusive: number): nu
|
|
|
1314
1317
|
export type QueryPrimitive = bigint | boolean | number | string | null | undefined;
|
|
1315
1318
|
/** URL 查询参数值;数组使用重复键表示。 */
|
|
1316
1319
|
export type QueryValue = QueryPrimitive | readonly QueryPrimitive[];
|
|
1317
|
-
/** {@link toQueryString}
|
|
1320
|
+
/** {@link toQueryString} 的序列化选项 */
|
|
1318
1321
|
export interface QueryStringOptions {
|
|
1319
1322
|
/** 返回非空结果时是否添加 `?`;默认 `false`。 */
|
|
1320
1323
|
prefixQuestionMark?: boolean;
|
|
@@ -1326,7 +1329,7 @@ export interface QueryStringOptions {
|
|
|
1326
1329
|
/**
|
|
1327
1330
|
* 判断值是否是普通对象。
|
|
1328
1331
|
*
|
|
1329
|
-
* @param value -
|
|
1332
|
+
* @param value - 任意待检查值
|
|
1330
1333
|
* @returns 原型为 `Object.prototype` 或 `null` 时返回 `true`。
|
|
1331
1334
|
*/
|
|
1332
1335
|
export declare function isPlainObject(value: unknown): value is Record<PropertyKey, unknown>;
|
|
@@ -1334,8 +1337,8 @@ export declare function isPlainObject(value: unknown): value is Record<PropertyK
|
|
|
1334
1337
|
* 安全判断对象是否拥有自己的属性。
|
|
1335
1338
|
*
|
|
1336
1339
|
* @remarks 不调用可能被对象覆盖的 `hasOwnProperty`。
|
|
1337
|
-
* @param value -
|
|
1338
|
-
* @param key - 字符串、数字或 Symbol
|
|
1340
|
+
* @param value - 待检查对象
|
|
1341
|
+
* @param key - 字符串、数字或 Symbol 属性键
|
|
1339
1342
|
* @returns 属性为对象自有属性时返回 `true`,并收窄键类型。
|
|
1340
1343
|
*/
|
|
1341
1344
|
export declare function hasOwn<ObjectType extends object, Key extends PropertyKey>(value: ObjectType, key: Key): key is Key & keyof ObjectType;
|
|
@@ -1344,7 +1347,7 @@ export declare function hasOwn<ObjectType extends object, Key extends PropertyKe
|
|
|
1344
1347
|
*
|
|
1345
1348
|
* @remarks 支持循环引用、共享引用、Symbol 键、对象原型、ArrayBuffer、DataView、Date、Map、RegExp、Set 和 TypedArray。
|
|
1346
1349
|
* Map 的键保持原引用,函数及其他不可克隆值在嵌套位置保持原引用;只复制自有可枚举属性。
|
|
1347
|
-
* @param value -
|
|
1350
|
+
* @param value - 需要深复制的任意值
|
|
1348
1351
|
* @returns 与输入类型一致且不共享可克隆嵌套值的新值;原始类型直接返回自身。
|
|
1349
1352
|
*/
|
|
1350
1353
|
export declare function cloneDeep<Value>(value: Value): Value;
|
|
@@ -1353,8 +1356,8 @@ export declare function cloneDeep<Value>(value: Value): Value;
|
|
|
1353
1356
|
*
|
|
1354
1357
|
* @remarks 原始值使用 SameValueZero 语义;支持循环引用、数组、对象、ArrayBuffer、DataView、Date、Error、Map、RegExp、Set、Symbol 和 TypedArray。
|
|
1355
1358
|
* 对象只比较自有可枚举字符串与 Symbol 属性,函数及其他不支持的宿主对象仅在引用相同时相等。
|
|
1356
|
-
* @param left -
|
|
1357
|
-
* @param right -
|
|
1359
|
+
* @param left - 第一待比较值
|
|
1360
|
+
* @param right - 第二待比较值
|
|
1358
1361
|
* @returns 两个值深度等价时返回 `true`。
|
|
1359
1362
|
*/
|
|
1360
1363
|
export declare function isEqual(left: unknown, right: unknown): boolean;
|
|
@@ -1362,7 +1365,7 @@ export declare function isEqual(left: unknown, right: unknown): boolean;
|
|
|
1362
1365
|
* 从对象中选择指定自有可枚举属性。
|
|
1363
1366
|
*
|
|
1364
1367
|
* @remarks 固定键元组保留精确返回类型;动态数组中可能被选择或排除的键在返回类型中保持可选。
|
|
1365
|
-
* @param source -
|
|
1368
|
+
* @param source - 不会被修改的源对象
|
|
1366
1369
|
* @param keys - 需要保留的键;不存在的键被忽略。
|
|
1367
1370
|
* @returns 新对象,保持 `keys` 的遍历顺序。
|
|
1368
1371
|
*/
|
|
@@ -1372,42 +1375,42 @@ export declare function pick<Source extends object>(source: Source, keys: readon
|
|
|
1372
1375
|
* 浅复制对象并删除指定属性。
|
|
1373
1376
|
*
|
|
1374
1377
|
* @remarks 固定键元组保留精确返回类型;动态数组中可能被选择或排除的键在返回类型中保持可选。
|
|
1375
|
-
* @param source -
|
|
1376
|
-
* @param keys -
|
|
1377
|
-
* @returns 包含其余自有可枚举字符串与 Symbol
|
|
1378
|
+
* @param source - 不会被修改的源对象
|
|
1379
|
+
* @param keys - 需要排除的键
|
|
1380
|
+
* @returns 包含其余自有可枚举字符串与 Symbol 属性的新对象
|
|
1378
1381
|
*/
|
|
1379
1382
|
export declare function omit<Source extends object, const Keys extends readonly (keyof Source)[]>(source: Source, keys: Keys): number extends Keys["length"] ? Omit<Source, Keys[number]> & Partial<Pick<Source, Keys[number]>> : Omit<Source, Keys[number]>;
|
|
1380
1383
|
export declare function omit<Source extends object>(source: Source, keys: readonly PropertyKey[]): Partial<Source>;
|
|
1381
1384
|
/**
|
|
1382
1385
|
* 按条件排除对象的自有可枚举属性。
|
|
1383
1386
|
*
|
|
1384
|
-
* @param source -
|
|
1387
|
+
* @param source - 不会被修改的源对象
|
|
1385
1388
|
* @param predicate - 接收属性值、键和源对象;返回真值时排除该属性。
|
|
1386
|
-
* @returns
|
|
1389
|
+
* @returns 由未匹配属性组成的新对象
|
|
1387
1390
|
*/
|
|
1388
1391
|
export declare function omitBy<Source extends object>(source: Source, predicate: (value: Source[keyof Source], key: keyof Source, source: Source) => unknown): Partial<Source>;
|
|
1389
1392
|
/**
|
|
1390
1393
|
* 按条件选择对象的自有可枚举属性。
|
|
1391
1394
|
*
|
|
1392
|
-
* @param source -
|
|
1395
|
+
* @param source - 不会被修改的源对象
|
|
1393
1396
|
* @param predicate - 接收属性值、键和源对象;返回真值时保留该属性。
|
|
1394
|
-
* @returns
|
|
1397
|
+
* @returns 由匹配属性组成的新对象
|
|
1395
1398
|
*/
|
|
1396
1399
|
export declare function pickBy<Source extends object>(source: Source, predicate: (value: Source[keyof Source], key: keyof Source, source: Source) => unknown): Partial<Source>;
|
|
1397
1400
|
/**
|
|
1398
1401
|
* 映射对象的自有可枚举属性值。
|
|
1399
1402
|
*
|
|
1400
|
-
* @param source -
|
|
1401
|
-
* @param mapper -
|
|
1402
|
-
* @returns
|
|
1403
|
+
* @param source - 不会被修改的源对象
|
|
1404
|
+
* @param mapper - 接收值、键和源对象的映射函数
|
|
1405
|
+
* @returns 保留原键的新对象
|
|
1403
1406
|
*/
|
|
1404
1407
|
export declare function mapValues<Source extends object, Result>(source: Source, mapper: (value: Source[keyof Source], key: keyof Source, source: Source) => Result): { [Key in keyof Source]: Result; };
|
|
1405
1408
|
/**
|
|
1406
1409
|
* 对自有可枚举属性执行 SameValue 浅比较。
|
|
1407
1410
|
*
|
|
1408
1411
|
* @remarks 嵌套对象只比较引用;`NaN` 相等,`0` 与 `-0` 不相等。
|
|
1409
|
-
* @param left -
|
|
1410
|
-
* @param right -
|
|
1412
|
+
* @param left - 第一对象
|
|
1413
|
+
* @param right - 第二对象
|
|
1411
1414
|
* @returns 自有可枚举键集合与对应值均满足 SameValue 时返回 `true`。
|
|
1412
1415
|
*/
|
|
1413
1416
|
export declare function shallowEqual(left: object, right: object): boolean;
|
|
@@ -1415,27 +1418,28 @@ export declare function shallowEqual(left: object, right: object): boolean;
|
|
|
1415
1418
|
* 将对象序列化为标准 URL 查询字符串。
|
|
1416
1419
|
*
|
|
1417
1420
|
* @remarks `null` 与 `undefined` 被跳过;数组使用重复键;返回值不会修改输入。
|
|
1418
|
-
* @param value -
|
|
1419
|
-
* @param options -
|
|
1421
|
+
* @param value - 查询参数对象
|
|
1422
|
+
* @param options - 排序、空格和问号前缀选项
|
|
1420
1423
|
* @returns URL 编码后的查询字符串;没有参数时始终返回空字符串。
|
|
1421
1424
|
* @throws `RangeError` 当参数包含 `NaN` 或无穷数字。
|
|
1425
|
+
* @throws `URIError` 当键或值包含孤立的 UTF-16 代理项。
|
|
1422
1426
|
*/
|
|
1423
1427
|
export declare function toQueryString(value: Readonly<Record<string, QueryValue>>, options?: QueryStringOptions): string;
|
|
1424
1428
|
//#endregion
|
|
1425
1429
|
//#region src/storage/index.d.ts
|
|
1426
|
-
/** Storage
|
|
1430
|
+
/** Storage 业务值编码器 */
|
|
1427
1431
|
export interface StorageCodec {
|
|
1428
1432
|
/**
|
|
1429
1433
|
* 把已编码文本恢复为业务值。
|
|
1430
|
-
* @param value - 由同一 Codec 的 `encode`
|
|
1431
|
-
* @returns
|
|
1434
|
+
* @param value - 由同一 Codec 的 `encode` 生成并持久化的文本
|
|
1435
|
+
* @returns 解码后的业务值
|
|
1432
1436
|
* @throws 当文本损坏、格式不受支持或无法反序列化时应抛出错误。
|
|
1433
1437
|
*/
|
|
1434
1438
|
decode: (value: string) => unknown;
|
|
1435
1439
|
/**
|
|
1436
1440
|
* 把业务值编码为可持久化字符串。
|
|
1437
|
-
* @param value -
|
|
1438
|
-
* @returns 可由同一 Codec 的 `decode`
|
|
1441
|
+
* @param value - 调用方传入的业务值
|
|
1442
|
+
* @returns 可由同一 Codec 的 `decode` 无损恢复的文本
|
|
1439
1443
|
* @throws 当值不受支持或无法序列化时应抛出错误。
|
|
1440
1444
|
*/
|
|
1441
1445
|
encode: (value: unknown) => string;
|
|
@@ -1451,7 +1455,7 @@ export interface StorageConfiguration {
|
|
|
1451
1455
|
/** 所有物理键使用的非空命名空间前缀,默认 `fast__`。 */
|
|
1452
1456
|
prefix?: string;
|
|
1453
1457
|
}
|
|
1454
|
-
/** 单次 Storage
|
|
1458
|
+
/** 单次 Storage 读取配置 */
|
|
1455
1459
|
export interface StorageReadOptions {
|
|
1456
1460
|
/**
|
|
1457
1461
|
* 仅覆盖本次读取使用的 Codec;`true` 使用 Base64 混淆,`false` 使用 JSON,省略时使用全局配置。
|
|
@@ -1459,12 +1463,12 @@ export interface StorageReadOptions {
|
|
|
1459
1463
|
*/
|
|
1460
1464
|
crypto?: boolean;
|
|
1461
1465
|
}
|
|
1462
|
-
/** 单次 Storage
|
|
1466
|
+
/** 单次 Storage 写入配置 */
|
|
1463
1467
|
export interface StorageWriteOptions extends StorageReadOptions {
|
|
1464
1468
|
/** 从写入时刻开始的有效毫秒数;必须是大于 0 的有限数,省略时永久有效。 */
|
|
1465
1469
|
ttlMs?: number;
|
|
1466
1470
|
}
|
|
1467
|
-
/** `Local` 与 `Session`
|
|
1471
|
+
/** `Local` 与 `Session` 的统一操作接口 */
|
|
1468
1472
|
export interface StorageArea {
|
|
1469
1473
|
/** 当前全局 Storage 配置的物理键前缀;首次读取会激活默认配置。 */
|
|
1470
1474
|
readonly prefix: string;
|
|
@@ -1475,7 +1479,7 @@ export interface StorageArea {
|
|
|
1475
1479
|
clear: () => void;
|
|
1476
1480
|
/**
|
|
1477
1481
|
* 获取并解码业务值;已过期记录会在读取时删除。
|
|
1478
|
-
* @param key -
|
|
1482
|
+
* @param key - 不含全局前缀的非空业务键
|
|
1479
1483
|
* @param options - 可选的单次 Base64 混淆开关;必须与写入时一致。
|
|
1480
1484
|
* @returns 解码后的值;未传泛型时静态类型默认为 `string`,键缺失或过期时返回 `undefined`。
|
|
1481
1485
|
* @throws 当键非法、包络损坏、Codec 解码失败或后端不可用时抛出错误。
|
|
@@ -1483,7 +1487,7 @@ export interface StorageArea {
|
|
|
1483
1487
|
get: <Value = string>(key: string, options?: StorageReadOptions) => Value | undefined;
|
|
1484
1488
|
/**
|
|
1485
1489
|
* 判断业务键是否具有有效且未过期的包络;不解码业务值。
|
|
1486
|
-
* @param key -
|
|
1490
|
+
* @param key - 不含全局前缀的非空业务键
|
|
1487
1491
|
* @returns 键存在且包络有效时返回 `true`。
|
|
1488
1492
|
*/
|
|
1489
1493
|
has: (key: string) => boolean;
|
|
@@ -1494,25 +1498,25 @@ export interface StorageArea {
|
|
|
1494
1498
|
keys: () => string[];
|
|
1495
1499
|
/**
|
|
1496
1500
|
* 扫描当前命名空间并删除全部过期记录。
|
|
1497
|
-
* @returns
|
|
1501
|
+
* @returns 本次实际删除的记录数量
|
|
1498
1502
|
* @throws 当发现损坏包络或后端不可用时抛出错误。
|
|
1499
1503
|
*/
|
|
1500
1504
|
pruneExpired: () => number;
|
|
1501
1505
|
/**
|
|
1502
1506
|
* 删除单个业务键;键不存在时保持幂等。
|
|
1503
|
-
* @param key -
|
|
1507
|
+
* @param key - 不含全局前缀的非空业务键
|
|
1504
1508
|
*/
|
|
1505
1509
|
remove: (key: string) => void;
|
|
1506
1510
|
/**
|
|
1507
1511
|
* 删除业务键以指定文本开头的全部条目,范围仍受全局命名空间限制。
|
|
1508
|
-
* @param keyPrefix -
|
|
1512
|
+
* @param keyPrefix - 不含全局前缀的非空业务键前缀
|
|
1509
1513
|
*/
|
|
1510
1514
|
removeByPrefix: (keyPrefix: string) => void;
|
|
1511
1515
|
/**
|
|
1512
1516
|
* 编码并写入业务值,可附加惰性清理的 TTL。
|
|
1513
|
-
* @param key -
|
|
1514
|
-
* @param value - 必须受当前 Codec
|
|
1515
|
-
* @param options - 可选的单次写入 TTL 与 Base64
|
|
1517
|
+
* @param key - 不含全局前缀的非空业务键
|
|
1518
|
+
* @param value - 必须受当前 Codec 支持的业务值
|
|
1519
|
+
* @param options - 可选的单次写入 TTL 与 Base64 混淆开关
|
|
1516
1520
|
* @throws 当键、TTL、业务值或后端写入无效时抛出错误。
|
|
1517
1521
|
*/
|
|
1518
1522
|
set: <Value>(key: string, value: Value, options?: StorageWriteOptions) => void;
|
|
@@ -1539,14 +1543,14 @@ export declare function isStorageConfigured(): boolean;
|
|
|
1539
1543
|
//#region src/string/index.d.ts
|
|
1540
1544
|
/** 查询字符串解析结果;重复键保留为数组,不存在的键读取为 `undefined`。 */
|
|
1541
1545
|
export type ParsedQueryParameters = Record<string, string | string[] | undefined>;
|
|
1542
|
-
/**
|
|
1546
|
+
/** 大小写与字素分割可接受的显式语言;省略时大小写转换使用标准 Unicode 规则,字素分割固定使用 `en-US`。 */
|
|
1543
1547
|
export type StringLocale = string | readonly string[] | undefined;
|
|
1544
1548
|
/**
|
|
1545
1549
|
* 重复执行 URI 组件解码,直到值稳定或达到深度上限。
|
|
1546
1550
|
*
|
|
1547
|
-
* @param value - 不包含 URI
|
|
1548
|
-
* @param maxDepth - 最大解码次数,默认 `10
|
|
1549
|
-
* @returns
|
|
1551
|
+
* @param value - 不包含 URI 路径语义的编码组件
|
|
1552
|
+
* @param maxDepth - 最大解码次数,默认 `10`
|
|
1553
|
+
* @returns 解码稳定或达到上限后的组件文本
|
|
1550
1554
|
* @throws `URIError` 当任一层包含非法百分号序列;深度非法时抛出 `RangeError`。
|
|
1551
1555
|
*/
|
|
1552
1556
|
export declare function decodeURIComponentRepeatedly(value: string, maxDepth?: number): string;
|
|
@@ -1554,8 +1558,9 @@ export declare function decodeURIComponentRepeatedly(value: string, maxDepth?: n
|
|
|
1554
1558
|
* 解析带 `://` 的绝对 URL、`?query` 或纯查询字符串。
|
|
1555
1559
|
*
|
|
1556
1560
|
* @remarks 纯查询字符串值中的未编码 `?` 会作为值内容保留;片段标识及其后内容被忽略。
|
|
1557
|
-
* @param input - 完整 URL
|
|
1561
|
+
* @param input - 完整 URL、带前导问号或不带前导问号的查询文本
|
|
1558
1562
|
* @returns 重复键对应字符串数组,空值保留为空字符串。
|
|
1563
|
+
* @throws `URIError` 当键或值包含非法百分号编码或无效的 UTF-8 字节序列。
|
|
1559
1564
|
*/
|
|
1560
1565
|
export declare function parseQueryString(input: string): ParsedQueryParameters;
|
|
1561
1566
|
/**
|
|
@@ -1569,57 +1574,57 @@ export declare function isValidJson(value: string): boolean;
|
|
|
1569
1574
|
* 按大小写边界、连字符、下划线与空白切分单词。
|
|
1570
1575
|
*
|
|
1571
1576
|
* @example `XMLHttp_request` 返回 `["XML", "Http", "request"]`。
|
|
1572
|
-
* @param value -
|
|
1573
|
-
* @returns
|
|
1577
|
+
* @param value - 待拆分文本
|
|
1578
|
+
* @returns 删除空项、保持输入顺序的单词数组
|
|
1574
1579
|
*/
|
|
1575
1580
|
export declare function splitWords(value: string): string[];
|
|
1576
1581
|
/**
|
|
1577
1582
|
* 将首个 Unicode 码点转为大写。
|
|
1578
1583
|
*
|
|
1579
1584
|
* @param value - 输入文本;空字符串保持为空。
|
|
1580
|
-
* @param locale -
|
|
1581
|
-
* @returns 首个 Unicode
|
|
1585
|
+
* @param locale - 显式语言;省略时使用标准 Unicode 大小写规则。
|
|
1586
|
+
* @returns 首个 Unicode 码点转换后的文本
|
|
1582
1587
|
*/
|
|
1583
1588
|
export declare function upperFirst(value: string, locale?: StringLocale): string;
|
|
1584
1589
|
/**
|
|
1585
1590
|
* 将首个 Unicode 码点转为小写。
|
|
1586
1591
|
*
|
|
1587
1592
|
* @param value - 输入文本;空字符串保持为空。
|
|
1588
|
-
* @param locale -
|
|
1589
|
-
* @returns 首个 Unicode
|
|
1593
|
+
* @param locale - 显式语言;省略时使用标准 Unicode 大小写规则。
|
|
1594
|
+
* @returns 首个 Unicode 码点转换后的文本
|
|
1590
1595
|
*/
|
|
1591
1596
|
export declare function lowerFirst(value: string, locale?: StringLocale): string;
|
|
1592
1597
|
/**
|
|
1593
1598
|
* 将文本转换为 camelCase。
|
|
1594
1599
|
*
|
|
1595
|
-
* @param value -
|
|
1596
|
-
* @param locale -
|
|
1597
|
-
* @returns camelCase
|
|
1600
|
+
* @param value - 由大小写、连字符、下划线或空白分隔的文本
|
|
1601
|
+
* @param locale - 大小写转换使用的语言;省略时使用标准 Unicode 大小写规则。
|
|
1602
|
+
* @returns camelCase 文本
|
|
1598
1603
|
*/
|
|
1599
1604
|
export declare function camelCase(value: string, locale?: StringLocale): string;
|
|
1600
1605
|
/**
|
|
1601
1606
|
* 将文本转换为 PascalCase。
|
|
1602
1607
|
*
|
|
1603
1608
|
* @param value - 参数语义与 {@link camelCase} 一致。
|
|
1604
|
-
* @param locale -
|
|
1605
|
-
* @returns PascalCase
|
|
1609
|
+
* @param locale - 大小写转换使用的显式语言
|
|
1610
|
+
* @returns PascalCase 文本
|
|
1606
1611
|
*/
|
|
1607
1612
|
export declare function pascalCase(value: string, locale?: StringLocale): string;
|
|
1608
1613
|
/**
|
|
1609
1614
|
* 将文本转换为 kebab-case。
|
|
1610
1615
|
*
|
|
1611
1616
|
* @param value - 参数语义与 {@link camelCase} 一致。
|
|
1612
|
-
* @param locale -
|
|
1613
|
-
* @returns kebab-case
|
|
1617
|
+
* @param locale - 大小写转换使用的显式语言
|
|
1618
|
+
* @returns kebab-case 文本
|
|
1614
1619
|
*/
|
|
1615
1620
|
export declare function kebabCase(value: string, locale?: StringLocale): string;
|
|
1616
1621
|
/**
|
|
1617
1622
|
* 按 Unicode 字素簇截断文本,避免拆开 emoji、组合音标或代理对。
|
|
1618
1623
|
*
|
|
1619
|
-
* @param value -
|
|
1620
|
-
* @param maxLength -
|
|
1624
|
+
* @param value - 输入文本
|
|
1625
|
+
* @param maxLength - 保留的最大字素簇数量
|
|
1621
1626
|
* @param suffix - 被截断时追加的文本,默认单字符省略号 `…`;不计入上限。
|
|
1622
|
-
* @param locale - 字素分割语言,默认固定为 `en-US
|
|
1627
|
+
* @param locale - 字素分割语言,默认固定为 `en-US`
|
|
1623
1628
|
* @returns 未超限时返回原字符串,否则返回截断内容与后缀。
|
|
1624
1629
|
* @throws `RangeError` 当 `maxLength` 不是非负安全整数或 Locale 无效;缺少
|
|
1625
1630
|
* `Intl.Segmenter` 时抛出 `Error`。
|
|
@@ -1630,8 +1635,8 @@ export declare function truncateGraphemes(value: string, maxLength: number, suff
|
|
|
1630
1635
|
*
|
|
1631
1636
|
* @remarks uni-app 使用 `setClipboardData`;浏览器优先使用 Clipboard API,并在该 API 不可用时
|
|
1632
1637
|
* 回退到 `document.execCommand("copy")`。平台拒绝访问剪贴板时不会静默忽略错误。
|
|
1633
|
-
* @param value -
|
|
1634
|
-
* @returns 复制完成后兑现的 Promise
|
|
1638
|
+
* @param value - 要复制的文本
|
|
1639
|
+
* @returns 复制完成后兑现的 Promise
|
|
1635
1640
|
* @throws `Error` 当运行时没有可用的剪贴板能力或复制失败。
|
|
1636
1641
|
*/
|
|
1637
1642
|
export declare function copy(value: string): Promise<void>;
|
|
@@ -1641,7 +1646,7 @@ export declare function copy(value: string): Promise<void>;
|
|
|
1641
1646
|
* @remarks 优先使用 Web Crypto;平台缺少安全随机能力时回退到 `Math.random()`。
|
|
1642
1647
|
* @param length - 字符数量,必须是 0 至 1,000,000 的安全整数。
|
|
1643
1648
|
* @param alphabet - 不得为空、包含重复字符或超过 2^32 个 Unicode 码点。
|
|
1644
|
-
* @returns 由 `alphabet` 中 Unicode
|
|
1649
|
+
* @returns 由 `alphabet` 中 Unicode 码点组成的随机文本
|
|
1645
1650
|
* @throws `RangeError` 当长度或字母表非法。
|
|
1646
1651
|
*/
|
|
1647
1652
|
export declare function randomString(length: number, alphabet?: string): string;
|
|
@@ -1650,7 +1655,7 @@ export declare function randomString(length: number, alphabet?: string): string;
|
|
|
1650
1655
|
*
|
|
1651
1656
|
* @remarks 优先使用 Web Crypto;平台缺少安全随机能力时回退到 `Math.random()`。
|
|
1652
1657
|
* 该 UUID 适合普通唯一标识,不应作为安全令牌或秘密。
|
|
1653
|
-
* @returns 小写、带连字符的 UUID v4
|
|
1658
|
+
* @returns 小写、带连字符的 UUID v4
|
|
1654
1659
|
*/
|
|
1655
1660
|
export declare function generateUuidV4(): string;
|
|
1656
1661
|
/**
|
|
@@ -1664,20 +1669,20 @@ export declare function isUuidV4(value: string): boolean;
|
|
|
1664
1669
|
* 转义 HTML 文本上下文中的五个特殊字符。
|
|
1665
1670
|
*
|
|
1666
1671
|
* @remarks 这不是 HTML 清洗器,不能让不可信文本安全进入 URL、CSS、脚本或属性名上下文。
|
|
1667
|
-
* @param value - 将作为 HTML
|
|
1668
|
-
* @returns 转义
|
|
1672
|
+
* @param value - 将作为 HTML 文本节点内容的字符串
|
|
1673
|
+
* @returns 转义 `&`、`<`、`>`、双引号与单引号后的文本
|
|
1669
1674
|
*/
|
|
1670
1675
|
export declare function escapeHtml(value: string): string;
|
|
1671
1676
|
/**
|
|
1672
1677
|
* 把连续 Unicode 空白折叠为单个空格并删除两端空白。
|
|
1673
1678
|
*
|
|
1674
|
-
* @param value -
|
|
1679
|
+
* @param value - 输入文本
|
|
1675
1680
|
* @returns 规范化后的文本;全空白输入返回空字符串。
|
|
1676
1681
|
*/
|
|
1677
1682
|
export declare function normalizeWhitespace(value: string): string;
|
|
1678
1683
|
//#endregion
|
|
1679
1684
|
//#region src/vue/breakpoints.d.ts
|
|
1680
|
-
/**
|
|
1685
|
+
/** 断点名称与最小视口宽度的映射 */
|
|
1681
1686
|
export type Breakpoints<Key extends string = string> = Readonly<Record<Key, number>>;
|
|
1682
1687
|
/** `useBreakpoints` 返回的断点状态。 */
|
|
1683
1688
|
export type UseBreakpointsReturn<Key extends string> = Readonly<Record<Key, Readonly<ShallowRef<boolean>>>> & {
|
|
@@ -1687,8 +1692,8 @@ export type UseBreakpointsReturn<Key extends string> = Readonly<Record<Key, Read
|
|
|
1687
1692
|
/**
|
|
1688
1693
|
* 使用原生 Media Query 创建响应式最小宽度断点。
|
|
1689
1694
|
*
|
|
1690
|
-
* @param breakpoints -
|
|
1691
|
-
* @returns
|
|
1695
|
+
* @param breakpoints - 断点名称与非负像素宽度的映射
|
|
1696
|
+
* @returns 每个断点的只读状态和当前最大命中断点
|
|
1692
1697
|
* @throws `Error` 当浏览器环境中不存在可用于自动清理的 Vue 响应式作用域。
|
|
1693
1698
|
* @throws `TypeError` 当断点使用保留名称 `active`。
|
|
1694
1699
|
* @throws `RangeError` 当断点宽度不是非负有限数值。
|
|
@@ -1696,20 +1701,20 @@ export type UseBreakpointsReturn<Key extends string> = Readonly<Record<Key, Read
|
|
|
1696
1701
|
export declare function useBreakpoints<Key extends string>(breakpoints: Breakpoints<Key>): UseBreakpointsReturn<Key>;
|
|
1697
1702
|
//#endregion
|
|
1698
1703
|
//#region src/vue/resize-observer.d.ts
|
|
1699
|
-
/** `useResizeObserver`
|
|
1704
|
+
/** `useResizeObserver` 接受的元素或响应式元素 */
|
|
1700
1705
|
export type ResizeObserverTarget = MaybeRefOrGetter<Element | null | undefined>;
|
|
1701
1706
|
/**
|
|
1702
1707
|
* 监听元素尺寸变化,并随响应式目标切换和 Vue 作用域销毁自动断开。
|
|
1703
1708
|
*
|
|
1704
|
-
* @param target - 原生元素、Ref 或 Getter
|
|
1705
|
-
* @param callback - 原生 ResizeObserver
|
|
1706
|
-
* @param options -
|
|
1709
|
+
* @param target - 原生元素、Ref 或 Getter
|
|
1710
|
+
* @param callback - 原生 ResizeObserver 回调
|
|
1711
|
+
* @param options - 原生元素观察选项
|
|
1707
1712
|
* @returns 可提前断开观察的停止函数;运行时不支持 ResizeObserver 时为空操作。
|
|
1708
1713
|
*/
|
|
1709
1714
|
export declare function useResizeObserver(target: ResizeObserverTarget, callback: ResizeObserverCallback, options?: ResizeObserverOptions): () => void;
|
|
1710
1715
|
//#endregion
|
|
1711
1716
|
//#region src/vue/element-size.d.ts
|
|
1712
|
-
/**
|
|
1717
|
+
/** 元素的二维尺寸 */
|
|
1713
1718
|
export interface ElementSize {
|
|
1714
1719
|
readonly width: number;
|
|
1715
1720
|
readonly height: number;
|
|
@@ -1723,45 +1728,45 @@ export interface UseElementSizeReturn {
|
|
|
1723
1728
|
/**
|
|
1724
1729
|
* 响应式读取元素 Content Rect 尺寸。
|
|
1725
1730
|
*
|
|
1726
|
-
* @param target - 原生元素、Ref 或 Getter
|
|
1727
|
-
* @param initialSize - 收到首次观察结果前的尺寸,默认均为 `0
|
|
1728
|
-
* @param options -
|
|
1729
|
-
* @returns
|
|
1731
|
+
* @param target - 原生元素、Ref 或 Getter
|
|
1732
|
+
* @param initialSize - 收到首次观察结果前的尺寸,默认均为 `0`
|
|
1733
|
+
* @param options - 原生元素观察选项
|
|
1734
|
+
* @returns 只读宽度、高度和手动停止函数
|
|
1730
1735
|
*/
|
|
1731
1736
|
export declare function useElementSize(target: ResizeObserverTarget, initialSize?: ElementSize, options?: ResizeObserverOptions): UseElementSizeReturn;
|
|
1732
1737
|
//#endregion
|
|
1733
1738
|
//#region src/vue/emits.d.ts
|
|
1734
|
-
/** Vue Emits
|
|
1739
|
+
/** Vue Emits 对象中允许的校验器形状 */
|
|
1735
1740
|
type EmitValidator = ((...arguments_: never[]) => unknown) | null;
|
|
1736
|
-
/**
|
|
1741
|
+
/** 事件名到可选参数校验器的内部映射 */
|
|
1737
1742
|
type EmitsOptions = Record<string, EmitValidator>;
|
|
1738
1743
|
/** 从校验器中提取事件参数;无校验器时保留未知参数。 */
|
|
1739
1744
|
type EventArguments<Validator> = Validator extends ((...arguments_: infer Arguments) => unknown) ? Arguments : unknown[];
|
|
1740
|
-
/** 在类型层递归把 kebab-case 事件名转换为 PascalCase
|
|
1745
|
+
/** 在类型层递归把 kebab-case 事件名转换为 PascalCase */
|
|
1741
1746
|
type PascalEventName<Value extends string> = Value extends `${infer Head}-${infer Tail}` ? `${Capitalize<Head>}${PascalEventName<Tail>}` : Capitalize<Value>;
|
|
1742
|
-
/** 把事件配置映射为 Vue `onXxx`
|
|
1747
|
+
/** 把事件配置映射为 Vue `onXxx` 属性 */
|
|
1743
1748
|
export type EmitHandlers<Emits extends EmitsOptions> = { [Name in keyof Emits as Name extends string ? `on${PascalEventName<Name>}` : never]: (...arguments_: EventArguments<Emits[Name]>) => void; };
|
|
1744
1749
|
/**
|
|
1745
1750
|
* 构建响应式 Vue 事件处理器。
|
|
1746
1751
|
*
|
|
1747
|
-
* @param emits - Vue emits
|
|
1748
|
-
* @param emit - `setup` 上下文提供的 emit
|
|
1749
|
-
* @param ignoredEvents -
|
|
1750
|
-
* @returns
|
|
1752
|
+
* @param emits - Vue emits 配置对象
|
|
1753
|
+
* @param emit - `setup` 上下文提供的 emit 函数
|
|
1754
|
+
* @param ignoredEvents - 不需要向子组件透传的事件名
|
|
1755
|
+
* @returns 随配置重新计算的事件处理器对象
|
|
1751
1756
|
*/
|
|
1752
1757
|
export declare function useEmits<Emits extends EmitsOptions>(emits: Emits, emit: (...arguments_: never[]) => unknown, ignoredEvents?: readonly (keyof Emits)[]): ComputedRef<Partial<EmitHandlers<Emits>>>;
|
|
1753
1758
|
//#endregion
|
|
1754
1759
|
//#region src/vue/event-listener.d.ts
|
|
1755
|
-
/** `useEventListener`
|
|
1760
|
+
/** `useEventListener` 接受的原生事件目标或响应式事件目标 */
|
|
1756
1761
|
export type EventTargetSource = MaybeRefOrGetter<EventTarget | null | undefined>;
|
|
1757
1762
|
/**
|
|
1758
1763
|
* 注册原生事件监听器,并在目标变化或 Vue 作用域销毁时自动移除。
|
|
1759
1764
|
*
|
|
1760
|
-
* @param target - 原生事件目标、Ref 或 Getter
|
|
1761
|
-
* @param event -
|
|
1762
|
-
* @param listener -
|
|
1763
|
-
* @param options -
|
|
1764
|
-
* @returns
|
|
1765
|
+
* @param target - 原生事件目标、Ref 或 Getter
|
|
1766
|
+
* @param event - 原生事件名称
|
|
1767
|
+
* @param listener - 事件回调
|
|
1768
|
+
* @param options - 原生事件监听选项
|
|
1769
|
+
* @returns 可提前移除监听器的停止函数
|
|
1765
1770
|
*/
|
|
1766
1771
|
export declare function useEventListener<EventType extends Event = Event>(target: EventTargetSource, event: string, listener: (event: EventType) => void, options?: boolean | AddEventListenerOptions): () => void;
|
|
1767
1772
|
//#endregion
|
|
@@ -1769,9 +1774,9 @@ export declare function useEventListener<EventType extends Event = Event>(target
|
|
|
1769
1774
|
/**
|
|
1770
1775
|
* 同时暴露组件实例能力并返回同一个对象,便于 `setup` 返回状态供 Vue Devtools 查看。
|
|
1771
1776
|
*
|
|
1772
|
-
* @param expose - `setup` 上下文提供的 expose
|
|
1773
|
-
* @param exposed -
|
|
1774
|
-
* @returns 原始 exposed
|
|
1777
|
+
* @param expose - `setup` 上下文提供的 expose 函数
|
|
1778
|
+
* @param exposed - 需要暴露的状态和方法
|
|
1779
|
+
* @returns 原始 exposed 对象
|
|
1775
1780
|
*/
|
|
1776
1781
|
export declare function useExpose<Exposed extends object>(expose: (exposed?: Exposed) => void, exposed: Exposed): Exposed;
|
|
1777
1782
|
//#endregion
|
|
@@ -1781,20 +1786,20 @@ export type AwaitableFunction<Arguments extends readonly unknown[], Result> = (.
|
|
|
1781
1786
|
/**
|
|
1782
1787
|
* 统一执行同步或异步函数,异常保持原样向调用方传播。
|
|
1783
1788
|
*
|
|
1784
|
-
* @param function_ -
|
|
1785
|
-
* @param arguments_ -
|
|
1789
|
+
* @param function_ - 可选的待执行函数
|
|
1790
|
+
* @param arguments_ - 原样传入函数的参数
|
|
1786
1791
|
* @returns 函数结果;未传函数时返回 `undefined`。
|
|
1787
1792
|
*/
|
|
1788
1793
|
export declare function callOptionalFunction<Arguments extends readonly unknown[], Result>(function_: AwaitableFunction<Arguments, Result> | null | undefined, ...arguments_: Arguments): Promise<Awaited<Result> | undefined>;
|
|
1789
1794
|
//#endregion
|
|
1790
1795
|
//#region src/vue/install.d.ts
|
|
1791
|
-
/** Vue
|
|
1796
|
+
/** Vue 组件对象、函数组件或指令对象可接受的最小结构类型 */
|
|
1792
1797
|
export type VueInstallValue = object | ((...arguments_: never[]) => unknown);
|
|
1793
|
-
/** 为 Vue 组件或指令附加供 Vue 3 `app.use()`
|
|
1798
|
+
/** 为 Vue 组件或指令附加供 Vue 3 `app.use()` 调用的安装能力 */
|
|
1794
1799
|
export type Installable<Value> = Value & {
|
|
1795
1800
|
/**
|
|
1796
1801
|
* 把当前组件或指令安装到 Vue 3 App。
|
|
1797
|
-
* @param app - Vue 3 App
|
|
1802
|
+
* @param app - Vue 3 App 实例
|
|
1798
1803
|
*/
|
|
1799
1804
|
install: (app: App) => void;
|
|
1800
1805
|
};
|
|
@@ -1805,8 +1810,8 @@ export type TSXWithInstall<Value> = Installable<Value>;
|
|
|
1805
1810
|
*
|
|
1806
1811
|
* @remarks 函数会直接为 `main` 定义附属组件属性和 `install`。所有组件名称、附属属性
|
|
1807
1812
|
* 冲突会在修改 `main` 前完成校验;安装到 App 时也会先预检全部全局名称,再统一注册。
|
|
1808
|
-
* @param main - 具有非空 `name`
|
|
1809
|
-
* @param extras -
|
|
1813
|
+
* @param main - 具有非空 `name` 的组件
|
|
1814
|
+
* @param extras - 同时注册并以可枚举属性挂到主组件的附属组件映射
|
|
1810
1815
|
* @returns 原始 `main` 引用,并附加类型化的 `install` 与 `extras` 属性。
|
|
1811
1816
|
* @throws `TypeError` 当组件缺少合法名称、已有 `install`、附属键或名称发生冲突。
|
|
1812
1817
|
* @throws `Error` 当 App 中同名位置已经注册其他组件。
|
|
@@ -1817,8 +1822,8 @@ export declare function withInstall<Main extends VueInstallValue, Extras extends
|
|
|
1817
1822
|
*
|
|
1818
1823
|
* @remarks 适用于只能作为主组件附属属性使用、但仍需满足 Vue Plugin 类型的组件。
|
|
1819
1824
|
* 函数直接修改并返回传入组件,不会向 Vue 3 App 注册内容。
|
|
1820
|
-
* @param component - 尚未定义或继承 `install`
|
|
1821
|
-
* @returns 原组件引用及无副作用的 `install`
|
|
1825
|
+
* @param component - 尚未定义或继承 `install` 属性的组件
|
|
1826
|
+
* @returns 原组件引用及无副作用的 `install` 方法
|
|
1822
1827
|
* @throws `TypeError` 当组件自身或原型链已经存在 `install`。
|
|
1823
1828
|
*/
|
|
1824
1829
|
export declare function withNoopInstall<Value extends VueInstallValue>(component: Value): TSXWithInstall<Value>;
|
|
@@ -1827,8 +1832,8 @@ export declare function withNoopInstall<Value extends VueInstallValue>(component
|
|
|
1827
1832
|
*
|
|
1828
1833
|
* @remarks 函数直接修改并返回指令。安装时重复注册同一引用保持幂等,不会覆盖同名的
|
|
1829
1834
|
* 其他指令。名称只传给 `directive()`,不得包含 `v-` 前缀。
|
|
1830
|
-
* @param directive - 尚未定义或继承 `install` 属性的 Vue
|
|
1831
|
-
* @param name - 非空、无空白且不以 `v-`
|
|
1835
|
+
* @param directive - 尚未定义或继承 `install` 属性的 Vue 指令对象
|
|
1836
|
+
* @param name - 非空、无空白且不以 `v-` 开头的全局指令名
|
|
1832
1837
|
* @returns 原指令引用及 Vue Plugin `install` 方法。
|
|
1833
1838
|
* @throws `TypeError` 当名称非法、指令已有 `install`,或安装目标无效。
|
|
1834
1839
|
* @throws `Error` 当 App 中同名位置已经注册其他指令。
|
|
@@ -1839,7 +1844,7 @@ export declare function withInstallDirective<Value extends VueInstallValue>(dire
|
|
|
1839
1844
|
/**
|
|
1840
1845
|
* 按固定间隔提供响应式当前时间。
|
|
1841
1846
|
*
|
|
1842
|
-
* @param intervalMilliseconds - 更新时间间隔,默认 `1000`
|
|
1847
|
+
* @param intervalMilliseconds - 更新时间间隔,默认 `1000` 毫秒
|
|
1843
1848
|
* @returns 当前 Date 的只读 ShallowRef;SSR 环境只返回调用时的时间。
|
|
1844
1849
|
* @throws `Error` 当浏览器或 uni-app 环境中不存在可用于自动清理的 Vue 响应式作用域。
|
|
1845
1850
|
* @throws `RangeError` 当间隔不是平台计时器支持的非负有限整数。
|
|
@@ -1852,16 +1857,16 @@ export declare function useNow(intervalMilliseconds?: number): Readonly<ShallowR
|
|
|
1852
1857
|
*
|
|
1853
1858
|
* @remarks 该函数只帮助 TypeScript 建模,不验证运行时值与 `Value` 一致;调用方仍应
|
|
1854
1859
|
* 传入 Vue 支持的构造器或构造器数组。
|
|
1855
|
-
* @param runtimeType - Vue
|
|
1860
|
+
* @param runtimeType - Vue 支持的运行时构造器或构造器数组
|
|
1856
1861
|
* @returns 同一引用,仅在类型层收窄为 `PropType<Value>`。
|
|
1857
1862
|
*/
|
|
1858
1863
|
export declare function definePropType<Value>(runtimeType: unknown): PropType<Value>;
|
|
1859
1864
|
/**
|
|
1860
1865
|
* 构建需要透传给子组件的响应式 Props。
|
|
1861
1866
|
*
|
|
1862
|
-
* @param props - Vue `setup` 接收的只读响应式 Props
|
|
1863
|
-
* @param rawProps - 子组件的运行时 Props
|
|
1864
|
-
* @param ignoredProps - 不需要透传的 Props
|
|
1867
|
+
* @param props - Vue `setup` 接收的只读响应式 Props 对象
|
|
1868
|
+
* @param rawProps - 子组件的运行时 Props 配置
|
|
1869
|
+
* @param ignoredProps - 不需要透传的 Props 名称
|
|
1865
1870
|
* @returns 只包含 `rawProps` 声明键且随 Props 更新的 ComputedRef。
|
|
1866
1871
|
*/
|
|
1867
1872
|
export declare function useProps<Props extends object, RawProps extends object, IgnoredProp extends keyof RawProps = never>(props: Props, rawProps: RawProps, ignoredProps?: readonly IgnoredProp[]): ComputedRef<Omit<Pick<Props, Extract<keyof Props, keyof RawProps>>, Extract<IgnoredProp, keyof Props>>>;
|
|
@@ -1870,19 +1875,19 @@ export declare function useProps<Props extends object, RawProps extends object,
|
|
|
1870
1875
|
/**
|
|
1871
1876
|
* 在当前 Vue 3 组件实例上安装 TSX 渲染函数。
|
|
1872
1877
|
* @remarks `setup` 仍可返回状态对象,因此状态能够显示在 Vue Devtools 中。
|
|
1873
|
-
* @param render -
|
|
1878
|
+
* @param render - 当前组件的渲染函数
|
|
1874
1879
|
* @throws 不在组件 `setup` 调用栈中使用时抛出 `Error`。
|
|
1875
1880
|
*/
|
|
1876
1881
|
export declare function useRender(render: () => VNode): void;
|
|
1877
1882
|
//#endregion
|
|
1878
1883
|
//#region src/vue/slots.d.ts
|
|
1879
|
-
/** Slot 名到 Props
|
|
1884
|
+
/** Slot 名到 Props 类型的内部声明映射 */
|
|
1880
1885
|
type RawSlots = Record<string, unknown>;
|
|
1881
|
-
/** 根据 Slot Props 是否为 never 生成无参数或有参数的 Slot
|
|
1886
|
+
/** 根据 Slot Props 是否为 never 生成无参数或有参数的 Slot 签名 */
|
|
1882
1887
|
type VueSlot<Properties> = [Properties] extends [never] ? () => VNode[] : (properties: Properties) => VNode[];
|
|
1883
|
-
/** 把 Slot 名称与作用域参数映射为 Vue 3 Slot
|
|
1888
|
+
/** 把 Slot 名称与作用域参数映射为 Vue 3 Slot 函数 */
|
|
1884
1889
|
export type TypedSlots<Slots extends RawSlots> = { [Name in keyof Slots]: VueSlot<Slots[Name]>; };
|
|
1885
|
-
/** Vue 3 `slots`
|
|
1890
|
+
/** Vue 3 `slots` 选项接受的运行时声明与官方静态类型标记 */
|
|
1886
1891
|
export type TypedSlotsDeclaration<Slots extends RawSlots> = SlotsType<Partial<TypedSlots<Slots>>>;
|
|
1887
1892
|
/**
|
|
1888
1893
|
* 为 Options API 的 `slots` 选项创建带作用域参数的类型声明。
|
|
@@ -1932,7 +1937,7 @@ export declare function useWindowSize(): UseWindowSizeReturn;
|
|
|
1932
1937
|
* 保留传入值并显式指定其 TypeScript 类型。
|
|
1933
1938
|
*
|
|
1934
1939
|
* @remarks 未传值时运行时结果为 `undefined`,仅适合为 reactive 对象的初始字段提供类型。
|
|
1935
|
-
* @param data -
|
|
1940
|
+
* @param data - 可选的原始值
|
|
1936
1941
|
* @returns 传入值本身;省略时返回类型化的 `undefined`。
|
|
1937
1942
|
*/
|
|
1938
1943
|
export declare function withDefineType<Value>(data?: Value): Value;
|