@ntnyq/utils 0.6.5 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -10
- package/dist/index.cjs +0 -1124
- package/dist/index.d.cts +0 -763
package/dist/index.d.cts
DELETED
|
@@ -1,763 +0,0 @@
|
|
|
1
|
-
//#region src/fn/noop.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* A function that does nothing.
|
|
4
|
-
*/
|
|
5
|
-
declare function noop(): void;
|
|
6
|
-
/**
|
|
7
|
-
* Alias of {@link noop}.
|
|
8
|
-
*/
|
|
9
|
-
declare const NOOP: typeof noop;
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region src/fn/once.d.ts
|
|
13
|
-
declare function once<T extends unknown[]>(func: (...args: T) => void): (this: unknown, ...args: T) => boolean;
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
|
-
//#region src/is/dom.d.ts
|
|
17
|
-
/**
|
|
18
|
-
* @file is/dom.ts
|
|
19
|
-
*/
|
|
20
|
-
/**
|
|
21
|
-
* Check if given value is an HTMLElement
|
|
22
|
-
* @param value - The value to check
|
|
23
|
-
* @returns True if the value is an HTMLElement, false otherwise
|
|
24
|
-
*/
|
|
25
|
-
declare function isHTMLElement(value: unknown): value is HTMLElement;
|
|
26
|
-
|
|
27
|
-
//#endregion
|
|
28
|
-
//#region src/is/core.d.ts
|
|
29
|
-
/**
|
|
30
|
-
* @file is utils
|
|
31
|
-
* @module is
|
|
32
|
-
* @copyright {@link https://github.com/sindresorhus/is}
|
|
33
|
-
*/
|
|
34
|
-
type Whitespace = " ";
|
|
35
|
-
type NonEmptyString = string & {
|
|
36
|
-
0: "";
|
|
37
|
-
};
|
|
38
|
-
declare function getObjectType(value: unknown): string;
|
|
39
|
-
declare function isUndefined(value: unknown): value is undefined;
|
|
40
|
-
declare function isNull(value: unknown): value is null;
|
|
41
|
-
declare function isNil(value: unknown): value is null | undefined;
|
|
42
|
-
declare const isNullOrUndefined: typeof isNil;
|
|
43
|
-
declare function isString(value: unknown): value is string;
|
|
44
|
-
declare function isEmptyString(value: unknown): value is "";
|
|
45
|
-
declare function isNonEmptyString(value: unknown): value is NonEmptyString;
|
|
46
|
-
declare function isWhitespaceString(value: unknown): value is Whitespace;
|
|
47
|
-
declare function isEmptyStringOrWhitespace(value: unknown): value is "" | Whitespace;
|
|
48
|
-
declare function isNumbericString(value: unknown): value is `${number}`;
|
|
49
|
-
declare function isNumber(value: unknown): value is number;
|
|
50
|
-
declare function isZero(value: unknown): value is 0;
|
|
51
|
-
declare function isNaN(value: unknown): value is typeof Number.NaN;
|
|
52
|
-
declare function isInteger(value: unknown): value is number;
|
|
53
|
-
declare function isBigInt(value: unknown): value is bigint;
|
|
54
|
-
declare function isBoolean(value: unknown): value is boolean;
|
|
55
|
-
declare function isTruthy<T>(value: T | undefined): value is T;
|
|
56
|
-
declare function isFunction(value: unknown): value is Function;
|
|
57
|
-
declare function isArray(value: unknown): value is unknown[];
|
|
58
|
-
declare function isEmptyArray(value: unknown): value is [];
|
|
59
|
-
declare function isNonEmptyArray<T = unknown, Item = unknown>(value: T | Item[]): value is [Item, ...Item[]];
|
|
60
|
-
declare function isObject(value: unknown): value is object;
|
|
61
|
-
declare function isEmptyObject(value: unknown): value is {};
|
|
62
|
-
declare function isMap<Key = unknown, Value = unknown>(value: unknown): value is Map<Key, Value>;
|
|
63
|
-
declare function isEmptyMap(value: unknown): value is Map<never, never>;
|
|
64
|
-
declare function isSet<Value = unknown>(value: unknown): value is Set<Value>;
|
|
65
|
-
declare function isEmptySet(value: unknown): value is Set<never>;
|
|
66
|
-
declare function isRegExp(value: unknown): value is RegExp;
|
|
67
|
-
declare function isError(value: unknown): value is Error;
|
|
68
|
-
declare function isNativePromise<T = unknown>(value: unknown): value is Promise<T>;
|
|
69
|
-
declare function isPromise<T = unknown>(value: unknown): value is Promise<T>;
|
|
70
|
-
declare function isIterable<T = unknown>(value: unknown): value is Iterable<T>;
|
|
71
|
-
|
|
72
|
-
//#endregion
|
|
73
|
-
//#region src/is/isDeepEqual.d.ts
|
|
74
|
-
/**
|
|
75
|
-
* check if two values are deeply equal
|
|
76
|
-
*/
|
|
77
|
-
declare function isDeepEqual(value1: any, value2: any): boolean;
|
|
78
|
-
|
|
79
|
-
//#endregion
|
|
80
|
-
//#region src/dom/scrollIntoView.d.ts
|
|
81
|
-
interface Options extends ScrollIntoViewOptions {
|
|
82
|
-
/**
|
|
83
|
-
* @default `document.body`
|
|
84
|
-
*/
|
|
85
|
-
parent?: HTMLElement;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Scroll element into view if it is out of view.
|
|
89
|
-
*
|
|
90
|
-
* @param element - element to scroll
|
|
91
|
-
* @param options - scroll options
|
|
92
|
-
*/
|
|
93
|
-
declare function scrollElementIntoView(element: HTMLElement, options?: Options): void;
|
|
94
|
-
|
|
95
|
-
//#endregion
|
|
96
|
-
//#region src/types/base.d.ts
|
|
97
|
-
type AnyFn<T = any, R = any> = (...args: T[]) => R;
|
|
98
|
-
type Arrayable<T> = T | T[];
|
|
99
|
-
type Awaitable<T> = Promise<T> | T;
|
|
100
|
-
type Callable<T> = AnyFn<any, T> | T;
|
|
101
|
-
type MayBe<T> = T | undefined;
|
|
102
|
-
type Nullable<T> = T | null;
|
|
103
|
-
/**
|
|
104
|
-
* Overwrite some keys type
|
|
105
|
-
*/
|
|
106
|
-
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
107
|
-
/**
|
|
108
|
-
* Prettify object type
|
|
109
|
-
*/
|
|
110
|
-
type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
111
|
-
type PrettifyV2<T> = Omit<T, never>;
|
|
112
|
-
type Primitive = bigint | boolean | number | string | symbol | AnyFn | null | undefined;
|
|
113
|
-
|
|
114
|
-
//#endregion
|
|
115
|
-
//#region src/types/deep.d.ts
|
|
116
|
-
type DeepRequired<T> = T extends Primitive ? NonNullable<T> : { [P in keyof T]-?: T[P] extends (infer U)[] ? DeepRequired<U>[] : T[P] extends readonly (infer V)[] ? NonNullable<V> : DeepRequired<T[P]> };
|
|
117
|
-
|
|
118
|
-
//#endregion
|
|
119
|
-
//#region src/types/json.d.ts
|
|
120
|
-
type JsonArray = JsonValue[] | readonly JsonValue[];
|
|
121
|
-
type JsonObject = { [Key in string]: JsonValue } & { [Key in string]?: JsonValue | undefined };
|
|
122
|
-
type JsonPrimitive = boolean | number | string | null;
|
|
123
|
-
/**
|
|
124
|
-
* @copyright {@link https://github.com/sindresorhus/type-fest/blob/main/source/basic.d.ts}
|
|
125
|
-
*/
|
|
126
|
-
type JsonValue = JsonArray | JsonObject | JsonPrimitive;
|
|
127
|
-
|
|
128
|
-
//#endregion
|
|
129
|
-
//#region src/types/utils.d.ts
|
|
130
|
-
/**
|
|
131
|
-
* A literal type that supports custom further strings but preserves autocompletion in IDEs.
|
|
132
|
-
*
|
|
133
|
-
* @see {@link https://github.com/microsoft/TypeScript/issues/29729#issuecomment-471566609}
|
|
134
|
-
*/
|
|
135
|
-
type LiteralUnion<Union extends Base, Base = string> = Union | (Base & {
|
|
136
|
-
zz_IGNORE_ME?: never;
|
|
137
|
-
});
|
|
138
|
-
/**
|
|
139
|
-
* @see {@link TODO:}
|
|
140
|
-
*/
|
|
141
|
-
type Merge<T, U> = keyof T & keyof U extends never ? T & U : Omit<T, keyof T & keyof U> & U;
|
|
142
|
-
/**
|
|
143
|
-
* Non empty object `{}`
|
|
144
|
-
*/
|
|
145
|
-
type NonEmptyObject<T> = T extends Record<string, never> ? never : T;
|
|
146
|
-
|
|
147
|
-
//#endregion
|
|
148
|
-
//#region src/types/module.d.ts
|
|
149
|
-
/**
|
|
150
|
-
* interop module
|
|
151
|
-
*/
|
|
152
|
-
type InteropModuleDefault<T> = T extends {
|
|
153
|
-
default: infer U;
|
|
154
|
-
} ? U : T;
|
|
155
|
-
/**
|
|
156
|
-
* Resolve `boolean | Options` to `Options`
|
|
157
|
-
*/
|
|
158
|
-
type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>;
|
|
159
|
-
|
|
160
|
-
//#endregion
|
|
161
|
-
//#region src/dom/openExternalURL.d.ts
|
|
162
|
-
interface OpenExternalURLOptions {
|
|
163
|
-
/**
|
|
164
|
-
* open target
|
|
165
|
-
*
|
|
166
|
-
* @default `_blank`
|
|
167
|
-
*/
|
|
168
|
-
target?: LiteralUnion<"_self" | "_top" | "_blank" | "_parent">;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Open external url
|
|
172
|
-
* @param url - URL to open
|
|
173
|
-
* @param options - open options
|
|
174
|
-
* @returns window proxy
|
|
175
|
-
*/
|
|
176
|
-
declare function openExternalURL(url: string | URL, options?: OpenExternalURLOptions): WindowProxy | null;
|
|
177
|
-
|
|
178
|
-
//#endregion
|
|
179
|
-
//#region src/dom/isVisibleInViewport.d.ts
|
|
180
|
-
/**
|
|
181
|
-
* Check if element is in viewport
|
|
182
|
-
* @param element - checked element
|
|
183
|
-
* @param targetWindow - window
|
|
184
|
-
* @returns true if element is in viewport, false otherwise
|
|
185
|
-
*/
|
|
186
|
-
declare function isElementVisibleInViewport(element: HTMLElement, targetWindow?: Window): boolean;
|
|
187
|
-
|
|
188
|
-
//#endregion
|
|
189
|
-
//#region src/env/isBrowser.d.ts
|
|
190
|
-
/**
|
|
191
|
-
* @file env.ts
|
|
192
|
-
*/
|
|
193
|
-
/**
|
|
194
|
-
* Checks if the code is running in a browser
|
|
195
|
-
*
|
|
196
|
-
* @returns boolean - true if the code is running in a browser
|
|
197
|
-
*/
|
|
198
|
-
declare const isBrowser: () => boolean;
|
|
199
|
-
|
|
200
|
-
//#endregion
|
|
201
|
-
//#region src/html/escape.d.ts
|
|
202
|
-
/**
|
|
203
|
-
* Escape html chars
|
|
204
|
-
*/
|
|
205
|
-
declare function escapeHTML(str: string): string;
|
|
206
|
-
/**
|
|
207
|
-
* Unescape html chars
|
|
208
|
-
*/
|
|
209
|
-
declare function unescapeHTML(str: string): string;
|
|
210
|
-
|
|
211
|
-
//#endregion
|
|
212
|
-
//#region src/misc/raf.d.ts
|
|
213
|
-
/**
|
|
214
|
-
* Request animation frame
|
|
215
|
-
*
|
|
216
|
-
* @param fn - callback
|
|
217
|
-
* @returns id
|
|
218
|
-
*/
|
|
219
|
-
declare function rAF(fn: FrameRequestCallback): number;
|
|
220
|
-
/**
|
|
221
|
-
* Cancel animation frame
|
|
222
|
-
*
|
|
223
|
-
* @param id - id
|
|
224
|
-
* @returns void
|
|
225
|
-
*/
|
|
226
|
-
declare function cAF(id: number): void;
|
|
227
|
-
|
|
228
|
-
//#endregion
|
|
229
|
-
//#region src/misc/time.d.ts
|
|
230
|
-
declare function seconds(count: number): number;
|
|
231
|
-
declare function minutes(count: number): number;
|
|
232
|
-
declare function hours(count: number): number;
|
|
233
|
-
declare function days(count: number): number;
|
|
234
|
-
declare function weeks(count: number): number;
|
|
235
|
-
|
|
236
|
-
//#endregion
|
|
237
|
-
//#region src/misc/clamp.d.ts
|
|
238
|
-
/**
|
|
239
|
-
* Clamps a number between a minimum and maximum value
|
|
240
|
-
* @param value - the value to clamp within the given range
|
|
241
|
-
* @param min - the minimum value to clamp
|
|
242
|
-
* @param max - the maximum value to clamp
|
|
243
|
-
* @returns the new value
|
|
244
|
-
*/
|
|
245
|
-
declare function clamp(value: number, min?: number, max?: number): number;
|
|
246
|
-
|
|
247
|
-
//#endregion
|
|
248
|
-
//#region src/misc/waitFor.d.ts
|
|
249
|
-
/**
|
|
250
|
-
* Wait for a number of milliseconds
|
|
251
|
-
*
|
|
252
|
-
* @param ms - millseconds to wait
|
|
253
|
-
* @returns a promise that resolves after ms milliseconds
|
|
254
|
-
*
|
|
255
|
-
* @example
|
|
256
|
-
* ```
|
|
257
|
-
* import { waitFor } from '@ntnyq/utils'
|
|
258
|
-
* await waitFor(3e3)
|
|
259
|
-
* // do somthing after 3 seconds
|
|
260
|
-
* ```
|
|
261
|
-
*/
|
|
262
|
-
declare function waitFor(ms: number): Promise<void>;
|
|
263
|
-
|
|
264
|
-
//#endregion
|
|
265
|
-
//#region src/misc/throttle.d.ts
|
|
266
|
-
interface ThrottleDebounceOptions {
|
|
267
|
-
/**
|
|
268
|
-
* @default false
|
|
269
|
-
*/
|
|
270
|
-
isDebounce?: boolean;
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Throttle a function to limit its execution to a maximum of once per a specified time interval.
|
|
274
|
-
*
|
|
275
|
-
* @param delay - Zero or greater delay in milliseconds
|
|
276
|
-
* @param callback - A function to be throttled
|
|
277
|
-
* @param options - throttle options
|
|
278
|
-
* @returns A throttled function
|
|
279
|
-
*/
|
|
280
|
-
declare function throttle<T extends ((...args: any[]) => undefined | void) | undefined | null>(delay: number, callback: Exclude<T, undefined | null>, options?: ThrottleDebounceOptions): T & {
|
|
281
|
-
cancel: () => void;
|
|
282
|
-
};
|
|
283
|
-
declare function debounce<T extends ((...args: any[]) => undefined | void) | undefined | null>(delay: number, callback: Exclude<T, undefined | null>, options?: ThrottleDebounceOptions): T & {
|
|
284
|
-
cancel: () => void;
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
//#endregion
|
|
288
|
-
//#region src/misc/warnOnce.d.ts
|
|
289
|
-
/**
|
|
290
|
-
* Warn message only once
|
|
291
|
-
*
|
|
292
|
-
* @param message - warning message
|
|
293
|
-
*/
|
|
294
|
-
declare function warnOnce(message: string): void;
|
|
295
|
-
|
|
296
|
-
//#endregion
|
|
297
|
-
//#region src/array/at.d.ts
|
|
298
|
-
/**
|
|
299
|
-
* Get array item by index, negative for backward
|
|
300
|
-
* @param array - given array
|
|
301
|
-
* @param index - index of item
|
|
302
|
-
* @returns undefined if not match, otherwise matched item
|
|
303
|
-
*/
|
|
304
|
-
declare function at<T>(array: readonly T[], index: number): T | undefined;
|
|
305
|
-
/**
|
|
306
|
-
* Get the last item of given array
|
|
307
|
-
* @param array - given array
|
|
308
|
-
* @returns undefined if empty array, otherwise last item
|
|
309
|
-
*/
|
|
310
|
-
declare function last<T>(array: readonly T[]): T | undefined;
|
|
311
|
-
|
|
312
|
-
//#endregion
|
|
313
|
-
//#region src/array/chunk.d.ts
|
|
314
|
-
/**
|
|
315
|
-
* Splits an array into smaller chunks of a given size.
|
|
316
|
-
* @param array - The array to split
|
|
317
|
-
* @param size - The size of each chunk
|
|
318
|
-
* @returns An array of arrays, where each sub-array has `size` elements from the original array.
|
|
319
|
-
*/
|
|
320
|
-
declare function chunk<T>(array: T[], size: number): T[][];
|
|
321
|
-
|
|
322
|
-
//#endregion
|
|
323
|
-
//#region src/array/unique.d.ts
|
|
324
|
-
/**
|
|
325
|
-
* Returns a new array with unique values.
|
|
326
|
-
* @param array - The array to process.
|
|
327
|
-
* @returns The new array.
|
|
328
|
-
*/
|
|
329
|
-
declare function unique<T>(array: T[]): T[];
|
|
330
|
-
/**
|
|
331
|
-
* Returns a new array with unique values.
|
|
332
|
-
* @param array - The array to process.
|
|
333
|
-
* @param equalFn - The function to compare values.
|
|
334
|
-
* @returns The new array.
|
|
335
|
-
*/
|
|
336
|
-
declare function uniqueBy<T>(array: T[], equalFn: (a: T, b: T) => boolean): T[];
|
|
337
|
-
|
|
338
|
-
//#endregion
|
|
339
|
-
//#region src/array/toArray.d.ts
|
|
340
|
-
/**
|
|
341
|
-
* Converts a value to an array.
|
|
342
|
-
* @param array - The value to convert.
|
|
343
|
-
* @returns The array.
|
|
344
|
-
*/
|
|
345
|
-
declare function toArray<T>(array?: Nullable<Arrayable<T>>): T[];
|
|
346
|
-
|
|
347
|
-
//#endregion
|
|
348
|
-
//#region src/array/arrayable.d.ts
|
|
349
|
-
/**
|
|
350
|
-
* Convert `Arrayable<T>` to `Array<T>` and flatten the result
|
|
351
|
-
* @param array - given array
|
|
352
|
-
* @returns Array<T>
|
|
353
|
-
*/
|
|
354
|
-
declare function flattenArrayable<T>(array?: Nullable<Arrayable<T | Array<T>>>): Array<T>;
|
|
355
|
-
/**
|
|
356
|
-
* Use rest arguments to merge arrays
|
|
357
|
-
* @param args - rest arguments
|
|
358
|
-
* @returns Array<T>
|
|
359
|
-
*/
|
|
360
|
-
declare function mergeArrayable<T>(...args: Nullable<Arrayable<T>>[]): Array<T>;
|
|
361
|
-
|
|
362
|
-
//#endregion
|
|
363
|
-
//#region src/array/intersect.d.ts
|
|
364
|
-
/**
|
|
365
|
-
* Get intersect items
|
|
366
|
-
*
|
|
367
|
-
* @returns intersect items
|
|
368
|
-
*/
|
|
369
|
-
declare function intersect<T>(a: T[], b: T[]): T[];
|
|
370
|
-
|
|
371
|
-
//#endregion
|
|
372
|
-
//#region src/array/isArrayEqual.d.ts
|
|
373
|
-
/**
|
|
374
|
-
* Check if values of two arrays are equal
|
|
375
|
-
* @param array1 - array 1
|
|
376
|
-
* @param array2 - array 2
|
|
377
|
-
* @returns `true` if equal
|
|
378
|
-
*/
|
|
379
|
-
declare function isArrayEqual(array1: unknown[], array2: unknown[]): boolean;
|
|
380
|
-
|
|
381
|
-
//#endregion
|
|
382
|
-
//#region src/color/color.d.ts
|
|
383
|
-
declare class Color {
|
|
384
|
-
red: number;
|
|
385
|
-
green: number;
|
|
386
|
-
blue: number;
|
|
387
|
-
alpha: number;
|
|
388
|
-
constructor(red?: number, green?: number, blue?: number, alpha?: number);
|
|
389
|
-
static fromRGB(red: number, green: number, blue: number): Color;
|
|
390
|
-
static fromRGBA(red: number, green: number, blue: number, alpha: number): Color;
|
|
391
|
-
static fromHex(hex: string): Color;
|
|
392
|
-
get brightness(): number;
|
|
393
|
-
get isDark(): boolean;
|
|
394
|
-
get isLight(): boolean;
|
|
395
|
-
toHexString(isUpperCase?: boolean): string;
|
|
396
|
-
toRGBAString(): string;
|
|
397
|
-
/**
|
|
398
|
-
* add alpha value to {@link Color}
|
|
399
|
-
*
|
|
400
|
-
* @param alpha - alpha value
|
|
401
|
-
* @returns instance of {@link Color}
|
|
402
|
-
*/
|
|
403
|
-
withAlpha(alpha?: number): Color;
|
|
404
|
-
/**
|
|
405
|
-
* lighten the color by percentage
|
|
406
|
-
*
|
|
407
|
-
* @param percentage - percentage to lighten
|
|
408
|
-
*/
|
|
409
|
-
lighten(percentage?: number): Color;
|
|
410
|
-
/**
|
|
411
|
-
* darken the color by percentage
|
|
412
|
-
*
|
|
413
|
-
* @param percentage - percentage to darken
|
|
414
|
-
*/
|
|
415
|
-
darken(percentage?: number): Color;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
//#endregion
|
|
419
|
-
//#region src/color/random.d.ts
|
|
420
|
-
/**
|
|
421
|
-
* get a random RGB color
|
|
422
|
-
* @returns a random RGB color
|
|
423
|
-
*/
|
|
424
|
-
declare function randomRGBColor(): string;
|
|
425
|
-
/**
|
|
426
|
-
* get a random RGBA color
|
|
427
|
-
* @returns a random RGBA color
|
|
428
|
-
*/
|
|
429
|
-
declare function randomRGBAColor(): string;
|
|
430
|
-
/**
|
|
431
|
-
* get a random hex color
|
|
432
|
-
* @returns a random hex color
|
|
433
|
-
*/
|
|
434
|
-
declare function randomHexColor(): string;
|
|
435
|
-
|
|
436
|
-
//#endregion
|
|
437
|
-
//#region src/proxy/enhance.d.ts
|
|
438
|
-
/**
|
|
439
|
-
* enhance object
|
|
440
|
-
* @module proxy
|
|
441
|
-
*/
|
|
442
|
-
declare function enhance<T extends Record<PropertyKey, any>, E extends Record<PropertyKey, any>>(module: T, extra: E): T;
|
|
443
|
-
|
|
444
|
-
//#endregion
|
|
445
|
-
//#region src/module/interopDefault.d.ts
|
|
446
|
-
/**
|
|
447
|
-
* Interop default export from a module
|
|
448
|
-
*
|
|
449
|
-
* @param mod - The module
|
|
450
|
-
* @returns The default export
|
|
451
|
-
*
|
|
452
|
-
* @example
|
|
453
|
-
*
|
|
454
|
-
* ```ts
|
|
455
|
-
* import { interopDefault } from '@ntnyq/utils'
|
|
456
|
-
*
|
|
457
|
-
* const { unindent } = await interopDefault(import('@ntnyq/utils'))
|
|
458
|
-
* ```
|
|
459
|
-
*/
|
|
460
|
-
declare function interopDefault<T>(mod: Awaitable<T>): Promise<InteropModuleDefault<T>>;
|
|
461
|
-
|
|
462
|
-
//#endregion
|
|
463
|
-
//#region src/module/resolveSubOptions.d.ts
|
|
464
|
-
/**
|
|
465
|
-
* Resolve sub options `boolean | Options` to `Options`
|
|
466
|
-
* @param options - core options
|
|
467
|
-
* @param key - sub options key
|
|
468
|
-
* @returns resolved sub options
|
|
469
|
-
*
|
|
470
|
-
* @example
|
|
471
|
-
*
|
|
472
|
-
* ```ts
|
|
473
|
-
* import { resolveSubOptions } from '@ntnyq/utils'
|
|
474
|
-
*
|
|
475
|
-
* interface Options {
|
|
476
|
-
* compile?: boolean | {
|
|
477
|
-
* include?: string[]
|
|
478
|
-
* exclude?: string[]
|
|
479
|
-
* }
|
|
480
|
-
* }
|
|
481
|
-
*
|
|
482
|
-
* const options: Options = {
|
|
483
|
-
* compile: true
|
|
484
|
-
* }
|
|
485
|
-
*
|
|
486
|
-
* console.log(resolveSubOptions(options, 'compile'))
|
|
487
|
-
*
|
|
488
|
-
* // => {}
|
|
489
|
-
* ```
|
|
490
|
-
*/
|
|
491
|
-
declare function resolveSubOptions<T extends Record<string, any>, K extends keyof T>(options: T, key: K): Partial<ResolvedOptions<T[K]>>;
|
|
492
|
-
|
|
493
|
-
//#endregion
|
|
494
|
-
//#region src/number/random.d.ts
|
|
495
|
-
interface RamdomNumberOptions {
|
|
496
|
-
/**
|
|
497
|
-
* include max value
|
|
498
|
-
*
|
|
499
|
-
* @default false
|
|
500
|
-
*/
|
|
501
|
-
includeMax?: boolean;
|
|
502
|
-
}
|
|
503
|
-
/**
|
|
504
|
-
* random an integer by given range
|
|
505
|
-
*
|
|
506
|
-
* @param min - min value
|
|
507
|
-
* @param max - max value
|
|
508
|
-
* @returns random integer in range
|
|
509
|
-
*/
|
|
510
|
-
declare function randomNumber(min: number, max?: number, options?: RamdomNumberOptions): number;
|
|
511
|
-
|
|
512
|
-
//#endregion
|
|
513
|
-
//#region src/number/toInteger.d.ts
|
|
514
|
-
interface ToIntegerOptions {
|
|
515
|
-
/**
|
|
516
|
-
* The number to convert to an integer.
|
|
517
|
-
*
|
|
518
|
-
* @default 0
|
|
519
|
-
*/
|
|
520
|
-
defaultValue?: number;
|
|
521
|
-
/**
|
|
522
|
-
* @default false
|
|
523
|
-
*/
|
|
524
|
-
allowDecimal?: boolean;
|
|
525
|
-
/**
|
|
526
|
-
* @default false
|
|
527
|
-
*/
|
|
528
|
-
allowNaN?: boolean;
|
|
529
|
-
/**
|
|
530
|
-
* @default `useDefault`
|
|
531
|
-
*/
|
|
532
|
-
onError?: "useDefault" | "throwError" | "returnOriginal";
|
|
533
|
-
/**
|
|
534
|
-
* Minimum value of the number. included
|
|
535
|
-
*/
|
|
536
|
-
min?: number;
|
|
537
|
-
/**
|
|
538
|
-
* Maximum value of the number. included
|
|
539
|
-
*/
|
|
540
|
-
max?: number;
|
|
541
|
-
/**
|
|
542
|
-
* @default `clamp`
|
|
543
|
-
*/
|
|
544
|
-
outOfRange?: "clamp" | "useDefault" | "throwError";
|
|
545
|
-
}
|
|
546
|
-
/**
|
|
547
|
-
* Transforms a value to an integer.
|
|
548
|
-
* @param value - The value to convert to an integer.
|
|
549
|
-
* @param options - Options for the conversion.
|
|
550
|
-
* @returns The converted integer.
|
|
551
|
-
*/
|
|
552
|
-
declare function toInteger(value: unknown, options?: ToIntegerOptions): number;
|
|
553
|
-
|
|
554
|
-
//#endregion
|
|
555
|
-
//#region src/object/omit.d.ts
|
|
556
|
-
declare function omit<T, K extends keyof T>(object: T, ...keys: K[]): Omit<T, K>;
|
|
557
|
-
|
|
558
|
-
//#endregion
|
|
559
|
-
//#region src/object/pick.d.ts
|
|
560
|
-
declare function pick<T, K extends keyof T>(object: T, keys: K[]): Pick<T, K>;
|
|
561
|
-
|
|
562
|
-
//#endregion
|
|
563
|
-
//#region src/object/clean.d.ts
|
|
564
|
-
interface CleanObjectOptions {
|
|
565
|
-
/**
|
|
566
|
-
* clean undefined
|
|
567
|
-
*
|
|
568
|
-
* @default true
|
|
569
|
-
*/
|
|
570
|
-
cleanUndefined?: boolean;
|
|
571
|
-
/**
|
|
572
|
-
* clean null
|
|
573
|
-
*
|
|
574
|
-
* @default true
|
|
575
|
-
*/
|
|
576
|
-
cleanNull?: boolean;
|
|
577
|
-
/**
|
|
578
|
-
* clean zero
|
|
579
|
-
*
|
|
580
|
-
* @default false
|
|
581
|
-
*/
|
|
582
|
-
cleanZero?: boolean;
|
|
583
|
-
/**
|
|
584
|
-
* clean NaN
|
|
585
|
-
*
|
|
586
|
-
* @default true
|
|
587
|
-
*/
|
|
588
|
-
cleanNaN?: boolean;
|
|
589
|
-
/**
|
|
590
|
-
* clean empty string
|
|
591
|
-
*
|
|
592
|
-
* @default false
|
|
593
|
-
*/
|
|
594
|
-
cleanEmptyString?: boolean;
|
|
595
|
-
/**
|
|
596
|
-
* clean empty array
|
|
597
|
-
*
|
|
598
|
-
* @default false
|
|
599
|
-
*/
|
|
600
|
-
cleanEmptyArray?: boolean;
|
|
601
|
-
/**
|
|
602
|
-
* clean empty object
|
|
603
|
-
*
|
|
604
|
-
* @default false
|
|
605
|
-
*/
|
|
606
|
-
cleanEmptyObject?: boolean;
|
|
607
|
-
/**
|
|
608
|
-
* recursive clean object
|
|
609
|
-
*
|
|
610
|
-
* @default true
|
|
611
|
-
*/
|
|
612
|
-
recursive?: boolean;
|
|
613
|
-
}
|
|
614
|
-
/**
|
|
615
|
-
* clean undefined, null, zero, empty string, empty array, empty object from object
|
|
616
|
-
* @param obj - object to be cleaned
|
|
617
|
-
* @param options - clean options
|
|
618
|
-
* @returns cleaned object
|
|
619
|
-
*/
|
|
620
|
-
declare function cleanObject<T extends object>(obj: T, options?: CleanObjectOptions): T;
|
|
621
|
-
|
|
622
|
-
//#endregion
|
|
623
|
-
//#region src/object/hasOwn.d.ts
|
|
624
|
-
/**
|
|
625
|
-
* check object has a property with given key
|
|
626
|
-
* @param object - the object to check
|
|
627
|
-
* @param key - the key to check
|
|
628
|
-
* @returns true if object has a property with given key, false otherwise
|
|
629
|
-
*/
|
|
630
|
-
declare function hasOwn<T>(object: T, key: PropertyKey): boolean;
|
|
631
|
-
|
|
632
|
-
//#endregion
|
|
633
|
-
//#region src/object/sortObject.d.ts
|
|
634
|
-
interface SortObjectOptions {
|
|
635
|
-
/**
|
|
636
|
-
* Recursive sorting
|
|
637
|
-
* @default false
|
|
638
|
-
*/
|
|
639
|
-
deep?: boolean;
|
|
640
|
-
/**
|
|
641
|
-
* Compare function
|
|
642
|
-
*/
|
|
643
|
-
compareFn?: (left: string, right: string) => number;
|
|
644
|
-
}
|
|
645
|
-
/**
|
|
646
|
-
* Sort object properties
|
|
647
|
-
*/
|
|
648
|
-
declare function sortObject<T extends Record<string, any>>(obj: T, options?: SortObjectOptions): T;
|
|
649
|
-
|
|
650
|
-
//#endregion
|
|
651
|
-
//#region src/string/pad.d.ts
|
|
652
|
-
interface CreatePadStringOptions {
|
|
653
|
-
length: number;
|
|
654
|
-
char: string;
|
|
655
|
-
}
|
|
656
|
-
declare function createPadString(options: CreatePadStringOptions): (value: string) => string;
|
|
657
|
-
|
|
658
|
-
//#endregion
|
|
659
|
-
//#region src/string/join.d.ts
|
|
660
|
-
type JoinableValue = string | number | null | undefined;
|
|
661
|
-
interface JoinOptions {
|
|
662
|
-
/**
|
|
663
|
-
* @default ''
|
|
664
|
-
*/
|
|
665
|
-
separator?: string;
|
|
666
|
-
}
|
|
667
|
-
/**
|
|
668
|
-
* Joins an array of strings or numbers into a single string.
|
|
669
|
-
* @param array - An array of strings or numbers.
|
|
670
|
-
* @param options - An object of options.
|
|
671
|
-
* @returns A string.
|
|
672
|
-
*/
|
|
673
|
-
declare function join(array: JoinableValue[], options?: JoinOptions): string;
|
|
674
|
-
|
|
675
|
-
//#endregion
|
|
676
|
-
//#region src/string/slash.d.ts
|
|
677
|
-
/**
|
|
678
|
-
* Replace backslash to slash
|
|
679
|
-
*/
|
|
680
|
-
declare function slash(input: string): string;
|
|
681
|
-
|
|
682
|
-
//#endregion
|
|
683
|
-
//#region src/string/random.d.ts
|
|
684
|
-
/**
|
|
685
|
-
* randome a string useing given chars
|
|
686
|
-
*
|
|
687
|
-
* @param length - string length
|
|
688
|
-
* @param chars - string chars
|
|
689
|
-
* @returns random string
|
|
690
|
-
*/
|
|
691
|
-
declare function randomString(length?: number, chars?: string): string;
|
|
692
|
-
|
|
693
|
-
//#endregion
|
|
694
|
-
//#region src/string/slugify.d.ts
|
|
695
|
-
/**
|
|
696
|
-
* Default slugify function
|
|
697
|
-
*/
|
|
698
|
-
declare function slugify(str: string): string;
|
|
699
|
-
|
|
700
|
-
//#endregion
|
|
701
|
-
//#region src/string/unindent.d.ts
|
|
702
|
-
/**
|
|
703
|
-
* Remove common leading whitespace from a template string
|
|
704
|
-
* Empty lines at the beginning and end of the template string are also removed.
|
|
705
|
-
* @param input - template string
|
|
706
|
-
*
|
|
707
|
-
* @example
|
|
708
|
-
*
|
|
709
|
-
* ```ts
|
|
710
|
-
* const str = unindent`
|
|
711
|
-
* if (foo) {
|
|
712
|
-
* bar()
|
|
713
|
-
* }
|
|
714
|
-
* `
|
|
715
|
-
* ```
|
|
716
|
-
*/
|
|
717
|
-
declare function unindent(input: TemplateStringsArray | string): string;
|
|
718
|
-
|
|
719
|
-
//#endregion
|
|
720
|
-
//#region src/string/getLength.d.ts
|
|
721
|
-
/**
|
|
722
|
-
* Counts graphemes in a given string
|
|
723
|
-
* @param value - A string to count graphemes.
|
|
724
|
-
* @returns The number of graphemes in `value`.
|
|
725
|
-
*/
|
|
726
|
-
declare function getStringLength(value: string): number;
|
|
727
|
-
|
|
728
|
-
//#endregion
|
|
729
|
-
//#region src/string/ensurePrefix.d.ts
|
|
730
|
-
declare function ensurePrefix(input: string, prefix: string): string;
|
|
731
|
-
|
|
732
|
-
//#endregion
|
|
733
|
-
//#region src/string/ensureSuffix.d.ts
|
|
734
|
-
declare function ensureSuffix(input: string, suffix: string): string;
|
|
735
|
-
|
|
736
|
-
//#endregion
|
|
737
|
-
//#region src/constants/char.d.ts
|
|
738
|
-
/**
|
|
739
|
-
* Special chars
|
|
740
|
-
*/
|
|
741
|
-
declare const SPECIAL_CHAR: {
|
|
742
|
-
newline: string;
|
|
743
|
-
};
|
|
744
|
-
|
|
745
|
-
//#endregion
|
|
746
|
-
//#region src/constants/regexp.d.ts
|
|
747
|
-
/**
|
|
748
|
-
* 注释正则
|
|
749
|
-
*
|
|
750
|
-
* 匹配 \<!-- 或 /* 开头的注释,直到 --> 或 *\/ 结尾
|
|
751
|
-
*/
|
|
752
|
-
declare const RE_COMMENTS: RegExp;
|
|
753
|
-
/**
|
|
754
|
-
* JavaScript line comment
|
|
755
|
-
*/
|
|
756
|
-
declare const RE_LINE_COMMENT: RegExp;
|
|
757
|
-
/**
|
|
758
|
-
* JavaScript block comment
|
|
759
|
-
*/
|
|
760
|
-
declare const RE_BLOCK_COMMENT: RegExp;
|
|
761
|
-
|
|
762
|
-
//#endregion
|
|
763
|
-
export { AnyFn, Arrayable, Awaitable, Callable, CleanObjectOptions, Color, CreatePadStringOptions, DeepRequired, InteropModuleDefault, JsonArray, JsonObject, JsonPrimitive, JsonValue, LiteralUnion, MayBe, Merge, NOOP, NonEmptyObject, NonEmptyString, Nullable, OpenExternalURLOptions, Overwrite, Prettify, PrettifyV2, Primitive, RE_BLOCK_COMMENT, RE_COMMENTS, RE_LINE_COMMENT, RamdomNumberOptions, ResolvedOptions, SPECIAL_CHAR, SortObjectOptions, ThrottleDebounceOptions, ToIntegerOptions, Whitespace, at, cAF, chunk, clamp, cleanObject, createPadString, days, debounce, enhance, ensurePrefix, ensureSuffix, escapeHTML, flattenArrayable, getObjectType, getStringLength, hasOwn, hours, interopDefault, intersect, isArray, isArrayEqual, isBigInt, isBoolean, isBrowser, isDeepEqual, isElementVisibleInViewport, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFunction, isHTMLElement, isInteger, isIterable, isMap, isNaN, isNativePromise, isNil, isNonEmptyArray, isNonEmptyString, isNull, isNullOrUndefined, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isTruthy, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, openExternalURL, pick, rAF, randomHexColor, randomNumber, randomRGBAColor, randomRGBColor, randomString, resolveSubOptions, scrollElementIntoView, seconds, slash, slugify, sortObject, throttle, toArray, toInteger, unescapeHTML, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
|