moderndash 1.1.1 → 1.3.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
@@ -153,7 +153,7 @@ declare function group<TElem, TKey extends PropertyKey>(array: TElem[], criteria
153
153
  *
154
154
  * intersection((a, b) => a.id === b.id, arr1, arr2)
155
155
  * // => [{ id: 3, name: 'John' }]
156
- * @param arrays - The arrays to inspect.
156
+ * @param arrays The arrays to inspect.
157
157
  * @returns Returns the new array of intersecting values.
158
158
  */
159
159
  declare function intersection<TArr>(...arrays: ArrayMinLength<TArr[], 2>): TArr[];
@@ -193,7 +193,7 @@ declare function range(start: number, end: number, step?: number): Generator<num
193
193
  *
194
194
  * sample([1, 2, 3, 4], 2)
195
195
  * // => [3, 1]
196
- * @param array - The array to sample.
196
+ * @param array The array to sample.
197
197
  * @returns Returns the random element.
198
198
  */
199
199
  declare function sample<TArr>(array: TArr[]): TArr | undefined;
@@ -206,7 +206,7 @@ declare function sample<TArr>(array: TArr[], multi: number): TArr[];
206
206
  * @example
207
207
  * shuffle([1, 2, 3, 4])
208
208
  * // => [4, 1, 3, 2]
209
- * @param array - The array or object to shuffle.
209
+ * @param array The array or object to shuffle.
210
210
  * @returns Returns the new shuffled array.
211
211
  */
212
212
  declare function shuffle<TArr>(array: TArr[]): TArr[];
@@ -226,8 +226,8 @@ declare function shuffle<TArr>(array: TArr[]): TArr[];
226
226
  * { order: 'desc', by: item => item.b }
227
227
  * )
228
228
  * // => [{ a: 1, b: 2 }, { a: 1, b: 1 }, { a: 2, b: 1 }]
229
- * @param array - The array to sort.
230
- * @param orders - The sorting criteria, one or multiple objects with properties order (either 'asc' or 'desc') and by (iteratee function to sort based on a specific property).
229
+ * @param array The array to sort.
230
+ * @param orders The sorting criteria, one or multiple objects with properties order (either 'asc' or 'desc') and by (iteratee function to sort based on a specific property).
231
231
  * @param orders.order - The order to sort in, either 'asc' or 'desc'.
232
232
  * @param orders.by - The iteratee function to sort based on a specific property.
233
233
  * @returns Returns the sorted array.
