moderndash 3.3.1 → 3.4.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,3 +1,5 @@
1
+ import { Call, Tuples, Objects } from 'hotscript';
2
+
1
3
  /**
2
4
  * Creates an array of elements split into groups the length of size. If array can't be split evenly, the final chunk will be the remaining elements.
3
5
  *
@@ -50,7 +52,7 @@ declare function count<TElem, TKey extends PropertyKey>(array: readonly TElem[],
50
52
  * @template TElem The type of the array elements.
51
53
  * @template TMinLength The minimum length of the array.
52
54
  */
53
- type ArrayMinLength<TElem, TMinLenght extends number> = BuildArrayMinLength<TElem, TMinLenght, []>;
55
+ type ArrayMinLength<TElem, TMinLength extends number> = BuildArrayMinLength<TElem, TMinLength, []>;
54
56
  type BuildArrayMinLength<TElem, TMinLength extends number, Current extends TElem[]> = Current["length"] extends TMinLength ? [...Current, ...TElem[]] : BuildArrayMinLength<TElem, TMinLength, [...Current, TElem]>;
55
57
 
56
58
  type CompareFunction<TArrays extends ArrayMinLength<unknown[], 2>> = (a: TArrays[0][number], b: ArrayTail<TArrays>[number][number]) => boolean;
