moderndash 3.3.0 → 3.3.2
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/README.md +4 -2
- package/dist/index.cjs +6 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +15 -15
- package/dist/index.js +6 -22
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ declare function count<TElem, TKey extends PropertyKey>(array: readonly TElem[],
|
|
|
50
50
|
* @template TElem The type of the array elements.
|
|
51
51
|
* @template TMinLength The minimum length of the array.
|
|
52
52
|
*/
|
|
53
|
-
type ArrayMinLength<TElem,
|
|
53
|
+
type ArrayMinLength<TElem, TMinLength extends number> = BuildArrayMinLength<TElem, TMinLength, []>;
|
|
54
54
|
type BuildArrayMinLength<TElem, TMinLength extends number, Current extends TElem[]> = Current["length"] extends TMinLength ? [...Current, ...TElem[]] : BuildArrayMinLength<TElem, TMinLength, [...Current, TElem]>;
|
|
55
55
|
|
|
56
56
|
type CompareFunction<TArrays extends ArrayMinLength<unknown[], 2>> = (a: TArrays[0][number], b: ArrayTail<TArrays>[number][number]) => boolean;
|
|
@@ -86,7 +86,7 @@ declare function difference<TArrays extends ArrayMinLength<unknown[], 2>>(...arr
|
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
88
|
* Creates a slice of `array` excluding elements dropped from the end.
|
|
89
|
-
* Elements are dropped until `predicate` returns
|
|
89
|
+
* Elements are dropped until `predicate` returns falsy.
|
|
90
90
|
*
|
|
91
91
|
* @example
|
|
92
92
|
* const users = [
|
|
@@ -106,7 +106,7 @@ declare function dropRightWhile<TElem>(array: readonly TElem[], predicate: (valu
|
|
|
106
106
|
|
|
107
107
|
/**
|
|
108
108
|
* Creates a slice of `array` excluding elements dropped from the beginning.
|
|
109
|
-
* Elements are dropped until `predicate` returns
|
|
109
|
+
* Elements are dropped until `predicate` returns falsy.
|
|
110
110
|
*
|
|
111
111
|
* @example
|
|
112
112
|
* const users = [
|
|
@@ -233,7 +233,7 @@ declare function sort<TElem>(array: readonly TElem[], ...orders: {
|
|
|
233
233
|
|
|
234
234
|
/**
|
|
235
235
|
* Creates a slice of `array` with elements taken from the end.
|
|
236
|
-
* Elements are taken until `predicate` returns
|
|
236
|
+
* Elements are taken until `predicate` returns falsy.
|
|
237
237
|
*
|
|
238
238
|
* @example
|
|
239
239
|
* const users = [
|
|
@@ -253,7 +253,7 @@ declare function takeRightWhile<TElem>(array: readonly TElem[], predicate: (elem
|
|
|
253
253
|
|
|
254
254
|
/**
|
|
255
255
|
* Creates a slice of `array` with elements taken from the beginning.
|
|
256
|
-
* Elements are taken until `predicate` returns
|
|
256
|
+
* Elements are taken until `predicate` returns falsy.
|
|
257
257
|
*
|
|
258
258
|
* @example
|
|
259
259
|
* const users = [
|
|
@@ -431,7 +431,7 @@ declare function randomInt(min: number, max: number): number;
|
|
|
431
431
|
declare function randomString(length: number, charSet?: string): string;
|
|
432
432
|
|
|
433
433
|
/**
|
|
434
|
-
*
|
|
434
|
+
* Debounces the decorated function. Only calling it after a specified amount of time has passed without any new calls.
|
|
435
435
|
*
|
|
436
436
|
* Look at {@link debounce} for the non-decorator version.
|
|
437
437
|
*
|
|
@@ -453,7 +453,7 @@ declare function randomString(length: number, charSet?: string): string;
|
|
|
453
453
|
* ```
|
|
454
454
|
* @param wait Milliseconds to wait before invoking the decorated function after the last invocation.
|
|
455
455
|
*/
|
|
456
|
-
declare function decDebounce(wait: number): (
|
|
456
|
+
declare function decDebounce(wait: number): (_target: unknown, _key: string, descriptor: PropertyDescriptor) => void;
|
|
457
457
|
|
|
458
458
|
/**
|
|
459
459
|
* Only invokes the decorated function as long as it's called `<= n` times.
|
|
@@ -479,7 +479,7 @@ declare function decDebounce(wait: number): (target: unknown, key: string, descr
|
|
|
479
479
|
* ```
|
|
480
480
|
* @param n The number of calls before the cached result is returned.
|
|
481
481
|
*/
|
|
482
|
-
declare function decMaxCalls(n: number): (
|
|
482
|
+
declare function decMaxCalls(n: number): (_target: unknown, _key: string, descriptor: PropertyDescriptor) => void;
|
|
483
483
|
|
|
484
484
|
type GenericFunction<TFunc extends (...args: any) => any> = (...args: Parameters<TFunc>) => ReturnType<TFunc>;
|
|
485
485
|
|
|
@@ -566,7 +566,7 @@ declare function memoize<TFunc extends GenericFunction<TFunc>, Cache extends Map
|
|
|
566
566
|
* @param options.resolver - A function that determines the cache key for storing the result based on the arguments provided.
|
|
567
567
|
* @param options.ttl - The time to live for the cache in milliseconds.
|
|
568
568
|
*/
|
|
569
|
-
declare function decMemoize(options?: Parameters<typeof memoize>[1]): (
|
|
569
|
+
declare function decMemoize(options?: Parameters<typeof memoize>[1]): (_target: unknown, _key: string, descriptor: PropertyDescriptor) => void;
|
|
570
570
|
|
|
571
571
|
/**
|
|
572
572
|
* Only invokes the decorated function after it's called more than `n` times.
|
|
@@ -589,7 +589,7 @@ declare function decMemoize(options?: Parameters<typeof memoize>[1]): (target: u
|
|
|
589
589
|
* ```
|
|
590
590
|
* @param n The number of calls before the decorated function is invoked.
|
|
591
591
|
*/
|
|
592
|
-
declare function decMinCalls(n: number): (
|
|
592
|
+
declare function decMinCalls(n: number): (_target: unknown, _key: string, descriptor: PropertyDescriptor) => void;
|
|
593
593
|
|
|
594
594
|
/**
|
|
595
595
|
* The decorated function is invoked at most once per every `wait` milliseconds.
|
|
@@ -613,7 +613,7 @@ declare function decMinCalls(n: number): (target: unknown, key: string, descript
|
|
|
613
613
|
* ```
|
|
614
614
|
* @param wait The number of milliseconds to wait between invocations.
|
|
615
615
|
*/
|
|
616
|
-
declare function decThrottle(wait: number): (
|
|
616
|
+
declare function decThrottle(wait: number): (_target: unknown, _key: string, descriptor: PropertyDescriptor) => void;
|
|
617
617
|
|
|
618
618
|
type Tail<T extends unknown[]> = T extends [infer _Head, ...infer Tail] ? Tail : never;
|
|
619
619
|
/**
|
|
@@ -644,7 +644,7 @@ type Tail<T extends unknown[]> = T extends [infer _Head, ...infer Tail] ? Tail :
|
|
|
644
644
|
* @param func The function to transform.
|
|
645
645
|
* @returns A decorator function that can be used to decorate a method.
|
|
646
646
|
*/
|
|
647
|
-
declare function toDecorator<TFunc extends GenericFunction<TFunc>>(func: TFunc): (...args: Tail<Parameters<TFunc>>) => (
|
|
647
|
+
declare function toDecorator<TFunc extends GenericFunction<TFunc>>(func: TFunc): (...args: Tail<Parameters<TFunc>>) => (_target: unknown, _key: string, descriptor: PropertyDescriptor) => void;
|
|
648
648
|
|
|
649
649
|
/**
|
|
650
650
|
* Creates a debounced version of a function. Only calling it after a specified amount of time has passed without any new calls.
|
|
@@ -961,9 +961,9 @@ declare class Queue {
|
|
|
961
961
|
*/
|
|
962
962
|
constructor(maxConcurrent: number);
|
|
963
963
|
/**
|
|
964
|
-
* Add
|
|
964
|
+
* Add async functions or an array of async functions to the queue.
|
|
965
965
|
*
|
|
966
|
-
* @param asyncFn The
|
|
966
|
+
* @param asyncFn The async function(s) to add to the queue.
|
|
967
967
|
* @returns A promise that resolves when the added function(s) finishes.
|
|
968
968
|
*/
|
|
969
969
|
add<TProm, TAsyncFn extends () => Promise<TProm>>(asyncFn: TAsyncFn): Promise<TProm>;
|
|
@@ -1217,7 +1217,7 @@ declare function snakeCase(str: string): string;
|
|
|
1217
1217
|
* @param forceFallback Force the use of the positive lookahead fallback. Only used for testing.
|
|
1218
1218
|
* @returns An array of words.
|
|
1219
1219
|
*/
|
|
1220
|
-
declare function splitWords(str: string
|
|
1220
|
+
declare function splitWords(str: string): string[];
|
|
1221
1221
|
|
|
1222
1222
|
/**
|
|
1223
1223
|
* Converts a string to Title Case.
|
package/dist/index.js
CHANGED
|
@@ -263,7 +263,7 @@ function randomString(length, charSet = DEFAULT_CHARSET) {
|
|
|
263
263
|
// src/decorator/toDecorator.ts
|
|
264
264
|
function toDecorator(func) {
|
|
265
265
|
return function(...args) {
|
|
266
|
-
return function(
|
|
266
|
+
return function(_target, _key, descriptor) {
|
|
267
267
|
const creatorArgs = [descriptor.value, ...args];
|
|
268
268
|
descriptor.value = func(...creatorArgs);
|
|
269
269
|
};
|
|
@@ -646,25 +646,9 @@ async function tryCatch(promise) {
|
|
|
646
646
|
}
|
|
647
647
|
|
|
648
648
|
// src/string/splitWords.ts
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
var wordBoundaryFallback = /[^\dA-Za-z]|(?=[A-Z][a-z])/;
|
|
653
|
-
var lookbehindReplacement = /([a-z])([A-Z])/g;
|
|
654
|
-
var lookbehindWordBoundary = tryLookbehindRegex();
|
|
655
|
-
function tryLookbehindRegex() {
|
|
656
|
-
try {
|
|
657
|
-
return new RegExp(
|
|
658
|
-
"[^\\dA-Za-z]|(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])"
|
|
659
|
-
// lookahead for an uppercase letter followed by a lowercase letter
|
|
660
|
-
);
|
|
661
|
-
} catch {
|
|
662
|
-
return void 0;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
function splitWordsFallback(str) {
|
|
666
|
-
const modifiedStr = str.replace(lookbehindReplacement, (match, p1, p2) => p1 + "\0" + p2);
|
|
667
|
-
return modifiedStr.split(wordBoundaryFallback).filter(Boolean).map((word) => word.replace(/\u0000/g, ""));
|
|
649
|
+
var wordsRegex = /(?:\d*[a-z]+)|(?:[A-Z][a-z]+)|(?:\d*[A-Z]+(?=[^a-z]|$))|\d+/g;
|
|
650
|
+
function splitWords(str) {
|
|
651
|
+
return str.match(wordsRegex) ?? [];
|
|
668
652
|
}
|
|
669
653
|
|
|
670
654
|
// src/string/deburr.ts
|
|
@@ -703,9 +687,9 @@ function escapeHtml(str) {
|
|
|
703
687
|
}
|
|
704
688
|
|
|
705
689
|
// src/string/escapeRegExp.ts
|
|
706
|
-
var
|
|
690
|
+
var escapeCharsRegex = /[$()*+.?[\\\]^{|}]/g;
|
|
707
691
|
function escapeRegExp(str) {
|
|
708
|
-
return str.replace(
|
|
692
|
+
return str.replace(escapeCharsRegex, "\\$&");
|
|
709
693
|
}
|
|
710
694
|
|
|
711
695
|
// src/string/kebabCase.ts
|