@@ -250,8 +250,8 @@ declare function sort<TInput>(array: TInput[], ...orders: {
250
250
  *
251
251
  * takeRightWhile(({ active }) => active, users)
252
252
  * // => objects for ['fred', 'pebbles']
253
- * @param predicate - The function invoked per iteration.
254
- * @param array - The array to query.
253
+ * @param predicate The function invoked per iteration.
254
+ * @param array The array to query.
255
255
  * @returns Returns the slice of `array`.
256
256
  */
257
257
  declare function takeRightWhile<TArr>(predicate: (elem: TArr) => boolean, array: TArr[]): TArr[];
@@ -286,16 +286,15 @@ declare function takeWhile<TArr>(array: TArr[], predicate: (elem: TArr) => boole
286
286
  * // => [2, 1]
287
287
  *
288
288
  * const users = [
289
- * { id: 1, name: 'a' },
290
- * { id: 1, name: 'c' }
289
+ * { id: 1, name: 'a' },
290
+ * { id: 1, name: 'c' }
291
291
  * ]
292
292
  *
293
293
  * unique(users, (a, b) => a.id === b.id)
294
294
  * // => [{ id: 1, name: 'a' }]
295
295
  *
296
- *
297
- * @param array - The array to inspect.
298
- * @param iteratee - The iteratee invoked per element.
296
+ * @param array The array to inspect.
297
+ * @param iteratee The iteratee invoked per element.
299
298
  * @returns Returns the new duplicate free array.
300
299
  */
301
300
  declare function unique<TInput>(array: TInput[], compareFn?: (a: TInput, b: TInput) => boolean): TInput[];
@@ -321,7 +320,7 @@ declare function unique<TInput>(array: TInput[], compareFn?: (a: TInput, b: TInp
321
320
  * instance.testMethod("World");
322
321
  * // => Only the second invocation of `debouncedSayHello` is executed, after a delay of 1000ms.
323
322
  * ```
324
- * @param wait - Milliseconds to wait before invoking the decorated function after the last invocation.
323
+ * @param wait Milliseconds to wait before invoking the decorated function after the last invocation.
325
324
  */
326
325
  declare function decDebounce(wait: number): (target: unknown, key: string, descriptor: PropertyDescriptor) => void;
327
326
 
@@ -347,7 +346,7 @@ declare function decDebounce(wait: number): (target: unknown, key: string, descr
347
346
  * instance.testMethod(); // => 2
348
347
  * instance.testMethod(); // => 2
349
348
  * ```
350
- * @param n - The number of calls before the cached result is returned.
349
+ * @param n The number of calls before the cached result is returned.
351
350
  */
352
351
  declare function decMaxCalls(n: number): (target: unknown, key: string, descriptor: PropertyDescriptor) => void;
353
352
 
@@ -370,8 +369,8 @@ type GenericFunction<TFunc extends (...args: any) => any> = (...args: Parameters
370
369
  * @example
371
370
  * ```typescript
372
371
  * function fibonacci(n: number) {
373
- * if (n <= 1) return n;
374
- * return fibonacci(n - 1) + fibonacci(n - 2);
372
+ * if (n <= 1) return n;
373
+ * return fibonacci(n - 1) + fibonacci(n - 2);
375
374
  * }
376
375
  *
377
376
  * const memoizedFib = memoize(fibonacci, { ttl: 1000 })
@@ -388,8 +387,8 @@ type GenericFunction<TFunc extends (...args: any) => any> = (...args: Parameters
388
387
  * // This is the default way to create cache keys.
389
388
  * const defaultResolver = (...args: unknown[]) => JSON.stringify(args)
390
389
  * ```
391
- * @param func - The function to have its output memoized.
392
- * @param options - The options object with optional `resolver` and `ttl` parameters.
390
+ * @param func The function to have its output memoized.
391
+ * @param options The options object with optional `resolver` and `ttl` parameters.
393
392
  * @param options.resolver - A function that determines the cache key for storing the result based on the arguments provided.
394
393
  * @param options.ttl - The time to live for the cache in milliseconds.
395
394
  * @template TFunc The type of the function to memoize.
@@ -430,7 +429,7 @@ declare function memoize<TFunc extends GenericFunction<TFunc>, Cache extends Map
430
429
  * // After 1 second:
431
430
  * instance.testMethod(1, 2); // => 3 (cache miss)
432
431
  * ```
433
- * @param options - The options object.
432
+ * @param options The options object.
434
433
  * @param options.resolver - A function that determines the cache key for storing the result based on the arguments provided.
435
434
  * @param options.ttl - The time to live for the cache in milliseconds.
436
435
  */
@@ -479,7 +478,7 @@ declare function decMinCalls(n: number): (target: unknown, key: string, descript
479
478
  * instance.testMethod(); // => "Throttled!" is logged once per second.
480
479
  * instance.testMethod(); // nothing happens
481
480
  * ```
482
- * @param wait - The number of milliseconds to wait between invocations.
481
+ * @param wait The number of milliseconds to wait between invocations.
483
482
  */
484
483
  declare function decThrottle(wait: number): (target: unknown, key: string, descriptor: PropertyDescriptor) => void;
485
484
 
@@ -509,7 +508,7 @@ type Tail<T extends unknown[]> = T extends [infer _Head, ...infer Tail] ? Tail :
509
508
  * instance.testMethod();
510
509
  * // => Log "Hello World" and return 1
511
510
  * ```
512
- * @param func - The function to transform.
511
+ * @param func The function to transform.
513
512
  * @returns A decorator function that can be used to decorate a method.
514
513
  */
515
514
  declare function toDecorator<TFunc extends GenericFunction<TFunc>>(func: TFunc): (...args: Tail<Parameters<TFunc>>) => (target: unknown, key: string, descriptor: PropertyDescriptor) => void;
@@ -530,8 +529,8 @@ declare function toDecorator<TFunc extends GenericFunction<TFunc>>(func: TFunc):
530
529
  * debouncedSayHello("John");
531
530
  * debouncedSayHello("Jane");
532
531
  * // => Only the second invocation of `debouncedSayHello` is executed, after a delay of 200ms.
533
- * @param func - The function to debounce.
534
- * @param wait - The number of milliseconds to wait before invoking `func`.
532
+ * @param func The function to debounce.
533
+ * @param wait The number of milliseconds to wait before invoking `func`.
535
534
  * @returns A debounced version of `func` with `cancel` and `flush` methods.
536
535
  */
537
536
  declare function debounce<TFunc extends GenericFunction<TFunc>>(func: TFunc, wait: number): TFunc & {
@@ -556,8 +555,8 @@ declare function debounce<TFunc extends GenericFunction<TFunc>>(func: TFunc, wai
556
555
  * limitAddCount() // => 2
557
556
  * limitAddCount() // => 2
558
557
  * // => `limitAddCount` is invoked twice and the result is cached.
559
- * @param n - The number of calls before the cached result is returned.
560
- * @param func - The function to restrict.
558
+ * @param n The number of calls before the cached result is returned.
559
+ * @param func The function to restrict.
561
560
  * @returns Returns the new restricted function.
562
561
  */
563
562
  declare function maxCalls<TFunc extends GenericFunction<TFunc>>(func: TFunc, n: number): TFunc;
@@ -591,8 +590,8 @@ declare function minCalls<TFunc extends GenericFunction<TFunc>>(func: TFunc, n:
591
590
  * throttled();
592
591
  * throttled();
593
592
  * // => "Throttled!" is logged once per second.
594
- * @param func - The function to throttle.
595
- * @param wait - The number of milliseconds to throttle invocations to.
593
+ * @param func The function to throttle.
594
+ * @param wait The number of milliseconds to throttle invocations to.
596
595
  * @returns Returns the new throttled function.
597
596
  */
598
597
  declare function throttle<TFunc extends GenericFunction<TFunc>>(func: TFunc, wait: number): TFunc;
@@ -608,8 +607,8 @@ declare function throttle<TFunc extends GenericFunction<TFunc>>(func: TFunc, wai
608
607
  * // => [0.123, 0.456, 0.789]
609
608
  * times(() => 0, 4)
610
609
  * // => [0, 0, 0, 0]
611
- * @param n - The number of times to invoke `func`.
612
- * @param func - The function invoked per iteration.
610
+ * @param n The number of times to invoke `func`.
611
+ * @param func The function invoked per iteration.
613
612
  * @returns Returns an array of results.
614
613
  */
615
614
  declare function times<TInput>(func: (index: number) => TInput, n: number): TInput[];
@@ -621,7 +620,7 @@ declare function times<TInput>(func: (index: number) => TInput, n: number): TInp
621
620
  * @example
622
621
  * average([1, 2, 3, 4, 5]) // => 3
623
622
  *
624
- * @param numbers - The input array of numbers
623
+ * @param numbers The input array of numbers
625
624
  * @returns The average of the input array, or NaN if the input array is empty
626
625
  */
627
626
  declare function average(numbers: number[]): number;
@@ -634,7 +633,7 @@ declare function average(numbers: number[]): number;
634
633
  * median([1, 2, 3, 4, 5]) // => 3
635
634
  * median([1, 2, 3, 4, 5, 6]) // => 3.5
636
635
  *
637
- * @param numbers - The input array of numbers
636
+ * @param numbers The input array of numbers
638
637
  * @returns The median of the input array
639
638
  */
640
639
  declare function median(numbers: number[]): number;
@@ -646,8 +645,8 @@ declare function median(numbers: number[]): number;
646
645
  * @example
647
646
  * randomFloat(1, 10) // => 1.123456789
648
647
  *
649
- * @param min - The smallest float that can be generated.
650
- * @param max - The largest float that can be generated.
648
+ * @param min The smallest float that can be generated.
649
+ * @param max The largest float that can be generated.
651
650
  *
652
651
  * @returns A random float between `min` and `max`, including `min` and `max`.
653
652
  */
@@ -660,13 +659,27 @@ declare function randomFloat(min: number, max: number): number;
660
659
  * @example
661
660
  * randomInt(1, 10) // => 5
662
661
  *
663
- * @param min - The smallest integer that can be generated.
664
- * @param max - The largest integer that can be generated.
662
+ * @param min The smallest integer that can be generated.
663
+ * @param max The largest integer that can be generated.
665
664
  *
666
665
  * @returns A random integer between `min` and `max`, including `min` and `max`.
667
666
  */
668
667
  declare function randomInt(min: number, max: number): number;
669
668
 
669
+ /**
670
+ * Rounds a number to the given precision.
671
+ *
672
+ * @example
673
+ * round(1.23456, 2); // => 1.23
674
+ * round(1.235, 1); // => 1.2
675
+ * round(1234.56); // => 1234.56
676
+ *
677
+ * @param number The number to be rounded.
678
+ * @param precision The number of decimal places to round to. Defaults to 2.
679
+ * @returns The rounded number.
680
+ */
681
+ declare function round(number: number, precision?: number): number;
682
+
670
683
  /**
671
684
  * Calculates the sum of an array of numbers.
672
685
  *
@@ -674,7 +687,7 @@ declare function randomInt(min: number, max: number): number;
674
687
  * @example
675
688
  * sum([1, 2, 3, 4, 5]) // => 15
676
689
  *
677
- * @param numbers - The input array of numbers
690
+ * @param numbers The input array of numbers
678
691
  * @returns The sum of the input array
679
692
  */
680
693
  declare function sum(numbers: number[]): number;
@@ -707,8 +720,8 @@ type PlainObject = Record<PropertyKey, unknown>;
707
720
  *
708
721
  * merge({ a: 1 }, { a: "Yes" })
709
722
  * // => { a: "Yes" }
710
- * @param target - The target object
711
- * @param sources - The source objects
723
+ * @param target The target object
724
+ * @param sources The source objects
712
725
  * @returns A new merged object
713
726
  */
714
727
  declare function merge<TTarget extends PlainObject, TSources extends ArrayMinLength<PlainObject, 1>>(target: TTarget, ...sources: TSources): MergeDeepObjects<[TTarget, ...TSources]>;
@@ -734,8 +747,8 @@ type MergeDeepObjects<A extends readonly [...unknown[]]> = A extends [infer L, .
734
747
  * omit(obj, ['a', 'b']);
735
748
  * // => {c: 3}
736
749
  *
737
- * @param object - The object to filter
738
- * @param keysToOmit - The keys to exclude from the returned object
750
+ * @param object The object to filter
751
+ * @param keysToOmit The keys to exclude from the returned object
739
752
  * @returns - An object without the specified keys
740
753
  *
741
754
  */
@@ -749,8 +762,8 @@ declare function omit<TObj extends PlainObject, Key extends keyof TObj>(object:
749
762
  *
750
763
  * pick(object, ['a', 'c'])
751
764
  * // => { 'a': 1, 'c': 3 }
752
- * @param object - The source object.
753
- * @param keysToPick - The property paths to pick.
765
+ * @param object The source object.
766
+ * @param keysToPick The property paths to pick.
754
767
  * @returns Returns the new object.
755
768
  */
756
769
  declare function pick<TInput extends PlainObject, Key extends keyof TInput>(object: TInput, keysToPick: Key[]): Pick<TInput, Key>;
@@ -791,14 +804,14 @@ declare function set<TObj extends PlainObject>(obj: TObj, path: string, value: u
791
804
  * queue.add(() => fetch('https://example.com'));
792
805
  *
793
806
  * queue.add(async () => {
794
- * const response = await fetch('https://example.com');
795
- * return response.json();
807
+ * const response = await fetch('https://example.com');
808
+ * return response.json();
796
809
  * });
797
810
  *
798
811
  * // Add an array of tasks to the queue and wait for them to resolve
799
812
  * await queue.add([
800
- * () => fetch('https://apple.com'),
801
- * () => fetch('https://microsoft.com')
813
+ * () => fetch('https://apple.com'),
814
+ * () => fetch('https://microsoft.com')
802
815
  * ]);
803
816
  * // => [Response, Response]
804
817
  */
@@ -809,13 +822,13 @@ declare class Queue {
809
822
  private queue;
810
823
  /**
811
824
  * @constructor
812
- * @param maxConcurrent - The maximum number of async functions to run concurrently.
825
+ * @param maxConcurrent The maximum number of async functions to run concurrently.
813
826
  */
814
827
  constructor(maxConcurrent: number);
815
828
  /**
816
829
  * Add aync functions or an array of async functions to the queue.
817
830
  *
818
- * @param asyncFn - The aync function(s) to add to the queue.
831
+ * @param asyncFn The aync function(s) to add to the queue.
819
832
  * @returns A promise that resolves when the added function(s) finishes.
820
833
  */
821
834
  add<TProm, TAsyncFn extends () => Promise<TProm>>(asyncFn: TAsyncFn): Promise<TProm>;
@@ -864,9 +877,9 @@ declare function races<TRes>(waitFor: number, ...promises: Promise<TRes>[]): Pro
864
877
  *
865
878
  * // ---- Advanced example ----
866
879
  * const fetchSite = async () => {
867
- * const response = await fetch('https://example.com');
868
- * if(!response.ok)
869
- * throw new Error('Failed to fetch');
880
+ * const response = await fetch('https://example.com');
881
+ * if(!response.ok)
882
+ * throw new Error('Failed to fetch');
870
883
  * }
871
884
  *
872
885
  * const logger = (error: unknown, retry?: number) => console.log("Retrying", retry, error);
@@ -895,7 +908,7 @@ declare function retry<TRes>(func: () => Promise<TRes>, options?: {
895
908
  * @example
896
909
  * await sleep(1000);
897
910
  * // => Waits for 1 second.
898
- * @param ms - Amount of time to sleep in milliseconds.
911
+ * @param ms Amount of time to sleep in milliseconds.
899
912
  * @returns A promise that resolves after the given amount of time.
900
913
  */
901
914
  declare function sleep(ms: number): Promise<unknown>;
@@ -911,13 +924,33 @@ declare function sleep(ms: number): Promise<unknown>;
911
924
  * // => 'Promise timed out after 1000ms'
912
925
  * }
913
926
  * @template TRes - The type of the resolved value.
914
- * @param promise - The promise to wrap.
915
- * @param timeout - The timeout in milliseconds.
927
+ * @param promise The promise to wrap.
928
+ * @param timeout The timeout in milliseconds.
916
929
  *
917
930
  * @returns A new promise that will reject with an error after the specified timeout.
918
931
  */
919
932
  declare function timeout<TRes>(promise: Promise<TRes>, timeout: number): Promise<TRes>;
920
933
 
934
+ /**
935
+ * Attempts to execute a promise and returns an array with the result or error.
936
+ *
937
+ * This is useful for handling errors in async functions without try/catch blocks.
938
+ *
939
+ * @example
940
+ * ```typescript
941
+ * const [data, error] = await tryCatch(fetch('https://example.com/api'));
942
+ * if (error)
943
+ * console.error(`Error: ${error.message}`);
944
+ * ```
945
+ * @param promise A Promise to be executed.
946
+ * @returns A Promise that resolves to an array containing the result or error.
947
+ * If the Promise executes successfully, the array contains the result and a null error.
948
+ * If the Promise throws an error, the array contains undefined for the result and the error object.
949
+ *
950
+ * @template TRes The type of the result.
951
+ */
952
+ declare function tryCatch<TRes>(promise: Promise<TRes>): Promise<[TRes, undefined] | [undefined, Error]>;
953
+
921
954
  /**
922
955
  * Converts `string` to camelCase.
923
956
  *
@@ -928,7 +961,7 @@ declare function timeout<TRes>(promise: Promise<TRes>, timeout: number): Promise
928
961
  * // => 'fooBar'
929
962
  * camelCase('__FOO_BAR__')
930
963
  * // => 'fooBar'
931
- * @param str - The string to convert.
964
+ * @param str The string to convert.
932
965
  * @returns Returns the camel cased string.
933
966
  */
934
967
  declare function camelCase(str: string): string;
@@ -939,7 +972,7 @@ declare function camelCase(str: string): string;
939
972
  * @example
940
973
  * capitalize('FRED')
941
974
  * // => 'Fred'
942
- * @param str - The string to capitalize.
975
+ * @param str The string to capitalize.
943
976
  * @returns Returns the capitalized string.
944
977
  */
945
978
  declare function capitalize(str: string): string;
@@ -954,7 +987,7 @@ declare function capitalize(str: string): string;
954
987
  * @example
955
988
  * deburr('déjà vu')
956
989
  * // => 'deja vu'
957
- * @param str - The string to deburr.
990
+ * @param str The string to deburr.
958
991
  * @returns Returns the deburred string.
959
992
  */
960
993
  declare function deburr(str: string): string;
@@ -965,7 +998,7 @@ declare function deburr(str: string): string;
965
998
  * @example
966
999
  * escapeHtml('fred, barney, & pebbles')
967
1000
  * // => 'fred, barney, &amp; pebbles'
968
- * @param str - The string to escape.
1001
+ * @param str The string to escape.
969
1002
  * @returns Returns the escaped string.
970
1003
  */
971
1004
  declare function escapeHtml(str: string): string;
@@ -977,7 +1010,7 @@ declare function escapeHtml(str: string): string;
977
1010
  * @example
978
1011
  * escapeRegExp('[moderndash](https://moderndash.io/)')
979
1012
  * // => '\[moderndash\]\(https://moderndash\.io/\)'
980
- * @param str - The string to escape.
1013
+ * @param str The string to escape.
981
1014
  * @returns Returns the escaped string.
982
1015
  */
983
1016
  declare function escapeRegExp(str: string): string;
@@ -993,7 +1026,7 @@ declare function escapeRegExp(str: string): string;
993
1026
  * kebabCase('__FOO_BAR__')
994
1027
  * // => 'foo-bar'
995
1028
  *
996
- * @param str - The string to convert.
1029
+ * @param str The string to convert.
997
1030
  * @returns Returns the kebab cased string.
998
1031
  */
999
1032
  declare function kebabCase(str: string): string;
@@ -1009,7 +1042,7 @@ declare function kebabCase(str: string): string;
1009
1042
  * pascalCase('__FOO_BAR__')
1010
1043
  * // => 'FooBar'
1011
1044
  *
1012
- * @param str - The string to convert.
1045
+ * @param str The string to convert.
1013
1046
  * @returns Returns the pascal cased string.
1014
1047
  */
1015
1048
  declare function pascalCase(str: string): string;
@@ -1027,7 +1060,7 @@ declare function pascalCase(str: string): string;
1027
1060
  * snakeCase('foo2bar')
1028
1061
  * // => 'foo_2_bar'
1029
1062
  *
1030
- * @param str - The string to convert.
1063
+ * @param str The string to convert.
1031
1064
  * @returns Returns the snake cased string.
1032
1065
  */
1033
1066
  declare function snakeCase(str: string): string;
@@ -1062,7 +1095,7 @@ declare function splitWords(str: string): string[];
1062
1095
  * // => 'Foo Bar'
1063
1096
  * titleCase('HélloWorld')
1064
1097
  * // => 'Hello World'
1065
- * @param str - The string to convert.
1098
+ * @param str The string to convert.
1066
1099
  * @returns Returns the title cased string.
1067
1100
  */
1068
1101
  declare function titleCase(str: string): string;
@@ -1074,7 +1107,7 @@ declare function titleCase(str: string): string;
1074
1107
  * @example
1075
1108
  * unescapeHtml('fred, barney, &amp; pebbles')
1076
1109
  * // => 'fred, barney, & pebbles'
1077
- * @param str - The string to unescape.
1110
+ * @param str The string to unescape.
1078
1111
  * @returns Returns the unescaped string.
1079
1112
  */
1080
1113
  declare function unescapeHtml(str: string): string;
@@ -1100,7 +1133,7 @@ declare function unescapeHtml(str: string): string;
1100
1133
  *
1101
1134
  * isEmpty({ 'a': 1 })
1102
1135
  * // => false
1103
- * @param value - The value to check.
1136
+ * @param value The value to check.
1104
1137
  * @returns Returns `true` if given vlaue is empty, else `false`.
1105
1138
  */
1106
1139
  declare function isEmpty(value: string | object | null | undefined): boolean;
@@ -1118,8 +1151,8 @@ declare function isEmpty(value: string | object | null | undefined): boolean;
1118
1151
  *
1119
1152
  * object === other;
1120
1153
  * // => false
1121
- * @param a - The value to compare.
1122
- * @param b - The other value to compare.
1154
+ * @param a The value to compare.
1155
+ * @param b The other value to compare.
1123
1156
  * @returns Returns `true` if the values are equivalent, else `false`.
1124
1157
  */
1125
1158
  declare function isEqual(a: unknown, b: unknown): boolean;
@@ -1135,7 +1168,7 @@ declare function isEqual(a: unknown, b: unknown): boolean;
1135
1168
  * isPlainObject([]) // => false
1136
1169
  * isPlainObject(new Function()) // => false
1137
1170
  * isPlainObject(new Date()) // => false
1138
- * @param value - The value to check
1171
+ * @param value The value to check
1139
1172
  * @returns Boolean indicating if the value is a plain object
1140
1173
  */
1141
1174
  declare function isPlainObject(value: unknown): value is PlainObject;
@@ -1148,9 +1181,9 @@ declare function isPlainObject(value: unknown): value is PlainObject;
1148
1181
  * // => true
1149
1182
  * isUrl('google.com')
1150
1183
  * // => false
1151
- * @param str - The string to check.
1184
+ * @param str The string to check.
1152
1185
  * @returns Returns `true` if given string is a valid URL, else `false`.
1153
1186
  */
1154
1187
  declare function isUrl(str: string): boolean;
1155
1188
 
1156
- export { ArrayMinLength, GenericFunction, PlainObject, Queue, average, camelCase, capitalize, chunk, count, debounce, deburr, decDebounce, decMaxCalls, decMemoize, decMinCalls, decThrottle, difference, dropRightWhile, dropWhile, escapeHtml, escapeRegExp, group, intersection, isEmpty, isEqual, isPlainObject, isUrl, kebabCase, maxCalls, median, memoize, merge, minCalls, omit, pascalCase, pick, races, randomFloat, randomInt, range, retry, sample, set, shuffle, sleep, snakeCase, sort, splitWords, sum, takeRightWhile, takeWhile, throttle, timeout, times, titleCase, toDecorator, unescapeHtml, unique };
1189
+ export { ArrayMinLength, GenericFunction, PlainObject, Queue, average, camelCase, capitalize, chunk, count, debounce, deburr, decDebounce, decMaxCalls, decMemoize, decMinCalls, decThrottle, difference, dropRightWhile, dropWhile, escapeHtml, escapeRegExp, group, intersection, isEmpty, isEqual, isPlainObject, isUrl, kebabCase, maxCalls, median, memoize, merge, minCalls, omit, pascalCase, pick, races, randomFloat, randomInt, range, retry, round, sample, set, shuffle, sleep, snakeCase, sort, splitWords, sum, takeRightWhile, takeWhile, throttle, timeout, times, titleCase, toDecorator, tryCatch, unescapeHtml, unique };
package/dist/index.js CHANGED
@@ -394,6 +394,12 @@ function randomInt(min, max) {
394
394
  return min + randomBuffer[0] % range2;
395
395
  }
396
396
 
397
+ // src/number/round.ts
398
+ function round(number, precision = 2) {
399
+ const factor = Math.pow(10, precision);
400
+ return Math.round((number + Number.EPSILON) * factor) / factor;
401
+ }
402
+
397
403
  // src/object/merge.ts
398
404
  function merge(target, ...sources) {
399
405
  const targetCopy = { ...target };
@@ -448,7 +454,7 @@ var Queue = class {
448
454
  queue = [];
449
455
  /**
450
456
  * @constructor
451
- * @param maxConcurrent - The maximum number of async functions to run concurrently.
457
+ * @param maxConcurrent The maximum number of async functions to run concurrently.
452
458
  */
453
459
  constructor(maxConcurrent) {
454
460
  this.maxConcurrent = maxConcurrent;
@@ -577,6 +583,18 @@ function timeout(promise, timeout2) {
577
583
  });
578
584
  }
579
585
 
586
+ // src/promise/tryCatch.ts
587
+ async function tryCatch(promise) {
588
+ try {
589
+ const data = await promise;
590
+ return [data, void 0];
591
+ } catch (error) {
592
+ if (error instanceof Error)
593
+ return [void 0, error];
594
+ throw error;
595
+ }
596
+ }
597
+
580
598
  // src/string/splitWords.ts
581
599
  function splitWords(str) {
582
600
  const regex = new RegExp(
@@ -750,6 +768,7 @@ export {
750
768
  randomInt,
751
769
  range,
752
770
  retry,
771
+ round,
753
772
  sample,
754
773
  set,
755
774
  shuffle,
@@ -765,6 +784,7 @@ export {
765
784
  times,
766
785
  titleCase,
767
786
  toDecorator,
787
+ tryCatch,
768
788
  unescapeHtml,
769
789
  unique
770
790
  };