@@ -86,7 +88,7 @@ declare function difference<TArrays extends ArrayMinLength<unknown[], 2>>(...arr
86
88
 
87
89
  /**
88
90
  * Creates a slice of `array` excluding elements dropped from the end.
89
- * Elements are dropped until `predicate` returns falsey.
91
+ * Elements are dropped until `predicate` returns falsy.
90
92
  *
91
93
  * @example
92
94
  * const users = [
@@ -106,7 +108,7 @@ declare function dropRightWhile<TElem>(array: readonly TElem[], predicate: (valu
106
108
 
107
109
  /**
108
110
  * Creates a slice of `array` excluding elements dropped from the beginning.
109
- * Elements are dropped until `predicate` returns falsey.
111
+ * Elements are dropped until `predicate` returns falsy.
110
112
  *
111
113
  * @example
112
114
  * const users = [
@@ -233,7 +235,7 @@ declare function sort<TElem>(array: readonly TElem[], ...orders: {
233
235
 
234
236
  /**
235
237
  * Creates a slice of `array` with elements taken from the end.
236
- * Elements are taken until `predicate` returns falsey.
238
+ * Elements are taken until `predicate` returns falsy.
237
239
  *
238
240
  * @example
239
241
  * const users = [
@@ -253,7 +255,7 @@ declare function takeRightWhile<TElem>(array: readonly TElem[], predicate: (elem
253
255
 
254
256
  /**
255
257
  * Creates a slice of `array` with elements taken from the beginning.
256
- * Elements are taken until `predicate` returns falsey.
258
+ * Elements are taken until `predicate` returns falsy.
257
259
  *
258
260
  * @example
259
261
  * const users = [
@@ -431,7 +433,7 @@ declare function randomInt(min: number, max: number): number;
431
433
  declare function randomString(length: number, charSet?: string): string;
432
434
 
433
435
  /**
434
- * Debouces the decorated function. Only calling it after a specified amount of time has passed without any new calls.
436
+ * Debounces the decorated function. Only calling it after a specified amount of time has passed without any new calls.
435
437
  *
436
438
  * Look at {@link debounce} for the non-decorator version.
437
439
  *
@@ -453,7 +455,7 @@ declare function randomString(length: number, charSet?: string): string;
453
455
  * ```
454
456
  * @param wait Milliseconds to wait before invoking the decorated function after the last invocation.
455
457
  */
456
- declare function decDebounce(wait: number): (target: unknown, key: string, descriptor: PropertyDescriptor) => void;
458
+ declare function decDebounce(wait: number): (_target: unknown, _key: string, descriptor: PropertyDescriptor) => void;
457
459
 
458
460
  /**
459
461
  * Only invokes the decorated function as long as it's called `<= n` times.
@@ -479,7 +481,7 @@ declare function decDebounce(wait: number): (target: unknown, key: string, descr
479
481
  * ```
480
482
  * @param n The number of calls before the cached result is returned.
481
483
  */
482
- declare function decMaxCalls(n: number): (target: unknown, key: string, descriptor: PropertyDescriptor) => void;
484
+ declare function decMaxCalls(n: number): (_target: unknown, _key: string, descriptor: PropertyDescriptor) => void;
483
485
 
484
486
  type GenericFunction<TFunc extends (...args: any) => any> = (...args: Parameters<TFunc>) => ReturnType<TFunc>;
485
487
 
@@ -566,7 +568,7 @@ declare function memoize<TFunc extends GenericFunction<TFunc>, Cache extends Map
566
568
  * @param options.resolver - A function that determines the cache key for storing the result based on the arguments provided.
567
569
  * @param options.ttl - The time to live for the cache in milliseconds.
568
570
  */
569
- declare function decMemoize(options?: Parameters<typeof memoize>[1]): (target: unknown, key: string, descriptor: PropertyDescriptor) => void;
571
+ declare function decMemoize(options?: Parameters<typeof memoize>[1]): (_target: unknown, _key: string, descriptor: PropertyDescriptor) => void;
570
572
 
571
573
  /**
572
574
  * Only invokes the decorated function after it's called more than `n` times.
@@ -589,7 +591,7 @@ declare function decMemoize(options?: Parameters<typeof memoize>[1]): (target: u
589
591
  * ```
590
592
  * @param n The number of calls before the decorated function is invoked.
591
593
  */
592
- declare function decMinCalls(n: number): (target: unknown, key: string, descriptor: PropertyDescriptor) => void;
594
+ declare function decMinCalls(n: number): (_target: unknown, _key: string, descriptor: PropertyDescriptor) => void;
593
595
 
594
596
  /**
595
597
  * The decorated function is invoked at most once per every `wait` milliseconds.
@@ -613,7 +615,7 @@ declare function decMinCalls(n: number): (target: unknown, key: string, descript
613
615
  * ```
614
616
  * @param wait The number of milliseconds to wait between invocations.
615
617
  */
616
- declare function decThrottle(wait: number): (target: unknown, key: string, descriptor: PropertyDescriptor) => void;
618
+ declare function decThrottle(wait: number): (_target: unknown, _key: string, descriptor: PropertyDescriptor) => void;
617
619
 
618
620
  type Tail<T extends unknown[]> = T extends [infer _Head, ...infer Tail] ? Tail : never;
619
621
  /**
@@ -644,7 +646,7 @@ type Tail<T extends unknown[]> = T extends [infer _Head, ...infer Tail] ? Tail :
644
646
  * @param func The function to transform.
645
647
  * @returns A decorator function that can be used to decorate a method.
646
648
  */
647
- declare function toDecorator<TFunc extends GenericFunction<TFunc>>(func: TFunc): (...args: Tail<Parameters<TFunc>>) => (target: unknown, key: string, descriptor: PropertyDescriptor) => void;
649
+ declare function toDecorator<TFunc extends GenericFunction<TFunc>>(func: TFunc): (...args: Tail<Parameters<TFunc>>) => (_target: unknown, _key: string, descriptor: PropertyDescriptor) => void;
648
650
 
649
651
  /**
650
652
  * Creates a debounced version of a function. Only calling it after a specified amount of time has passed without any new calls.
@@ -795,7 +797,8 @@ declare function round(number: number, precision?: number): number;
795
797
  * @param numbers The input array of numbers
796
798
  * @returns The sum of the input array
797
799
  */
798
- declare function sum(numbers: readonly number[]): number;
800
+ declare function sum(numbers: number[]): number;
801
+ declare function sum<TNum extends readonly number[]>(numbers: TNum): Call<Tuples.Sum, TNum>;
799
802
 
800
803
  /**
801
804
  * The type of a plain object.
@@ -811,6 +814,8 @@ declare function sum(numbers: readonly number[]): number;
811
814
  */
812
815
  type PlainObject = Record<PropertyKey, unknown>;
813
816
 
817
+ type StringIfNever<Type> = [Type] extends [never] ? string : Type;
818
+ type Paths$1<TObj> = StringIfNever<Call<Objects.AllPaths, TObj>>;
814
819
  /**
815
820
  * Flattens an object into a single level object.
816
821
  *
@@ -823,7 +828,7 @@ type PlainObject = Record<PropertyKey, unknown>;
823
828
  * @template TObj The type of the object to flatten.
824
829
  * @returns A new object with flattened keys.
825
830
  */
826
- declare function flatKeys<TObj extends PlainObject>(obj: TObj): Record<string, unknown>;
831
+ declare function flatKeys<TObj extends PlainObject>(obj: TObj): Record<Paths$1<TObj>, unknown>;
827
832
 
828
833
  /**
829
834
  * This function combines two or more objects into a single new object. Arrays and other types are overwritten.
@@ -890,6 +895,8 @@ declare function omit<TObj extends PlainObject, Key extends keyof TObj>(object:
890
895
  */
891
896
  declare function pick<TObj extends PlainObject, Key extends keyof TObj>(object: TObj, keysToPick: Key[]): Pick<TObj, Key>;
892
897
 
898
+ type Paths<TObj> = Call<Objects.AllPaths, TObj> | string & {};
899
+ type UpdateObj<TObj extends PlainObject, TPath extends string, TVal> = Call<Objects.Update<TPath, TVal>, TObj>;
893
900
  /**
894
901
  * Sets the value at path of object. If a portion of path doesn’t exist, it’s created.
895
902
  *
@@ -914,9 +921,11 @@ declare function pick<TObj extends PlainObject, Key extends keyof TObj>(object:
914
921
  * @param path The path of the property to set.
915
922
  * @param value The value to set.
916
923
  * @template TObj The type of the object.
924
+ * @template TPath The type of the object path.
925
+ * @template TVal The type of the value to set.
917
926
  * @returns The modified object.
918
927
  */
919
- declare function set(obj: PlainObject, path: string, value: unknown): PlainObject;
928
+ declare function set<TObj extends PlainObject, TPath extends Paths<TObj>, TVal>(obj: TObj, path: TPath, value: TVal): UpdateObj<TObj, TPath, TVal>;
920
929
 
921
930
  /**
922
931
  * A class for managing a queue of async functions that runs a set number concurrently.
@@ -961,9 +970,9 @@ declare class Queue {
961
970
  */
962
971
  constructor(maxConcurrent: number);
963
972
  /**
964
- * Add aync functions or an array of async functions to the queue.
973
+ * Add async functions or an array of async functions to the queue.
965
974
  *
966
- * @param asyncFn The aync function(s) to add to the queue.
975
+ * @param asyncFn The async function(s) to add to the queue.
967
976
  * @returns A promise that resolves when the added function(s) finishes.
968
977
  */
969
978
  add<TProm, TAsyncFn extends () => Promise<TProm>>(asyncFn: TAsyncFn): Promise<TProm>;
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(target, key, descriptor) {
266
+ return function(_target, _key, descriptor) {
267
267
  const creatorArgs = [descriptor.value, ...args];
268
268
  descriptor.value = func(...creatorArgs);
269
269
  };
@@ -468,7 +468,7 @@ function omit(object, keysToOmit) {
468
468
  }
469
469
 
470
470
  // src/object/set.ts
471
- var validPathRegex = /^(?:[^.[\]]+(?:\[\d+])*(?:\.|\[\d+]))+(?:[^.[\]]+(?:\[\d+])*)+$/;
471
+ var validPathRegex = /^[^.[\]]+(?:\.[^.[\]]+)*(?:\[\d+])*(?:\.[^.[\]]+(?:\[\d+])*)*$/;
472
472
  var pathSplitRegex = /\.|(?=\[)/g;
473
473
  var matchBracketsRegex = /[[\]]/g;
474
474
  function set(obj, path, value) {
@@ -646,7 +646,7 @@ async function tryCatch(promise) {
646
646
  }
647
647
 
648
648
  // src/string/splitWords.ts
649
- var wordsRegex = /(\d*[a-z]+)|([A-Z][a-z]+)|(\d*[A-Z]+(?=[^a-z]|$))|(\d+)/g;
649
+ var wordsRegex = /(?:\d*[a-z]+)|(?:[A-Z][a-z]+)|(?:\d*[A-Z]+(?=[^a-z]|$))|\d+/g;
650
650
  function splitWords(str) {
651
651
  return str.match(wordsRegex) ?? [];
652
652
  }
@@ -687,9 +687,9 @@ function escapeHtml(str) {
687
687
  }
688
688
 
689
689
  // src/string/escapeRegExp.ts
690
- var escapleCharsRegex = /[$()*+.?[\\\]^{|}]/g;
690
+ var escapeCharsRegex = /[$()*+.?[\\\]^{|}]/g;
691
691
  function escapeRegExp(str) {
692
- return str.replace(escapleCharsRegex, "\\$&");
692
+ return str.replace(escapeCharsRegex, "\\$&");
693
693
  }
694
694
 
695
695
  // src/string/kebabCase.ts