@idlebox/common 1.3.18 → 1.3.19

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.
@@ -0,0 +1,1056 @@
1
+ export declare function addDisposableEventListener<T extends Function>(target: IEventHostObject<T> | IEventEmitterObject<T>, type: string, options: IEventListenerOptions, handler: T): IDisposable;
2
+
3
+ export declare function addDisposableEventListener<T extends Function>(target: IEventHostObject<T> | IEventEmitterObject<T>, type: string, handler: T): IDisposable;
4
+
5
+ /**
6
+ * Compare two array, returns the difference from `before` to `after`
7
+ * @public
8
+ */
9
+ export declare function arrayDiff<T>(_before: readonly T[], after: readonly T[]): {
10
+ add: T[];
11
+ del: T[];
12
+ same: T[];
13
+ };
14
+
15
+ /**
16
+ * Returns a new array without duplicate values
17
+ * @public
18
+ */
19
+ export declare function arrayUnique<T>(arr: readonly T[]): T[];
20
+
21
+ /**
22
+ * Removes duplicate values from an array
23
+ * @public
24
+ */
25
+ export declare function arrayUniqueReference(arr: any[]): void;
26
+
27
+ /**
28
+ * Assert function must have oneof displayName/name property
29
+ */
30
+ export declare function assertFunctionHasName(func: MaybeNamedFunction): void;
31
+
32
+ /**
33
+ * assert value is not null or undefined or NaN
34
+ * @public
35
+ */
36
+ export declare function assertNotNull<T>(val: T | null | undefined): T;
37
+
38
+ export declare function assertSerializable(value: any): void;
39
+
40
+ /**
41
+ * like CallbackList, but async
42
+ */
43
+ export declare class AsyncCallbackList<Argument extends unknown[]> {
44
+ protected list: MyAsyncCallback<Argument>[];
45
+ protected running: boolean;
46
+ constructor();
47
+ count(): number;
48
+ reset(): void;
49
+ /**
50
+ * @param name optional name of `item` (will assign displayName to `item`)
51
+ * @returns function list length
52
+ */
53
+ add(item: MyAsyncCallback<Argument>, name?: string): number;
54
+ /**
55
+ * @returns if removed: return `item`; if did not exists: return null
56
+ */
57
+ remove(item: MyAsyncCallback<Argument>): null | MyAsyncCallback<Argument>;
58
+ /**
59
+ * Stop run if one callback return `true`
60
+ * @returns {boolean} true if one callback return true
61
+ */
62
+ run(...argument: Argument): Promise<boolean>;
63
+ }
64
+
65
+ /**
66
+ * Async version of Disposable
67
+ * @public
68
+ */
69
+ export declare class AsyncDisposable implements IAsyncDisposable, IDisposableBaseInternal {
70
+ private readonly _disposables;
71
+ protected readonly _onDisposeError: Emitter<Error>;
72
+ readonly onDisposeError: EventRegister<Error>;
73
+ protected readonly _onBeforeDispose: Emitter<void>;
74
+ readonly onBeforeDispose: EventRegister<void>;
75
+ private _disposed?;
76
+ get hasDisposed(): boolean;
77
+ /**
78
+ * @throws if already disposed
79
+ */
80
+ assertNotDisposed(): void;
81
+ /**
82
+ * register a disposable object
83
+ */
84
+ _register<T extends IAsyncDisposable>(d: T): T;
85
+ dispose(): Promise<void>;
86
+ }
87
+
88
+ /**
89
+ * Convert Iterator into Promise, resolve with the last value from Iterator
90
+ */
91
+ export declare function awaitIterator<T>(generator: Iterator<T>): Promise<T>;
92
+
93
+ /**
94
+ * Auto bind `this` to class method
95
+ */
96
+ export declare const bindThis: MethodDecorator;
97
+
98
+ /**
99
+ * Manage a list of callback
100
+ */
101
+ export declare class CallbackList<Argument extends unknown[]> {
102
+ protected list: MyCallback<Argument>[];
103
+ protected running: boolean;
104
+ protected stop: boolean;
105
+ constructor();
106
+ count(): number;
107
+ /**
108
+ * remove all callback
109
+ */
110
+ reset(): void;
111
+ /**
112
+ * @param name optional name of `item` (will assign displayName to `item`)
113
+ * @returns function list length
114
+ */
115
+ add(item: MyCallback<Argument>, name?: string): number;
116
+ /**
117
+ * @returns if removed: return `item`; if did not exists: return null
118
+ */
119
+ remove(item: MyCallback<Argument>): null | MyCallback<Argument>;
120
+ /**
121
+ * in a callback, call this.stopRun() to stop remain callbacks (not by return false)
122
+ * @returns {boolean} true if every callback called, false if stop in middle
123
+ */
124
+ run(...argument: Argument): boolean;
125
+ stopRun(): void;
126
+ }
127
+
128
+ /** @public */
129
+ export declare function camelCase(str: string): string;
130
+
131
+ /**
132
+ * Error when cancel() is called
133
+ * @public
134
+ */
135
+ export declare class CanceledError extends Error {
136
+ constructor();
137
+ }
138
+
139
+ /** @public */
140
+ export declare interface CancellationToken {
141
+ readonly isCancellationRequested: boolean;
142
+ onCancellationRequested(callback: EventHandler<void>): IDisposable;
143
+ }
144
+
145
+ /** @public */
146
+ export declare class CancellationTokenSource extends DisposableOnce implements IDisposable {
147
+ private readonly driver;
148
+ readonly token: CancellationToken;
149
+ constructor();
150
+ cancel(): void;
151
+ _dispose(): void;
152
+ }
153
+
154
+ export declare enum ColorKind {
155
+ DISABLE = 0,
156
+ TERMINAL = 1,
157
+ WEB = 2,
158
+ DETECT = 3
159
+ }
160
+
161
+ /**
162
+ *
163
+ * GENERATED FILE, DO NOT MODIFY
164
+ * 这是生成的文件,千万不要修改
165
+ *
166
+ */
167
+ export declare function concatStringType<T0 extends string>(t0: T0): `${T0}`;
168
+
169
+ export declare function concatStringType<T0 extends string, T1 extends string>(t0: T0, t1: T1): `${T0}${T1}`;
170
+
171
+ export declare function concatStringType<T0 extends string, T1 extends string, T2 extends string>(t0: T0, t1: T1, t2: T2): `${T0}${T1}${T2}`;
172
+
173
+ export declare function concatStringType<T0 extends string, T1 extends string, T2 extends string, T3 extends string>(t0: T0, t1: T1, t2: T2, t3: T3): `${T0}${T1}${T2}${T3}`;
174
+
175
+ export declare function concatStringType<T0 extends string, T1 extends string, T2 extends string, T3 extends string, T4 extends string>(t0: T0, t1: T1, t2: T2, t3: T3, t4: T4): `${T0}${T1}${T2}${T3}${T4}`;
176
+
177
+ export declare function concatStringType<T0 extends string, T1 extends string, T2 extends string, T3 extends string, T4 extends string, T5 extends string>(t0: T0, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5): `${T0}${T1}${T2}${T3}${T4}${T5}`;
178
+
179
+ export declare function concatStringType<T0 extends string, T1 extends string, T2 extends string, T3 extends string, T4 extends string, T5 extends string, T6 extends string>(t0: T0, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6): `${T0}${T1}${T2}${T3}${T4}${T5}${T6}`;
180
+
181
+ export declare function concatStringType<T0 extends string, T1 extends string, T2 extends string, T3 extends string, T4 extends string, T5 extends string, T6 extends string, T7 extends string>(t0: T0, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7): `${T0}${T1}${T2}${T3}${T4}${T5}${T6}${T7}`;
182
+
183
+ export declare function concatStringType<T0 extends string, T1 extends string, T2 extends string, T3 extends string, T4 extends string, T5 extends string, T6 extends string, T7 extends string, T8 extends string>(t0: T0, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8): `${T0}${T1}${T2}${T3}${T4}${T5}${T6}${T7}${T8}`;
184
+
185
+ export declare function concatStringType<T0 extends string, T1 extends string, T2 extends string, T3 extends string, T4 extends string, T5 extends string, T6 extends string, T7 extends string, T8 extends string, T9 extends string>(t0: T0, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8, t9: T9): `${T0}${T1}${T2}${T3}${T4}${T5}${T6}${T7}${T8}${T9}`;
186
+
187
+ export declare function concatStringType<T0 extends string, T1 extends string, T2 extends string, T3 extends string, T4 extends string, T5 extends string, T6 extends string, T7 extends string, T8 extends string, T9 extends string, T10 extends string>(t0: T0, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8, t9: T9, t10: T10): `${T0}${T1}${T2}${T3}${T4}${T5}${T6}${T7}${T8}${T9}${T10}`;
188
+
189
+ export declare function concatStringType<T0 extends string, T1 extends string, T2 extends string, T3 extends string, T4 extends string, T5 extends string, T6 extends string, T7 extends string, T8 extends string, T9 extends string, T10 extends string, T11 extends string>(t0: T0, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8, t9: T9, t10: T10, t11: T11): `${T0}${T1}${T2}${T3}${T4}${T5}${T6}${T7}${T8}${T9}${T10}${T11}`;
190
+
191
+ export declare function concatStringType<T0 extends string, T1 extends string, T2 extends string, T3 extends string, T4 extends string, T5 extends string, T6 extends string, T7 extends string, T8 extends string, T9 extends string, T10 extends string, T11 extends string, T12 extends string>(t0: T0, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8, t9: T9, t10: T10, t11: T11, t12: T12): `${T0}${T1}${T2}${T3}${T4}${T5}${T6}${T7}${T8}${T9}${T10}${T11}${T12}`;
192
+
193
+ export declare function concatStringType<T0 extends string, T1 extends string, T2 extends string, T3 extends string, T4 extends string, T5 extends string, T6 extends string, T7 extends string, T8 extends string, T9 extends string, T10 extends string, T11 extends string, T12 extends string, T13 extends string>(t0: T0, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8, t9: T9, t10: T10, t11: T11, t12: T12, t13: T13): `${T0}${T1}${T2}${T3}${T4}${T5}${T6}${T7}${T8}${T9}${T10}${T11}${T12}${T13}`;
194
+
195
+ export declare function concatStringType<T0 extends string, T1 extends string, T2 extends string, T3 extends string, T4 extends string, T5 extends string, T6 extends string, T7 extends string, T8 extends string, T9 extends string, T10 extends string, T11 extends string, T12 extends string, T13 extends string, T14 extends string>(t0: T0, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8, t9: T9, t10: T10, t11: T11, t12: T12, t13: T13, t14: T14): `${T0}${T1}${T2}${T3}${T4}${T5}${T6}${T7}${T8}${T9}${T10}${T11}${T12}${T13}${T14}`;
196
+
197
+ export declare function concatStringType<T0 extends string, T1 extends string, T2 extends string, T3 extends string, T4 extends string, T5 extends string, T6 extends string, T7 extends string, T8 extends string, T9 extends string, T10 extends string, T11 extends string, T12 extends string, T13 extends string, T14 extends string, T15 extends string>(t0: T0, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8, t9: T9, t10: T10, t11: T11, t12: T12, t13: T13, t14: T14, t15: T15): `${T0}${T1}${T2}${T3}${T4}${T5}${T6}${T7}${T8}${T9}${T10}${T11}${T12}${T13}${T14}${T15}`;
198
+
199
+ export declare function concatStringType<T0 extends string, T1 extends string, T2 extends string, T3 extends string, T4 extends string, T5 extends string, T6 extends string, T7 extends string, T8 extends string, T9 extends string, T10 extends string, T11 extends string, T12 extends string, T13 extends string, T14 extends string, T15 extends string, T16 extends string>(t0: T0, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8, t9: T9, t10: T10, t11: T11, t12: T12, t13: T13, t14: T14, t15: T15, t16: T16): `${T0}${T1}${T2}${T3}${T4}${T5}${T6}${T7}${T8}${T9}${T10}${T11}${T12}${T13}${T14}${T15}${T16}`;
200
+
201
+ export declare function concatStringType<T0 extends string, T1 extends string, T2 extends string, T3 extends string, T4 extends string, T5 extends string, T6 extends string, T7 extends string, T8 extends string, T9 extends string, T10 extends string, T11 extends string, T12 extends string, T13 extends string, T14 extends string, T15 extends string, T16 extends string, T17 extends string>(t0: T0, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8, t9: T9, t10: T10, t11: T11, t12: T12, t13: T13, t14: T14, t15: T15, t16: T16, t17: T17): `${T0}${T1}${T2}${T3}${T4}${T5}${T6}${T7}${T8}${T9}${T10}${T11}${T12}${T13}${T14}${T15}${T16}${T17}`;
202
+
203
+ export declare function concatStringType<T0 extends string, T1 extends string, T2 extends string, T3 extends string, T4 extends string, T5 extends string, T6 extends string, T7 extends string, T8 extends string, T9 extends string, T10 extends string, T11 extends string, T12 extends string, T13 extends string, T14 extends string, T15 extends string, T16 extends string, T17 extends string, T18 extends string>(t0: T0, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8, t9: T9, t10: T10, t11: T11, t12: T12, t13: T13, t14: T14, t15: T15, t16: T16, t17: T17, t18: T18): `${T0}${T1}${T2}${T3}${T4}${T5}${T6}${T7}${T8}${T9}${T10}${T11}${T12}${T13}${T14}${T15}${T16}${T17}${T18}`;
204
+
205
+ export declare function concatStringType<T0 extends string, T1 extends string, T2 extends string, T3 extends string, T4 extends string, T5 extends string, T6 extends string, T7 extends string, T8 extends string, T9 extends string, T10 extends string, T11 extends string, T12 extends string, T13 extends string, T14 extends string, T15 extends string, T16 extends string, T17 extends string, T18 extends string, T19 extends string>(t0: T0, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8: T8, t9: T9, t10: T10, t11: T11, t12: T12, t13: T13, t14: T14, t15: T15, t16: T16, t17: T17, t18: T18, t19: T19): `${T0}${T1}${T2}${T3}${T4}${T5}${T6}${T7}${T8}${T9}${T10}${T11}${T12}${T13}${T14}${T15}${T16}${T17}${T18}${T19}`;
206
+
207
+ export declare function convertCatchedError(e: unknown): Error;
208
+
209
+ /**
210
+ * Get a symbol singleton, if not exists, create it
211
+ *
212
+ * this is very like Symbol.for, but not real global symbol
213
+ * @public
214
+ */
215
+ export declare function createSymbol(category: string, name: string): symbol;
216
+
217
+ /**
218
+ * Like a Set, but use custom compare function insteadof ===
219
+ */
220
+ export declare class CustomSet<Type = string> {
221
+ protected registry: Type[];
222
+ private finder;
223
+ constructor(finder?: Finder<Type>);
224
+ setFinder(finder: Finder<Type>): void;
225
+ has(item: Type): boolean;
226
+ add(item: Type): boolean;
227
+ /**
228
+ * @returns all added values
229
+ */
230
+ addAll(items: Type[]): Type[];
231
+ delete(item: Type): boolean;
232
+ /**
233
+ * @returns all deleted values
234
+ */
235
+ deleteAll(items: Type[]): Type[];
236
+ clear(): void;
237
+ get length(): number;
238
+ get size(): number;
239
+ [Symbol.iterator](): Iterator<Type>;
240
+ keys(): Iterator<Type>;
241
+ values(): Iterator<Type>;
242
+ toArray(): Type[];
243
+ }
244
+
245
+ export declare type DeepNonNullable<T> = T extends Primitive ? T : T extends ReadonlyArray<infer U> | Array<infer U> ? DeepNonNullableArray<U> : T extends ReadonlyMap<infer K, infer V> | Map<infer K, infer V> ? DeepNonNullableMap<K, V> : T extends ReadonlySet<infer M> ? DeepNonNullableSet<M> : DeepNonNullableObject<T>;
246
+
247
+ declare type DeepNonNullableArray<T> = Array<DeepNonNullable<T>>;
248
+
249
+ declare type DeepNonNullableMap<K, V> = Map<DeepNonNullable<K>, DeepNonNullable<V>>;
250
+
251
+ declare type DeepNonNullableObject<T> = {
252
+ [K in keyof T]-?: NonNullable<T[K]>;
253
+ };
254
+
255
+ declare type DeepNonNullableSet<T> = Set<DeepNonNullable<T>>;
256
+
257
+ export declare type DeepPartial<T> = T extends Primitive ? T : T extends ReadonlyArray<infer U> ? DeepPartialArray<U> : T extends ReadonlyMap<infer K, infer V> ? DeepPartialMap<K, V> : T extends ReadonlySet<infer M> ? DeepPartialSet<M> : DeepPartialObject<T>;
258
+
259
+ declare type DeepPartialArray<T> = Array<DeepPartial<T>>;
260
+
261
+ declare type DeepPartialMap<K, V> = Map<DeepPartial<K>, DeepPartial<V>>;
262
+
263
+ declare type DeepPartialObject<T> = {
264
+ [K in keyof T]?: DeepPartial<T[K]>;
265
+ };
266
+
267
+ declare type DeepPartialSet<T> = Set<DeepPartial<T>>;
268
+
269
+ export declare type DeepReadonly<T> = T extends Primitive ? T : T extends Array<infer U> ? DeepReadonlyArray<U> : T extends Map<infer K, infer V> ? DeepReadonlyMap<K, V> : T extends Set<infer M> ? DeepReadonlySet<M> : DeepReadonlyObject<T>;
270
+
271
+ declare type DeepReadonlyArray<T> = ReadonlyArray<DeepReadonly<T>>;
272
+
273
+ declare type DeepReadonlyMap<K, V> = ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>;
274
+
275
+ declare type DeepReadonlyObject<T> = {
276
+ readonly [K in keyof T]: DeepReadonly<T[K]>;
277
+ };
278
+
279
+ declare type DeepReadonlySet<T> = ReadonlySet<DeepReadonly<T>>;
280
+
281
+ export declare type DeepWriteable<T> = T extends Primitive ? T : T extends ReadonlyArray<infer U> ? DeepWriteableArray<U> : T extends ReadonlyMap<infer K, infer V> ? DeepWriteableMap<K, V> : T extends ReadonlySet<infer M> ? DeepWriteableSet<M> : DeepWriteableObject<T>;
282
+
283
+ declare type DeepWriteableArray<T> = Array<DeepWriteable<T>>;
284
+
285
+ declare type DeepWriteableMap<K, V> = Map<DeepWriteable<K>, DeepWriteable<V>>;
286
+
287
+ declare type DeepWriteableObject<T> = {
288
+ -readonly [K in keyof T]: DeepWriteable<T[K]>;
289
+ };
290
+
291
+ declare type DeepWriteableSet<T> = Set<DeepWriteable<T>>;
292
+
293
+ /**
294
+ * a promise can resolve or reject later
295
+ * @public
296
+ */
297
+ export declare class DeferredPromise<T, PT = any> {
298
+ readonly p: Promise<T> & IProgressHolder<T, PT>;
299
+ private _completeCallback;
300
+ private _errorCallback;
301
+ private _state;
302
+ private _progressList?;
303
+ constructor();
304
+ notify(progress: PT): this;
305
+ progress(fn: ProgressCallback<PT>): void;
306
+ get completed(): boolean;
307
+ get resolved(): boolean;
308
+ get rejected(): boolean;
309
+ /**
310
+ * resolve the promise
311
+ */
312
+ complete(value: T): void;
313
+ /**
314
+ * reject the promise
315
+ */
316
+ error(err: any): void;
317
+ /**
318
+ * reject the promise with CancelError
319
+ */
320
+ cancel(): void;
321
+ /**
322
+ * Convert promise into deferred
323
+ * returns a DeferredPromise, resolve when prev resolve, reject when prev reject
324
+ */
325
+ static wrap(prev: Promise<any>): DeferredPromise<unknown, any>;
326
+ }
327
+
328
+ export declare function definePublicConstant(object: any, propertyKey: string | symbol, value: any): void;
329
+
330
+ /**
331
+ * remember arguments after run
332
+ * run all later added function with memorized argument
333
+ */
334
+ export declare class DelayCallbackList<Argument extends unknown[]> {
335
+ private delayArgument?;
336
+ private delayComplete;
337
+ protected list?: MyDelayCallback<Argument>[];
338
+ count(): number;
339
+ add(item: MyDelayCallback<Argument>, name?: string): void;
340
+ run(argument: Argument): void;
341
+ }
342
+
343
+ /**
344
+ * Delete a symbol from window/global object
345
+ * @public
346
+ */
347
+ export declare function deleteSymbol(category: string, name: string): void;
348
+
349
+ /**
350
+ * Standalone disposable class, can use as instance or base class.
351
+ */
352
+ export declare class Disposable implements IDisposable, IDisposableBaseInternal {
353
+ private readonly _disposables;
354
+ protected readonly _onDisposeError: Emitter<Error>;
355
+ readonly onDisposeError: EventRegister<Error>;
356
+ protected readonly _onBeforeDispose: Emitter<void>;
357
+ readonly onBeforeDispose: EventRegister<void>;
358
+ private _disposed?;
359
+ get hasDisposed(): boolean;
360
+ /**
361
+ * @throws if already disposed
362
+ */
363
+ assertNotDisposed(): void;
364
+ _register<T extends IDisposable>(d: T): T;
365
+ dispose(): void;
366
+ }
367
+
368
+ export declare abstract class DisposableOnce implements IDisposable {
369
+ private _disposed?;
370
+ get hasDisposed(): boolean;
371
+ dispose(): void;
372
+ protected abstract _dispose(): void;
373
+ }
374
+
375
+ /**
376
+ * Error when call dispose() twice
377
+ */
378
+ export declare class DisposedError extends Error {
379
+ constructor(object: any, previous: Error);
380
+ }
381
+
382
+ /**
383
+ * Dispose the global disposable store
384
+ * this function must be manually called by user, when registerGlobalLifecycle is used
385
+ *
386
+ * @throws when call twice
387
+ */
388
+ export declare function disposeGlobal(): Promise<void>;
389
+
390
+ /**
391
+ * 事件注册对象
392
+ * @public
393
+ */
394
+ export declare class Emitter<T> implements IDisposable {
395
+ private readonly _callbacks;
396
+ constructor();
397
+ /**
398
+ * @returns 当前注册回调数量
399
+ */
400
+ listenerCount(): number;
401
+ /**
402
+ * 触发本事件
403
+ * @param data 回调数据
404
+ */
405
+ fire(data: T): void;
406
+ /**
407
+ * 与 `fire()`相同,但是忽略任何错误,并且即便出错也继续执行全部callback
408
+ */
409
+ fireNoError(data: T): void;
410
+ /**
411
+ * 获取handle()方法的引用
412
+ */
413
+ get register(): EventRegister<T>;
414
+ /**
415
+ * 注册本事件的新回调
416
+ * @param callback 回调函数
417
+ */
418
+ handle(callback: EventHandler<T>): IDisposable;
419
+ dispose(): void;
420
+ }
421
+
422
+ /**
423
+ * Same as disposeGlobal, but do not throw by duplicate call
424
+ */
425
+ export declare function ensureDisposeGlobal(): Promise<void>;
426
+
427
+ export declare function ensureGlobalObject<T>(symbol: string, constructor: () => T): T;
428
+
429
+ /** @public */
430
+ export declare function escapeRegExp(str: string): string;
431
+
432
+ export declare interface EventHandler<T> {
433
+ (data: T): void;
434
+ }
435
+
436
+ export declare interface EventRegister<T> {
437
+ (callback: EventHandler<T>): IDisposable;
438
+ }
439
+
440
+ /**
441
+ * A map, will throw error when try to get not exists key
442
+ */
443
+ export declare class ExtendMap<K, V> extends Map<K, V> {
444
+ /**
445
+ * Get value from map, if not exists, throw an error
446
+ */
447
+ get(id: K): V;
448
+ /**
449
+ * Get value from map, if not exists, return def instead (not insert it into map)
450
+ */
451
+ get(id: K, def: V): V;
452
+ /**
453
+ * Get a value, if not exists, call init() and set to map
454
+ */
455
+ entry(id: K, init: (id: K) => V): V;
456
+ }
457
+
458
+ /** Find the index of given item */
459
+ export declare interface Finder<Type> {
460
+ (this: Type[], item: Type): number;
461
+ }
462
+
463
+ /**
464
+ * @deprecated Use Promise.allSettled instead
465
+ */
466
+ export declare function finishAllPromise<T>(ps: Promise<T>[]): Promise<PromiseResultArray<T>>;
467
+
468
+ /**
469
+ * Takes ms
470
+ */
471
+ export declare function fromTimeStamp(timestamp: number): Date;
472
+
473
+ /**
474
+ * Get displayName/name of a function
475
+ */
476
+ export declare function functionName(func: Function): string;
477
+
478
+ /**
479
+ * Get nth line of Error.stack
480
+ * @returns {string} if frame greater than max, return ''
481
+ */
482
+ export declare function getErrorFrame(e: Error, frame: number): string;
483
+
484
+ /**
485
+ * Returns ms
486
+ */
487
+ export declare function getTimeStamp(date: Date): number;
488
+
489
+ export declare function getTypeOf(value: any): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "function" | "unknown" | "null" | "Promise" | "Error" | "DOM" | "EventTarget" | "datetime" | "regexp";
490
+
491
+ /**
492
+ * globalThis when supported.
493
+ * if not, window in browser, global in nodejs
494
+ * @public
495
+ */
496
+ export declare const globalObject: any;
497
+
498
+ /**
499
+ * Same with globalSingletonStrong, but save instance in a WeakMap, so it maybe delete by gc if no reference
500
+ * @public
501
+ */
502
+ export declare function globalSingleton<T>(symbol: symbol | string, constructor: () => T): T;
503
+
504
+ /**
505
+ * Same with globalSingletonStrong, but save instance in a WeakMap, so it maybe delete by gc if no reference
506
+ * @public
507
+ */
508
+ export declare function globalSingleton<T>(symbol: symbol | string): T | undefined;
509
+
510
+ /**
511
+ * Delete a key from window/global space
512
+ * use with care
513
+ * @public
514
+ */
515
+ export declare function globalSingletonDelete(symbol: symbol | string): void;
516
+
517
+ /**
518
+ * Get an singleton instance from window/global space
519
+ * if symbol did not exists, create it and assign to window/global
520
+ * @public
521
+ */
522
+ export declare function globalSingletonStrong<T>(symbol: symbol | string, constructor: () => T): T;
523
+
524
+ /**
525
+ * Get an singleton instance from window/global space
526
+ * @public
527
+ */
528
+ export declare function globalSingletonStrong<T>(symbol: symbol | string): T | undefined;
529
+
530
+ export declare function hookClass<TC extends IConstructorOf<T>, T>(target: TC): IHooks<T, TC>;
531
+
532
+ export declare const hookClassSymbol: unique symbol;
533
+
534
+ export declare namespace humanDate {
535
+ /**
536
+ * Format: HH:mm:ss
537
+ */
538
+ export function time(date: Date | string | number): string;
539
+ /**
540
+ * Format: YYYY-MM-dd
541
+ *
542
+ * separator can change
543
+ */
544
+ export function date(date: Date | string | number, sp?: string): string;
545
+ /**
546
+ * Format: YYYY-MM-dd HH:mm:ss
547
+ */
548
+ export function datetime(date: Date | string | number): string;
549
+ export interface ITimeFormatter {
550
+ (s: number): string;
551
+ }
552
+ export interface IFormatters {
553
+ s: ITimeFormatter;
554
+ m: ITimeFormatter;
555
+ h: ITimeFormatter;
556
+ d: ITimeFormatter;
557
+ }
558
+ /**
559
+ * set format for time delta
560
+ */
561
+ export function setLocaleFormatter(formatter: Partial<IFormatters>): void;
562
+ /**
563
+ * format time delta (in ms) to string, like: '1d'
564
+ * when ms<=0, returns '0s'
565
+ *
566
+ * format can set by `setLocaleFormatter`
567
+ * day is the largest unit
568
+ */
569
+ export function deltaTiny(ms: number): string;
570
+ /**
571
+ * format time delta (in ms) to string, like: '1d10m42s'
572
+ * when ms<=0, returns '0s'
573
+ *
574
+ * format can set by `setLocaleFormatter`
575
+ * day is the largest unit
576
+ */
577
+ export function delta(ms: number): string;
578
+ }
579
+
580
+ /**
581
+ * Convert bytes to largest unit, with binary prefix unit (1024), eg: 211.293GiB
582
+ * @public
583
+ */
584
+ export declare function humanSize(bytes: number, fixed?: number): string;
585
+
586
+ /**
587
+ * Convert bytes to largest unit, with SI prefix unit (1000), eg: 211.293GB
588
+ * @public
589
+ */
590
+ export declare function humanSizeSI(bytes: number, fixed?: number): string;
591
+
592
+ /** @deprecated */
593
+ export declare function humanSpeed(bps: number): string;
594
+
595
+ /**
596
+ * @public
597
+ */
598
+ export declare interface IArrayUpdate<T> {
599
+ add: T[];
600
+ del: T[];
601
+ same: T[];
602
+ }
603
+
604
+ /** @public */
605
+ export declare interface IAsyncDisposable {
606
+ dispose(): void | Promise<void>;
607
+ }
608
+
609
+ declare interface IConstructorOf<T> extends Object {
610
+ new (...args: any[]): T;
611
+ }
612
+
613
+ /** @public */
614
+ export declare interface IDisposable {
615
+ dispose(): void;
616
+ }
617
+
618
+ /**
619
+ * @private
620
+ */
621
+ export declare interface IDisposableBaseInternal {
622
+ onDisposeError: EventRegister<Error>;
623
+ onBeforeDispose: EventRegister<void>;
624
+ readonly hasDisposed: boolean;
625
+ }
626
+
627
+ export declare interface IEventEmitterObject<T extends Function> {
628
+ addListener(type: string, handler: T): any;
629
+ removeListener(type: string, handler: T): any;
630
+ }
631
+
632
+ export declare interface IEventHostObject<T extends Function> {
633
+ addEventListener(type: string, handler: T, options?: IEventListenerOptions): any;
634
+ removeEventListener(type: string, handler: T, options?: IEventListenerOptions): any;
635
+ }
636
+
637
+ export declare interface IEventListenerOptions {
638
+ capture?: boolean;
639
+ once?: boolean;
640
+ passive?: boolean;
641
+ }
642
+
643
+ declare interface IHooks<T, TC> {
644
+ afterConstruct?: ((obj: T) => void)[];
645
+ beforeConstruct?: ((obj: TC) => T | void)[];
646
+ }
647
+
648
+ /**
649
+ * Decorater version of `initOnRead`
650
+ * @see initOnRead
651
+ */
652
+ export declare function init<O, T extends keyof O>(init: InitFunc<O, O[T]>): PropertyDecorator;
653
+
654
+ /** @public */
655
+ export declare interface InitFunc<O, T> {
656
+ (this: O): T;
657
+ }
658
+
659
+ /**
660
+ * Define property on target, call init it when first use, them memorize
661
+ * @public
662
+ */
663
+ export declare function initOnRead<O, T extends keyof O>(target: any, propertyKey: T, init: InitFunc<O, O[T]>): void;
664
+
665
+ export declare interface IProgressHolder<T, PT> {
666
+ progress(fn: ProgressCallback<PT>): Promise<T> & IProgressHolder<T, PT>;
667
+ }
668
+
669
+ /**
670
+ * return true if a path is absolute:
671
+ * - /xxxx
672
+ * - \xxxx
673
+ * - c:/
674
+ * - c:\
675
+ * - http://
676
+ */
677
+ export declare function isAbsolute(path: string): boolean;
678
+
679
+ /**
680
+ * is the two array EXACTLY same
681
+ * @public
682
+ */
683
+ export declare function isArraySame<T>(a1: readonly T[], a2: readonly T[]): boolean;
684
+
685
+ /** @public */
686
+ export declare function isCanceledError(error: any): boolean;
687
+
688
+ /**
689
+ * Check if a date is NaN
690
+ */
691
+ export declare function isDateInvalid(date: Date): boolean;
692
+
693
+ export declare function isDisposedError(error: any): boolean;
694
+
695
+ export declare const isElectron: boolean;
696
+
697
+ export declare const isElectronMain: boolean;
698
+
699
+ export declare const isElectronRenderer: boolean;
700
+
701
+ export declare const isLinux: boolean;
702
+
703
+ export declare const isMacintosh: boolean;
704
+
705
+ export declare const isNative: boolean;
706
+
707
+ /**
708
+ * Should ensure a and b is none-null before call this
709
+ * @returns true when a and b has EXACTLY same keys and values
710
+ */
711
+ export declare function isObjectSame(a: any, b: any): boolean;
712
+
713
+ /**
714
+ * Should ensure a and b is none-null before call this
715
+ * @returns true when a and b has EXACTLY same keys and values, recursive compare all object values
716
+ */
717
+ export declare function isObjectSameRecursive(a: any, b: any): boolean;
718
+
719
+ export declare function isScalar(value: any): value is ScalarTypes;
720
+
721
+ export declare function isSerializable(value: any): SerializableKind;
722
+
723
+ /** @public */
724
+ export declare function isTimeoutError(error: Error): error is TimeoutError;
725
+
726
+ export declare const isWeb: boolean;
727
+
728
+ export declare const isWindows: boolean;
729
+
730
+ export declare interface IUniqueIdFactory<T> {
731
+ (item: T): string;
732
+ }
733
+
734
+ /**
735
+ * lowercase first char
736
+ * @public
737
+ */
738
+ export declare function lcfirst<T extends string>(str: T): Uncapitalize<T>;
739
+
740
+ /** @public */
741
+ export declare function linux_case(str: string): string;
742
+
743
+ /** @public */
744
+ export declare function linux_case_hyphen(str: string): string;
745
+
746
+ export declare interface MapLike<V> {
747
+ [id: string]: V;
748
+ }
749
+
750
+ export declare interface MaybeNamedFunction extends Function {
751
+ displayName?: string;
752
+ }
753
+
754
+ /**
755
+ * Decorate class method/getter
756
+ *
757
+ * remember first return value of method/getter, directlly return memorized value when call it again
758
+ */
759
+ export declare const memo: MethodDecorator;
760
+
761
+ /**
762
+ * 会记住上次fire的内容,并在每个新的handler注册时立即调用一次的Emitter
763
+ * 显然,这会对fire的内容保留一个引用,可以调用forget()取消
764
+ * @public
765
+ */
766
+ export declare class MemorizedEmitter<T> extends Emitter<T> {
767
+ private _memo?;
768
+ private _is_memo;
769
+ fire(data: T): void;
770
+ fireNoError(data: T): void;
771
+ handle(callback: EventHandler<T>): IDisposable;
772
+ forget(): void;
773
+ dispose(): void;
774
+ }
775
+
776
+ export declare const memorizeValueSymbol: unique symbol;
777
+
778
+ export declare interface MyAsyncCallback<Argument extends unknown[]> {
779
+ displayName?: string;
780
+ (...param: Argument): Promise<void | undefined | boolean> | void | undefined | boolean;
781
+ }
782
+
783
+ export declare interface MyCallback<Argument extends unknown[]> {
784
+ displayName?: string;
785
+ (...param: Argument): any;
786
+ }
787
+
788
+ export declare interface MyDelayCallback<Argument extends unknown[]> {
789
+ displayName?: string;
790
+ (...param: Argument): void;
791
+ }
792
+
793
+ /**
794
+ * Function with displayName
795
+ */
796
+ export declare interface NamedFunction extends Function {
797
+ displayName: string;
798
+ }
799
+
800
+ /**
801
+ * Set displayName of a function
802
+ */
803
+ export declare function nameFunction<T extends Function>(name: string, func: T): T & NamedFunction;
804
+
805
+ export declare function nextDay(d: Date, n?: number): Date;
806
+
807
+ export declare function nextHour(d: Date, n?: number): Date;
808
+
809
+ export declare function nextMinute(d: Date, n?: number): Date;
810
+
811
+ export declare function nextMonth(d: Date, n?: number): Date;
812
+
813
+ export declare function nextSecond(d: Date, n?: number): Date;
814
+
815
+ export declare function nextWeek(d: Date, n?: number): Date;
816
+
817
+ export declare function nextYear(d: Date, n?: number): Date;
818
+
819
+ /**
820
+ * ensure a value is an array
821
+ * @public
822
+ */
823
+ export declare function normalizeArray<T>(input: T | T[]): T[];
824
+
825
+ /**
826
+ * replace // to /
827
+ * replace \ to /
828
+ * remove ending /
829
+ */
830
+ export declare function normalizePath(p: string): string;
831
+
832
+ /**
833
+ * Get deep child property of an object
834
+ * @param path object path seprate by "."
835
+ */
836
+ export declare function objectPath(obj: object, path: string): any;
837
+
838
+ export declare const oneDay = 86400000;
839
+
840
+ export declare const oneHour = 1440000;
841
+
842
+ export declare const oneMinute = 60000;
843
+
844
+ export declare const oneSecond = 1000;
845
+
846
+ export declare const oneWeek = 604800000;
847
+
848
+ /**
849
+ * Pad number to two digits string, used in time format
850
+ * @public
851
+ */
852
+ export declare function pad2(s: number): string;
853
+
854
+ /**
855
+ * Work on "PATH"-like values
856
+ */
857
+ export declare class PathArray extends Set<string> {
858
+ private readonly sep;
859
+ constructor(init: string, sep: ':' | ';');
860
+ add(paths: string): this;
861
+ delete(paths: string): boolean;
862
+ has(path: string): boolean;
863
+ toString(): string;
864
+ /**
865
+ * @returns an array with `part` append to every element
866
+ */
867
+ join(part: string): string[];
868
+ }
869
+
870
+ export declare type Primitive = undefined | null | boolean | string | number | Function | bigint;
871
+
872
+ export declare type ProgressCallback<T = any> = (value: T) => void;
873
+
874
+ /**
875
+ * resolve with true when `p` resolve
876
+ * resolve with false when `p` reject (and drop error)
877
+ */
878
+ export declare function promiseBool(p: Promise<any>): Promise<boolean>;
879
+
880
+ export declare class PromisePool {
881
+ protected readonly promiseList: Record<string, DeferredPromise<any>>;
882
+ size(): number;
883
+ create(id: string): Promise<any> & IProgressHolder<any, any>;
884
+ has(id: string): boolean;
885
+ done(id: string, data: any): void;
886
+ error(id: string, e: Error): void;
887
+ dispose(): void;
888
+ }
889
+
890
+ /** @deprecated */
891
+ export declare interface PromiseResultArray<T> {
892
+ count: number;
893
+ fulfilledResult: T[];
894
+ fulfilled: number[];
895
+ rejectedResult: Error[];
896
+ rejected: number[];
897
+ }
898
+
899
+ export declare function RegexpFinder(this: RegExp[], item: RegExp): number;
900
+
901
+ /**
902
+ * Add object into global disposable store, it will be dispose when call to `disposeGlobal`
903
+ */
904
+ export declare function registerGlobalLifecycle(object: IDisposable): void;
905
+
906
+ declare type ScalarTypes = bigint | number | Number | boolean | Boolean | string | String | symbol | undefined | null | Date | RegExp | Function;
907
+
908
+ export declare const sepList: string;
909
+
910
+ export declare enum SerializableKind {
911
+ Invalid = 0,
912
+ Primitive = 1,
913
+ Manual = 2,
914
+ Other = 3
915
+ }
916
+
917
+ export declare function singleton(type?: SingletonType): ClassDecorator;
918
+
919
+ export declare const singletonSymbol: unique symbol;
920
+
921
+ export declare enum SingletonType {
922
+ Throw = 0,
923
+ Return = 1
924
+ }
925
+
926
+ /**
927
+ * @returns promise resolve after specific time
928
+ */
929
+ export declare function sleep(ms: number): Promise<void>;
930
+
931
+ /**
932
+ * Sort string array alphabet order
933
+ *
934
+ * to be used in <arr>.sort()
935
+ * @public
936
+ */
937
+ export declare function sortByString(a: string, b: string): number;
938
+
939
+ /**
940
+ * assert value is not null or undefined or NaN
941
+ * @throws Value is null or undefined
942
+ * @public
943
+ */
944
+ export declare function throwNull<T>(val: T): NonNullable<T>;
945
+
946
+ /**
947
+ * @returns promise reject with TimeoutError after specific time
948
+ */
949
+ export declare function timeout(ms: number, error?: string): Promise<never>;
950
+
951
+ /**
952
+ * Error when timeout() done
953
+ * @public
954
+ */
955
+ export declare class TimeoutError extends Error {
956
+ constructor(time: number, what?: string);
957
+ }
958
+
959
+ export declare function timeoutPromise<T>(ms: number, p: Promise<T>): Promise<T>;
960
+
961
+ export declare function timeoutPromise<T>(ms: number, message: string, p: Promise<T>): Promise<T>;
962
+
963
+ export declare function timeoutPromise<T, PT = any>(ms: number, p: DeferredPromise<T, PT>): DeferredPromise<T, PT>;
964
+
965
+ export declare function timeoutPromise<T, PT = any>(ms: number, message: string, p: DeferredPromise<T, PT>): DeferredPromise<T, PT>;
966
+
967
+ export declare class TimeoutPromisePool extends PromisePool {
968
+ private readonly defaultTimeoutMs;
969
+ constructor(defaultTimeoutMs?: number);
970
+ create(id: string, timeoutMs?: number, timeoutMsg?: string): Promise<any> & IProgressHolder<any, any>;
971
+ }
972
+
973
+ /**
974
+ * Convert "dispose function" to disposable object
975
+ * @public
976
+ */
977
+ export declare function toDisposable(fn: () => void): IDisposable;
978
+
979
+ /**
980
+ * try to call `inspect` method of an object, if not exists, call `toString`.
981
+ * @returns {string}
982
+ */
983
+ export declare function tryInspect(object: any): any;
984
+
985
+ /**
986
+ * Uppercase first char
987
+ * @public
988
+ */
989
+ export declare function ucfirst<T extends string>(str: T): Capitalize<T>;
990
+
991
+ /**
992
+ * Returns a function to be used in <arr>.filter()
993
+ *
994
+ * the returned function can use multiple times, it will remember all values inter multiple arrays
995
+ *
996
+ * @param {IUniqueIdFactory} idFactory function takes an array element, return it's id to be compare with each other
997
+ * @public
998
+ */
999
+ export declare function uniqueFilter<T>(idFactory?: IUniqueIdFactory<T>): (item: T) => boolean;
1000
+
1001
+ declare interface Unsubscribable {
1002
+ unsubscribe(): void;
1003
+ }
1004
+
1005
+ export declare function unsubscribableToDisposable(subscription: Unsubscribable): {
1006
+ dispose: () => void;
1007
+ };
1008
+
1009
+ export declare const userAgent: string;
1010
+
1011
+ export declare type ValueCallback<T = any> = (value: T | Promise<T>) => void;
1012
+
1013
+ export declare abstract class WrappedConsole {
1014
+ info: Console['info'];
1015
+ log: Console['log'];
1016
+ success: Console['log'];
1017
+ debug: Console['debug'];
1018
+ error: Console['error'];
1019
+ trace: Console['trace'];
1020
+ warn: Console['warn'];
1021
+ assert: Console['assert'];
1022
+ time: Console['time'];
1023
+ timeEnd: Console['timeEnd'];
1024
+ timeLog: Console['timeLog'];
1025
+ count: Console['count'];
1026
+ countReset: Console['countReset'];
1027
+ group: Console['group'];
1028
+ groupCollapsed: Console['groupCollapsed'];
1029
+ groupEnd: Console['groupEnd'];
1030
+ table: Console['table'];
1031
+ dir: Console['dir'];
1032
+ clear: Console['clear'];
1033
+ protected readonly title: string;
1034
+ protected readonly parent: Console;
1035
+ protected readonly bind: boolean;
1036
+ constructor(title: string, { parent, bind }?: WrappedConsoleOptions);
1037
+ protected wrap<T extends keyof Omit<Console & {
1038
+ Console: any;
1039
+ }, 'Console'>>(original: T): Function;
1040
+ private wrapSimple;
1041
+ private wrapExtra;
1042
+ protected createPrefix(message: string): string;
1043
+ private wrapMessageAt;
1044
+ private convertObjectArg;
1045
+ protected abstract processColorLabel(normalizedArguments: any[], messageLoc: number, level: string, prefix: string): void;
1046
+ protected uncolor(args: any[], pos: number, prefix: string, postfix: string): void;
1047
+ }
1048
+
1049
+ export declare interface WrappedConsoleOptions {
1050
+ parent?: Console;
1051
+ bind?: boolean;
1052
+ }
1053
+
1054
+ export declare function x(): number;
1055
+
1056
+ export { }