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