@ntnyq/utils 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +13 -53
- package/dist/index.js +20 -20
- package/package.json +8 -8
package/dist/index.d.ts
CHANGED
|
@@ -7,11 +7,9 @@ declare function noop(): void;
|
|
|
7
7
|
* Alias of {@link noop}.
|
|
8
8
|
*/
|
|
9
9
|
declare const NOOP: typeof noop;
|
|
10
|
-
|
|
11
10
|
//#endregion
|
|
12
11
|
//#region src/fn/once.d.ts
|
|
13
12
|
declare function once<T extends unknown[]>(func: (...args: T) => void): (this: unknown, ...args: T) => boolean;
|
|
14
|
-
|
|
15
13
|
//#endregion
|
|
16
14
|
//#region src/is/dom.d.ts
|
|
17
15
|
/**
|
|
@@ -23,7 +21,6 @@ declare function once<T extends unknown[]>(func: (...args: T) => void): (this: u
|
|
|
23
21
|
* @returns True if the value is an HTMLElement, false otherwise
|
|
24
22
|
*/
|
|
25
23
|
declare function isHTMLElement(value: unknown): value is HTMLElement;
|
|
26
|
-
|
|
27
24
|
//#endregion
|
|
28
25
|
//#region src/is/core.d.ts
|
|
29
26
|
/**
|
|
@@ -48,11 +45,12 @@ declare function isEmptyStringOrWhitespace(value: unknown): value is "" | Whites
|
|
|
48
45
|
declare function isNumbericString(value: unknown): value is `${number}`;
|
|
49
46
|
declare function isNumber(value: unknown): value is number;
|
|
50
47
|
declare function isZero(value: unknown): value is 0;
|
|
51
|
-
declare function isNaN(value: unknown): value is typeof
|
|
48
|
+
declare function isNaN(value: unknown): value is typeof NaN;
|
|
52
49
|
declare function isInteger(value: unknown): value is number;
|
|
53
50
|
declare function isBigInt(value: unknown): value is bigint;
|
|
54
51
|
declare function isBoolean(value: unknown): value is boolean;
|
|
55
52
|
declare function isTruthy<T>(value: T | undefined): value is T;
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
56
54
|
declare function isFunction(value: unknown): value is Function;
|
|
57
55
|
declare function isArray(value: unknown): value is unknown[];
|
|
58
56
|
declare function isEmptyArray(value: unknown): value is [];
|
|
@@ -68,14 +66,12 @@ declare function isError(value: unknown): value is Error;
|
|
|
68
66
|
declare function isNativePromise<T = unknown>(value: unknown): value is Promise<T>;
|
|
69
67
|
declare function isPromise<T = unknown>(value: unknown): value is Promise<T>;
|
|
70
68
|
declare function isIterable<T = unknown>(value: unknown): value is Iterable<T>;
|
|
71
|
-
|
|
72
69
|
//#endregion
|
|
73
70
|
//#region src/is/isDeepEqual.d.ts
|
|
74
71
|
/**
|
|
75
72
|
* check if two values are deeply equal
|
|
76
73
|
*/
|
|
77
74
|
declare function isDeepEqual(value1: any, value2: any): boolean;
|
|
78
|
-
|
|
79
75
|
//#endregion
|
|
80
76
|
//#region src/dom/scrollIntoView.d.ts
|
|
81
77
|
interface Options extends ScrollIntoViewOptions {
|
|
@@ -91,7 +87,6 @@ interface Options extends ScrollIntoViewOptions {
|
|
|
91
87
|
* @param options - scroll options
|
|
92
88
|
*/
|
|
93
89
|
declare function scrollElementIntoView(element: HTMLElement, options?: Options): void;
|
|
94
|
-
|
|
95
90
|
//#endregion
|
|
96
91
|
//#region src/types/base.d.ts
|
|
97
92
|
type AnyFn<T = any, R = any> = (...args: T[]) => R;
|
|
@@ -110,11 +105,9 @@ type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
|
110
105
|
type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
111
106
|
type PrettifyV2<T> = Omit<T, never>;
|
|
112
107
|
type Primitive = bigint | boolean | number | string | symbol | AnyFn | null | undefined;
|
|
113
|
-
|
|
114
108
|
//#endregion
|
|
115
109
|
//#region src/types/deep.d.ts
|
|
116
110
|
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
111
|
//#endregion
|
|
119
112
|
//#region src/types/json.d.ts
|
|
120
113
|
type JsonArray = JsonValue[] | readonly JsonValue[];
|
|
@@ -124,7 +117,6 @@ type JsonPrimitive = boolean | number | string | null;
|
|
|
124
117
|
* @copyright {@link https://github.com/sindresorhus/type-fest/blob/main/source/basic.d.ts}
|
|
125
118
|
*/
|
|
126
119
|
type JsonValue = JsonArray | JsonObject | JsonPrimitive;
|
|
127
|
-
|
|
128
120
|
//#endregion
|
|
129
121
|
//#region src/types/utils.d.ts
|
|
130
122
|
/**
|
|
@@ -143,7 +135,6 @@ type Merge<T, U> = keyof T & keyof U extends never ? T & U : Omit<T, keyof T & k
|
|
|
143
135
|
* Non empty object `{}`
|
|
144
136
|
*/
|
|
145
137
|
type NonEmptyObject<T> = T extends Record<string, never> ? never : T;
|
|
146
|
-
|
|
147
138
|
//#endregion
|
|
148
139
|
//#region src/types/module.d.ts
|
|
149
140
|
/**
|
|
@@ -156,7 +147,6 @@ type InteropModuleDefault<T> = T extends {
|
|
|
156
147
|
* Resolve `boolean | Options` to `Options`
|
|
157
148
|
*/
|
|
158
149
|
type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>;
|
|
159
|
-
|
|
160
150
|
//#endregion
|
|
161
151
|
//#region src/dom/openExternalURL.d.ts
|
|
162
152
|
interface OpenExternalURLOptions {
|
|
@@ -174,7 +164,6 @@ interface OpenExternalURLOptions {
|
|
|
174
164
|
* @returns window proxy
|
|
175
165
|
*/
|
|
176
166
|
declare function openExternalURL(url: string | URL, options?: OpenExternalURLOptions): WindowProxy | null;
|
|
177
|
-
|
|
178
167
|
//#endregion
|
|
179
168
|
//#region src/dom/isVisibleInViewport.d.ts
|
|
180
169
|
/**
|
|
@@ -184,7 +173,6 @@ declare function openExternalURL(url: string | URL, options?: OpenExternalURLOpt
|
|
|
184
173
|
* @returns true if element is in viewport, false otherwise
|
|
185
174
|
*/
|
|
186
175
|
declare function isElementVisibleInViewport(element: HTMLElement, targetWindow?: Window): boolean;
|
|
187
|
-
|
|
188
176
|
//#endregion
|
|
189
177
|
//#region src/env/isBrowser.d.ts
|
|
190
178
|
/**
|
|
@@ -196,7 +184,6 @@ declare function isElementVisibleInViewport(element: HTMLElement, targetWindow?:
|
|
|
196
184
|
* @returns boolean - true if the code is running in a browser
|
|
197
185
|
*/
|
|
198
186
|
declare const isBrowser: () => boolean;
|
|
199
|
-
|
|
200
187
|
//#endregion
|
|
201
188
|
//#region src/html/escape.d.ts
|
|
202
189
|
/**
|
|
@@ -207,9 +194,9 @@ declare function escapeHTML(str: string): string;
|
|
|
207
194
|
* Unescape html chars
|
|
208
195
|
*/
|
|
209
196
|
declare function unescapeHTML(str: string): string;
|
|
210
|
-
|
|
211
197
|
//#endregion
|
|
212
198
|
//#region src/misc/raf.d.ts
|
|
199
|
+
declare function getRoot(): Window | typeof globalThis;
|
|
213
200
|
/**
|
|
214
201
|
* Request animation frame
|
|
215
202
|
*
|
|
@@ -224,15 +211,22 @@ declare function rAF(fn: FrameRequestCallback): number;
|
|
|
224
211
|
* @returns void
|
|
225
212
|
*/
|
|
226
213
|
declare function cAF(id: number): void;
|
|
227
|
-
|
|
228
214
|
//#endregion
|
|
229
215
|
//#region src/misc/time.d.ts
|
|
216
|
+
/**
|
|
217
|
+
* @file time utils
|
|
218
|
+
* @module Time
|
|
219
|
+
*/
|
|
220
|
+
declare const ONE_SECOND_MILLSECONDS: number;
|
|
221
|
+
declare const ONE_MINUTE_MILLSECONDS: number;
|
|
222
|
+
declare const ONE_HOUR_MILLSECONDS: number;
|
|
223
|
+
declare const ONE_DAY_MILLSECONDS: number;
|
|
224
|
+
declare const ONE_WEEK_MILLSECONDS: number;
|
|
230
225
|
declare function seconds(count: number): number;
|
|
231
226
|
declare function minutes(count: number): number;
|
|
232
227
|
declare function hours(count: number): number;
|
|
233
228
|
declare function days(count: number): number;
|
|
234
229
|
declare function weeks(count: number): number;
|
|
235
|
-
|
|
236
230
|
//#endregion
|
|
237
231
|
//#region src/misc/clamp.d.ts
|
|
238
232
|
/**
|
|
@@ -243,7 +237,6 @@ declare function weeks(count: number): number;
|
|
|
243
237
|
* @returns the new value
|
|
244
238
|
*/
|
|
245
239
|
declare function clamp(value: number, min?: number, max?: number): number;
|
|
246
|
-
|
|
247
240
|
//#endregion
|
|
248
241
|
//#region src/misc/waitFor.d.ts
|
|
249
242
|
/**
|
|
@@ -260,7 +253,6 @@ declare function clamp(value: number, min?: number, max?: number): number;
|
|
|
260
253
|
* ```
|
|
261
254
|
*/
|
|
262
255
|
declare function waitFor(ms: number): Promise<void>;
|
|
263
|
-
|
|
264
256
|
//#endregion
|
|
265
257
|
//#region src/misc/throttle.d.ts
|
|
266
258
|
interface ThrottleDebounceOptions {
|
|
@@ -283,7 +275,6 @@ declare function throttle<T extends ((...args: any[]) => undefined | void) | und
|
|
|
283
275
|
declare function debounce<T extends ((...args: any[]) => undefined | void) | undefined | null>(delay: number, callback: Exclude<T, undefined | null>, options?: ThrottleDebounceOptions): T & {
|
|
284
276
|
cancel: () => void;
|
|
285
277
|
};
|
|
286
|
-
|
|
287
278
|
//#endregion
|
|
288
279
|
//#region src/misc/warnOnce.d.ts
|
|
289
280
|
/**
|
|
@@ -292,7 +283,6 @@ declare function debounce<T extends ((...args: any[]) => undefined | void) | und
|
|
|
292
283
|
* @param message - warning message
|
|
293
284
|
*/
|
|
294
285
|
declare function warnOnce(message: string): void;
|
|
295
|
-
|
|
296
286
|
//#endregion
|
|
297
287
|
//#region src/array/at.d.ts
|
|
298
288
|
/**
|
|
@@ -308,7 +298,6 @@ declare function at<T>(array: readonly T[], index: number): T | undefined;
|
|
|
308
298
|
* @returns undefined if empty array, otherwise last item
|
|
309
299
|
*/
|
|
310
300
|
declare function last<T>(array: readonly T[]): T | undefined;
|
|
311
|
-
|
|
312
301
|
//#endregion
|
|
313
302
|
//#region src/array/chunk.d.ts
|
|
314
303
|
/**
|
|
@@ -318,7 +307,6 @@ declare function last<T>(array: readonly T[]): T | undefined;
|
|
|
318
307
|
* @returns An array of arrays, where each sub-array has `size` elements from the original array.
|
|
319
308
|
*/
|
|
320
309
|
declare function chunk<T>(array: T[], size: number): T[][];
|
|
321
|
-
|
|
322
310
|
//#endregion
|
|
323
311
|
//#region src/array/unique.d.ts
|
|
324
312
|
/**
|
|
@@ -334,7 +322,6 @@ declare function unique<T>(array: T[]): T[];
|
|
|
334
322
|
* @returns The new array.
|
|
335
323
|
*/
|
|
336
324
|
declare function uniqueBy<T>(array: T[], equalFn: (a: T, b: T) => boolean): T[];
|
|
337
|
-
|
|
338
325
|
//#endregion
|
|
339
326
|
//#region src/array/toArray.d.ts
|
|
340
327
|
/**
|
|
@@ -343,7 +330,6 @@ declare function uniqueBy<T>(array: T[], equalFn: (a: T, b: T) => boolean): T[];
|
|
|
343
330
|
* @returns The array.
|
|
344
331
|
*/
|
|
345
332
|
declare function toArray<T>(array?: Nullable<Arrayable<T>>): T[];
|
|
346
|
-
|
|
347
333
|
//#endregion
|
|
348
334
|
//#region src/array/arrayable.d.ts
|
|
349
335
|
/**
|
|
@@ -358,7 +344,6 @@ declare function flattenArrayable<T>(array?: Nullable<Arrayable<T | Array<T>>>):
|
|
|
358
344
|
* @returns Array<T>
|
|
359
345
|
*/
|
|
360
346
|
declare function mergeArrayable<T>(...args: Nullable<Arrayable<T>>[]): Array<T>;
|
|
361
|
-
|
|
362
347
|
//#endregion
|
|
363
348
|
//#region src/array/intersect.d.ts
|
|
364
349
|
/**
|
|
@@ -367,7 +352,6 @@ declare function mergeArrayable<T>(...args: Nullable<Arrayable<T>>[]): Array<T>;
|
|
|
367
352
|
* @returns intersect items
|
|
368
353
|
*/
|
|
369
354
|
declare function intersect<T>(a: T[], b: T[]): T[];
|
|
370
|
-
|
|
371
355
|
//#endregion
|
|
372
356
|
//#region src/array/isArrayEqual.d.ts
|
|
373
357
|
/**
|
|
@@ -377,7 +361,6 @@ declare function intersect<T>(a: T[], b: T[]): T[];
|
|
|
377
361
|
* @returns `true` if equal
|
|
378
362
|
*/
|
|
379
363
|
declare function isArrayEqual(array1: unknown[], array2: unknown[]): boolean;
|
|
380
|
-
|
|
381
364
|
//#endregion
|
|
382
365
|
//#region src/color/color.d.ts
|
|
383
366
|
declare class Color {
|
|
@@ -414,7 +397,6 @@ declare class Color {
|
|
|
414
397
|
*/
|
|
415
398
|
darken(percentage?: number): Color;
|
|
416
399
|
}
|
|
417
|
-
|
|
418
400
|
//#endregion
|
|
419
401
|
//#region src/color/random.d.ts
|
|
420
402
|
/**
|
|
@@ -432,7 +414,6 @@ declare function randomRGBAColor(): string;
|
|
|
432
414
|
* @returns a random hex color
|
|
433
415
|
*/
|
|
434
416
|
declare function randomHexColor(): string;
|
|
435
|
-
|
|
436
417
|
//#endregion
|
|
437
418
|
//#region src/proxy/enhance.d.ts
|
|
438
419
|
/**
|
|
@@ -440,7 +421,6 @@ declare function randomHexColor(): string;
|
|
|
440
421
|
* @module proxy
|
|
441
422
|
*/
|
|
442
423
|
declare function enhance<T extends Record<PropertyKey, any>, E extends Record<PropertyKey, any>>(module: T, extra: E): T;
|
|
443
|
-
|
|
444
424
|
//#endregion
|
|
445
425
|
//#region src/module/interopDefault.d.ts
|
|
446
426
|
/**
|
|
@@ -458,7 +438,6 @@ declare function enhance<T extends Record<PropertyKey, any>, E extends Record<Pr
|
|
|
458
438
|
* ```
|
|
459
439
|
*/
|
|
460
440
|
declare function interopDefault<T>(mod: Awaitable<T>): Promise<InteropModuleDefault<T>>;
|
|
461
|
-
|
|
462
441
|
//#endregion
|
|
463
442
|
//#region src/module/resolveSubOptions.d.ts
|
|
464
443
|
/**
|
|
@@ -489,7 +468,6 @@ declare function interopDefault<T>(mod: Awaitable<T>): Promise<InteropModuleDefa
|
|
|
489
468
|
* ```
|
|
490
469
|
*/
|
|
491
470
|
declare function resolveSubOptions<T extends Record<string, any>, K extends keyof T>(options: T, key: K): Partial<ResolvedOptions<T[K]>>;
|
|
492
|
-
|
|
493
471
|
//#endregion
|
|
494
472
|
//#region src/number/random.d.ts
|
|
495
473
|
interface RamdomNumberOptions {
|
|
@@ -508,7 +486,6 @@ interface RamdomNumberOptions {
|
|
|
508
486
|
* @returns random integer in range
|
|
509
487
|
*/
|
|
510
488
|
declare function randomNumber(min: number, max?: number, options?: RamdomNumberOptions): number;
|
|
511
|
-
|
|
512
489
|
//#endregion
|
|
513
490
|
//#region src/number/toInteger.d.ts
|
|
514
491
|
interface ToIntegerOptions {
|
|
@@ -550,15 +527,12 @@ interface ToIntegerOptions {
|
|
|
550
527
|
* @returns The converted integer.
|
|
551
528
|
*/
|
|
552
529
|
declare function toInteger(value: unknown, options?: ToIntegerOptions): number;
|
|
553
|
-
|
|
554
530
|
//#endregion
|
|
555
531
|
//#region src/object/omit.d.ts
|
|
556
532
|
declare function omit<T, K extends keyof T>(object: T, ...keys: K[]): Omit<T, K>;
|
|
557
|
-
|
|
558
533
|
//#endregion
|
|
559
534
|
//#region src/object/pick.d.ts
|
|
560
535
|
declare function pick<T, K extends keyof T>(object: T, keys: K[]): Pick<T, K>;
|
|
561
|
-
|
|
562
536
|
//#endregion
|
|
563
537
|
//#region src/object/clean.d.ts
|
|
564
538
|
interface CleanObjectOptions {
|
|
@@ -618,7 +592,6 @@ interface CleanObjectOptions {
|
|
|
618
592
|
* @returns cleaned object
|
|
619
593
|
*/
|
|
620
594
|
declare function cleanObject<T extends object>(obj: T, options?: CleanObjectOptions): T;
|
|
621
|
-
|
|
622
595
|
//#endregion
|
|
623
596
|
//#region src/object/hasOwn.d.ts
|
|
624
597
|
/**
|
|
@@ -628,7 +601,6 @@ declare function cleanObject<T extends object>(obj: T, options?: CleanObjectOpti
|
|
|
628
601
|
* @returns true if object has a property with given key, false otherwise
|
|
629
602
|
*/
|
|
630
603
|
declare function hasOwn<T>(object: T, key: PropertyKey): boolean;
|
|
631
|
-
|
|
632
604
|
//#endregion
|
|
633
605
|
//#region src/object/sortObject.d.ts
|
|
634
606
|
interface SortObjectOptions {
|
|
@@ -646,7 +618,6 @@ interface SortObjectOptions {
|
|
|
646
618
|
* Sort object properties
|
|
647
619
|
*/
|
|
648
620
|
declare function sortObject<T extends Record<string, any>>(obj: T, options?: SortObjectOptions): T;
|
|
649
|
-
|
|
650
621
|
//#endregion
|
|
651
622
|
//#region src/string/pad.d.ts
|
|
652
623
|
interface CreatePadStringOptions {
|
|
@@ -654,7 +625,6 @@ interface CreatePadStringOptions {
|
|
|
654
625
|
char: string;
|
|
655
626
|
}
|
|
656
627
|
declare function createPadString(options: CreatePadStringOptions): (value: string) => string;
|
|
657
|
-
|
|
658
628
|
//#endregion
|
|
659
629
|
//#region src/string/join.d.ts
|
|
660
630
|
type JoinableValue = string | number | null | undefined;
|
|
@@ -671,14 +641,12 @@ interface JoinOptions {
|
|
|
671
641
|
* @returns A string.
|
|
672
642
|
*/
|
|
673
643
|
declare function join(array: JoinableValue[], options?: JoinOptions): string;
|
|
674
|
-
|
|
675
644
|
//#endregion
|
|
676
645
|
//#region src/string/slash.d.ts
|
|
677
646
|
/**
|
|
678
647
|
* Replace backslash to slash
|
|
679
648
|
*/
|
|
680
649
|
declare function slash(input: string): string;
|
|
681
|
-
|
|
682
650
|
//#endregion
|
|
683
651
|
//#region src/string/random.d.ts
|
|
684
652
|
/**
|
|
@@ -689,14 +657,12 @@ declare function slash(input: string): string;
|
|
|
689
657
|
* @returns random string
|
|
690
658
|
*/
|
|
691
659
|
declare function randomString(length?: number, chars?: string): string;
|
|
692
|
-
|
|
693
660
|
//#endregion
|
|
694
661
|
//#region src/string/slugify.d.ts
|
|
695
662
|
/**
|
|
696
663
|
* Default slugify function
|
|
697
664
|
*/
|
|
698
665
|
declare function slugify(str: string): string;
|
|
699
|
-
|
|
700
666
|
//#endregion
|
|
701
667
|
//#region src/string/unindent.d.ts
|
|
702
668
|
/**
|
|
@@ -715,7 +681,6 @@ declare function slugify(str: string): string;
|
|
|
715
681
|
* ```
|
|
716
682
|
*/
|
|
717
683
|
declare function unindent(input: TemplateStringsArray | string): string;
|
|
718
|
-
|
|
719
684
|
//#endregion
|
|
720
685
|
//#region src/string/getLength.d.ts
|
|
721
686
|
/**
|
|
@@ -724,15 +689,12 @@ declare function unindent(input: TemplateStringsArray | string): string;
|
|
|
724
689
|
* @returns The number of graphemes in `value`.
|
|
725
690
|
*/
|
|
726
691
|
declare function getStringLength(value: string): number;
|
|
727
|
-
|
|
728
692
|
//#endregion
|
|
729
693
|
//#region src/string/ensurePrefix.d.ts
|
|
730
694
|
declare function ensurePrefix(input: string, prefix: string): string;
|
|
731
|
-
|
|
732
695
|
//#endregion
|
|
733
696
|
//#region src/string/ensureSuffix.d.ts
|
|
734
697
|
declare function ensureSuffix(input: string, suffix: string): string;
|
|
735
|
-
|
|
736
698
|
//#endregion
|
|
737
699
|
//#region src/constants/char.d.ts
|
|
738
700
|
/**
|
|
@@ -741,7 +703,6 @@ declare function ensureSuffix(input: string, suffix: string): string;
|
|
|
741
703
|
declare const SPECIAL_CHAR: {
|
|
742
704
|
newline: string;
|
|
743
705
|
};
|
|
744
|
-
|
|
745
706
|
//#endregion
|
|
746
707
|
//#region src/constants/regexp.d.ts
|
|
747
708
|
/**
|
|
@@ -758,6 +719,5 @@ declare const RE_LINE_COMMENT: RegExp;
|
|
|
758
719
|
* JavaScript block comment
|
|
759
720
|
*/
|
|
760
721
|
declare const RE_BLOCK_COMMENT: RegExp;
|
|
761
|
-
|
|
762
722
|
//#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 };
|
|
723
|
+
export { AnyFn, Arrayable, Awaitable, Callable, CleanObjectOptions, Color, CreatePadStringOptions, DeepRequired, InteropModuleDefault, JsonArray, JsonObject, JsonPrimitive, JsonValue, LiteralUnion, MayBe, Merge, NOOP, NonEmptyObject, NonEmptyString, Nullable, ONE_DAY_MILLSECONDS, ONE_HOUR_MILLSECONDS, ONE_MINUTE_MILLSECONDS, ONE_SECOND_MILLSECONDS, ONE_WEEK_MILLSECONDS, 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, getRoot, 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 };
|
package/dist/index.js
CHANGED
|
@@ -261,7 +261,9 @@ function unescapeHTML(str) {
|
|
|
261
261
|
|
|
262
262
|
//#endregion
|
|
263
263
|
//#region src/misc/raf.ts
|
|
264
|
-
|
|
264
|
+
function getRoot() {
|
|
265
|
+
return isBrowser() ? window : globalThis;
|
|
266
|
+
}
|
|
265
267
|
let prev = Date.now();
|
|
266
268
|
function mockRAF(fn) {
|
|
267
269
|
const curr = Date.now();
|
|
@@ -277,6 +279,7 @@ function mockRAF(fn) {
|
|
|
277
279
|
* @returns id
|
|
278
280
|
*/
|
|
279
281
|
function rAF(fn) {
|
|
282
|
+
const root = getRoot();
|
|
280
283
|
const raf = root.requestAnimationFrame || mockRAF;
|
|
281
284
|
return raf.call(root, fn);
|
|
282
285
|
}
|
|
@@ -287,6 +290,7 @@ function rAF(fn) {
|
|
|
287
290
|
* @returns void
|
|
288
291
|
*/
|
|
289
292
|
function cAF(id) {
|
|
293
|
+
const root = getRoot();
|
|
290
294
|
const caf = root.cancelAnimationFrame || root.clearTimeout;
|
|
291
295
|
return caf.call(root, id);
|
|
292
296
|
}
|
|
@@ -297,25 +301,25 @@ function cAF(id) {
|
|
|
297
301
|
* @file time utils
|
|
298
302
|
* @module Time
|
|
299
303
|
*/
|
|
300
|
-
const
|
|
301
|
-
const
|
|
302
|
-
const
|
|
303
|
-
const
|
|
304
|
-
const
|
|
304
|
+
const ONE_SECOND_MILLSECONDS = 1e3;
|
|
305
|
+
const ONE_MINUTE_MILLSECONDS = 60 * ONE_SECOND_MILLSECONDS;
|
|
306
|
+
const ONE_HOUR_MILLSECONDS = 60 * ONE_MINUTE_MILLSECONDS;
|
|
307
|
+
const ONE_DAY_MILLSECONDS = 24 * ONE_HOUR_MILLSECONDS;
|
|
308
|
+
const ONE_WEEK_MILLSECONDS = 7 * ONE_DAY_MILLSECONDS;
|
|
305
309
|
function seconds(count) {
|
|
306
|
-
return count *
|
|
310
|
+
return count * ONE_SECOND_MILLSECONDS;
|
|
307
311
|
}
|
|
308
312
|
function minutes(count) {
|
|
309
|
-
return count *
|
|
313
|
+
return count * ONE_MINUTE_MILLSECONDS;
|
|
310
314
|
}
|
|
311
315
|
function hours(count) {
|
|
312
|
-
return count *
|
|
316
|
+
return count * ONE_HOUR_MILLSECONDS;
|
|
313
317
|
}
|
|
314
318
|
function days(count) {
|
|
315
|
-
return count *
|
|
319
|
+
return count * ONE_DAY_MILLSECONDS;
|
|
316
320
|
}
|
|
317
321
|
function weeks(count) {
|
|
318
|
-
return count *
|
|
322
|
+
return count * ONE_WEEK_MILLSECONDS;
|
|
319
323
|
}
|
|
320
324
|
|
|
321
325
|
//#endregion
|
|
@@ -407,7 +411,7 @@ function debounce(delay, callback, options = {}) {
|
|
|
407
411
|
/**
|
|
408
412
|
* Cached warnings
|
|
409
413
|
*/
|
|
410
|
-
const warned = new Set();
|
|
414
|
+
const warned = /* @__PURE__ */ new Set();
|
|
411
415
|
/**
|
|
412
416
|
* Warn message only once
|
|
413
417
|
*
|
|
@@ -930,13 +934,9 @@ function hasOwn(object, key) {
|
|
|
930
934
|
//#endregion
|
|
931
935
|
//#region src/object/pick.ts
|
|
932
936
|
function pick(object, keys) {
|
|
933
|
-
return Object.assign(
|
|
934
|
-
{}
|
|
935
|
-
|
|
936
|
-
...keys.map((key) => {
|
|
937
|
-
if (object && hasOwn(object, key)) return { [key]: object[key] };
|
|
938
|
-
})
|
|
939
|
-
);
|
|
937
|
+
return Object.assign({}, ...keys.map((key) => {
|
|
938
|
+
if (object && hasOwn(object, key)) return { [key]: object[key] };
|
|
939
|
+
}));
|
|
940
940
|
}
|
|
941
941
|
|
|
942
942
|
//#endregion
|
|
@@ -1027,4 +1027,4 @@ const RE_LINE_COMMENT = /\/\/.*/;
|
|
|
1027
1027
|
const RE_BLOCK_COMMENT = /\/\*[\s\S]*?\*\//g;
|
|
1028
1028
|
|
|
1029
1029
|
//#endregion
|
|
1030
|
-
export { Color, NOOP, RE_BLOCK_COMMENT, RE_COMMENTS, RE_LINE_COMMENT, SPECIAL_CHAR, 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 };
|
|
1030
|
+
export { Color, NOOP, ONE_DAY_MILLSECONDS, ONE_HOUR_MILLSECONDS, ONE_MINUTE_MILLSECONDS, ONE_SECOND_MILLSECONDS, ONE_WEEK_MILLSECONDS, RE_BLOCK_COMMENT, RE_COMMENTS, RE_LINE_COMMENT, SPECIAL_CHAR, at, cAF, chunk, clamp, cleanObject, createPadString, days, debounce, enhance, ensurePrefix, ensureSuffix, escapeHTML, flattenArrayable, getObjectType, getRoot, 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 };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ntnyq/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.1",
|
|
5
5
|
"description": "Common used utils.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"utils"
|
|
@@ -30,17 +30,17 @@
|
|
|
30
30
|
],
|
|
31
31
|
"sideEffects": false,
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@ntnyq/eslint-config": "^
|
|
34
|
-
"@ntnyq/prettier-config": "^2.
|
|
35
|
-
"bumpp": "^10.1.
|
|
36
|
-
"eslint": "^9.
|
|
33
|
+
"@ntnyq/eslint-config": "^5.0.0-beta.5",
|
|
34
|
+
"@ntnyq/prettier-config": "^2.2.0",
|
|
35
|
+
"bumpp": "^10.1.1",
|
|
36
|
+
"eslint": "^9.28.0",
|
|
37
37
|
"husky": "^9.1.7",
|
|
38
38
|
"nano-staged": "^0.8.0",
|
|
39
|
-
"npm-run-all2": "^8.0.
|
|
39
|
+
"npm-run-all2": "^8.0.4",
|
|
40
40
|
"prettier": "^3.5.3",
|
|
41
|
-
"tsdown": "^0.
|
|
41
|
+
"tsdown": "^0.12.6",
|
|
42
42
|
"typescript": "^5.8.3",
|
|
43
|
-
"vitest": "^3.1
|
|
43
|
+
"vitest": "^3.2.1"
|
|
44
44
|
},
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=18.18.0"
|