@budsbox/lib-es 2.3.0 → 3.0.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/array.d.ts CHANGED
@@ -1,53 +1,75 @@
1
- import type { TupleN } from '@budsbox/lib-types';
2
- import type { FValue } from './types.js';
3
1
  /**
4
- * Ensures that the provided value is returned as an array. If the value is already an array,
5
- * it is returned as-is. If the value is not an array, it is wrapped in a new array.
2
+ * This module provides array utility functions for common operations like deduplication, union, intersection, difference, etc.
6
3
  *
7
- * @param value - The value to be checked and converted into an array if necessary.
8
- * @returns An array containing the original value or the original array if it was already an array.
4
+ * @module
5
+ * @importTarget ./array
6
+ */
7
+ import type { FValue, TupleN } from '@budsbox/lib-types';
8
+ /**
9
+ * @module
10
+ *
11
+ * Array utility functions for common operations like deduplication, union, intersection, and difference.
12
+ */
13
+ /**
14
+ * {@label MUTABLE} Returns the value as an array. If already an array, returns it as-is; otherwise wraps it.
15
+ *
16
+ * @param value - The value to convert.
17
+ * @returns An array containing the value.
18
+ * @typeParam T - The element type.
9
19
  */
10
20
  export declare function ensureArray<T>(value: T | T[]): T[];
21
+ /**
22
+ * {@label READONLY} Returns the value as an array. If already an array, returns it as-is; otherwise wraps it.
23
+ *
24
+ * @param value - The value to convert.
25
+ * @returns An array containing the value.
26
+ * @typeParam T - The element type.
27
+ */
11
28
  export declare function ensureArray<T>(value: readonly T[] | T): readonly T[];
12
29
  /**
13
- * Creates an array of a fixed length with all elements initialized to the specified value.
30
+ * Creates a fixed-length array filled with a value or computed by a function.
14
31
  *
15
- * @param n - The length of the array to create.
16
- * @param value - The value to fill the array with. Defaults to `null`.
17
- * @returns A tuple of the specified length with all elements set to the given value.
32
+ * @param n - The desired array length.
33
+ * @param value - The fill value or a function that receives the index and returns the element value. Defaults to `null`.
34
+ * @returns A tuple of length N with all elements set to the value or computed result.
35
+ * @throws {@link !TypeError} if `n` is not a non-negative integer.
36
+ * @typeParam N - The array length.
37
+ * @typeParam T - The element type.
18
38
  */
19
39
  export declare function nArray<N extends number, T = null>(n: N, value?: FValue<number, T>): TupleN<N, T>;
20
40
  /**
21
- * Removes duplicate elements from the provided array while preserving the order of the first occurrence of each element.
41
+ * Removes duplicate elements from an array, preserving the order of the first occurrence.
22
42
  *
23
- * @param items - The array of items from which duplicates should be removed.
24
- * The array is expected to be read-only and can contain elements of any type.
25
- * @returns A new array containing only the unique elements from the input array, in the order of their first occurrence.
43
+ * @param items - The array to deduplicate.
44
+ * @returns A new array with unique elements in their original order.
45
+ * @throws {@link !TypeError} if `items` is not an array.
46
+ * @typeParam T - The element type.
26
47
  */
27
48
  export declare const dedupe: <T>(items: readonly T[]) => T[];
28
49
  /**
29
- * Creates an array of unique values from the combined elements of the input arrays.
50
+ * Creates an array of unique values from multiple input arrays.
30
51
  *
31
- * @param arrays - The arrays to be merged and deduplicated.
32
- * @returns An array containing unique elements from all input arrays.
52
+ * @param arrays - Arrays or individual elements to merge.
53
+ * @returns A new array containing unique elements from all inputs.
54
+ * @typeParam T - The element type.
33
55
  */
34
56
  export declare function union<T>(...arrays: ReadonlyArray<readonly T[] | T>): T[];
35
57
  /**
36
- * Computes the intersection of multiple arrays, returning an array that contains
37
- * all elements that are present in every input array.
58
+ * Returns elements present in all input arrays.
38
59
  *
39
- * @param arrays - A variadic parameter allowing multiple arrays or single elements.
40
- * Each array or element will be checked for intersection.
41
- * @returns An array containing elements that are present in all input arrays.
60
+ * @param arrays - Arrays or individual elements to intersect.
61
+ * @returns A new array containing elements common to all inputs.
62
+ * @typeParam T - The element type.
42
63
  */
43
64
  export declare function intersection<T>(...arrays: ReadonlyArray<readonly T[] | T>): T[];
44
65
  /**
45
- * Computes the difference between a source array and one or more arrays of exclusions.
46
- * Returns a new array containing elements from the source array that are not present in any of the exclusion arrays.
66
+ * Returns elements from the source array that are not in any exclusion arrays.
47
67
  *
48
- * @param source - The source array to compare against.
49
- * @param excludes - Arrays containing elements to be excluded from the source array.
50
- * @returns A new array containing elements from the source array that are not in the exclusion arrays.
68
+ * @param source - The source array.
69
+ * @param excludes - Arrays of elements to exclude.
70
+ * @returns A new array with excluded elements removed.
71
+ * @throws {@link !TypeError} if `source` is not an array or `excludes` contains non-array elements.
72
+ * @typeParam T - The element type.
51
73
  */
52
74
  export declare function diff<T>(source: readonly T[], ...excludes: ReadonlyArray<readonly T[]>): T[];
53
75
  //# sourceMappingURL=array.d.ts.map
package/dist/array.js CHANGED
@@ -1,9 +1,15 @@
1
- import { isFunction } from '#guards';
1
+ /**
2
+ * This module provides array utility functions for common operations like deduplication, union, intersection, difference, etc.
3
+ *
4
+ * @module
5
+ * @importTarget ./array
6
+ */
7
+ import { assertArray, assertEvery, isArray, isFunction, isInteger, isNonNegative, isNumber, } from '#guards';
2
8
  export function ensureArray(value) {
3
9
  return Array.isArray(value) ? value : [value];
4
10
  }
5
11
  export function nArray(n, value = null) {
6
- // eslint-disable-next-line jsdoc/require-jsdoc
12
+ assertEvery(n, 'n', isNumber, isNonNegative, isInteger);
7
13
  if (isFunction(value)) {
8
14
  const newArray = new Array(n);
9
15
  for (let i = 0; i < newArray.length; i++) {
@@ -14,29 +20,33 @@ export function nArray(n, value = null) {
14
20
  return new Array(n).fill(value);
15
21
  }
16
22
  /**
17
- * Removes duplicate elements from the provided array while preserving the order of the first occurrence of each element.
23
+ * Removes duplicate elements from an array, preserving the order of the first occurrence.
18
24
  *
19
- * @param items - The array of items from which duplicates should be removed.
20
- * The array is expected to be read-only and can contain elements of any type.
21
- * @returns A new array containing only the unique elements from the input array, in the order of their first occurrence.
25
+ * @param items - The array to deduplicate.
26
+ * @returns A new array with unique elements in their original order.
27
+ * @throws {@link !TypeError} if `items` is not an array.
28
+ * @typeParam T - The element type.
22
29
  */
23
- export const dedupe = (items) => Array.from(new Set(items));
30
+ export const dedupe = (items) => {
31
+ assertArray(items, 'items');
32
+ return Array.from(new Set(items));
33
+ };
24
34
  /**
25
- * Creates an array of unique values from the combined elements of the input arrays.
35
+ * Creates an array of unique values from multiple input arrays.
26
36
  *
27
- * @param arrays - The arrays to be merged and deduplicated.
28
- * @returns An array containing unique elements from all input arrays.
37
+ * @param arrays - Arrays or individual elements to merge.
38
+ * @returns A new array containing unique elements from all inputs.
39
+ * @typeParam T - The element type.
29
40
  */
30
41
  export function union(...arrays) {
31
42
  return dedupe(arrays.flatMap((v) => v));
32
43
  }
33
44
  /**
34
- * Computes the intersection of multiple arrays, returning an array that contains
35
- * all elements that are present in every input array.
45
+ * Returns elements present in all input arrays.
36
46
  *
37
- * @param arrays - A variadic parameter allowing multiple arrays or single elements.
38
- * Each array or element will be checked for intersection.
39
- * @returns An array containing elements that are present in all input arrays.
47
+ * @param arrays - Arrays or individual elements to intersect.
48
+ * @returns A new array containing elements common to all inputs.
49
+ * @typeParam T - The element type.
40
50
  */
41
51
  export function intersection(...arrays) {
42
52
  const { length } = arrays;
@@ -52,14 +62,16 @@ export function intersection(...arrays) {
52
62
  .map(([item]) => item);
53
63
  }
54
64
  /**
55
- * Computes the difference between a source array and one or more arrays of exclusions.
56
- * Returns a new array containing elements from the source array that are not present in any of the exclusion arrays.
65
+ * Returns elements from the source array that are not in any exclusion arrays.
57
66
  *
58
- * @param source - The source array to compare against.
59
- * @param excludes - Arrays containing elements to be excluded from the source array.
60
- * @returns A new array containing elements from the source array that are not in the exclusion arrays.
67
+ * @param source - The source array.
68
+ * @param excludes - Arrays of elements to exclude.
69
+ * @returns A new array with excluded elements removed.
70
+ * @throws {@link !TypeError} if `source` is not an array or `excludes` contains non-array elements.
71
+ * @typeParam T - The element type.
61
72
  */
62
73
  export function diff(source, ...excludes) {
74
+ assertArray(excludes, isArray, 'excludes');
63
75
  const set = new Set(excludes.flatMap((v) => v));
64
76
  return source.filter((v) => !set.has(v));
65
77
  }
@@ -1,5 +1,12 @@
1
+ /**
2
+ * This module provides utility functions for working with functions, including caching and memoization.
3
+ *
4
+ * @module
5
+ * @importTarget ./function
6
+ */
1
7
  import type { UnknownArray } from 'type-fest';
2
- import type { AnyFunction } from '@budsbox/lib-types';
8
+ import type { AnyFunction, Predicate } from '@budsbox/lib-types';
9
+ import { type NormalizedOptionalRest } from '#guards';
3
10
  /**
4
11
  * A function that does nothing.
5
12
  */
@@ -13,16 +20,17 @@ export declare const noop: () => void;
13
20
  export declare const pass: <T>(value: T) => T;
14
21
  type CacheableFn<TFn extends AnyFunction> = Parameters<TFn> extends [unknown, ...UnknownArray] ? TFn : never;
15
22
  type DefaultCacheKey<TFn extends AnyFunction> = Parameters<TFn> extends [infer TArg0, ...UnknownArray] ? TArg0 : never;
16
- type CachedFn<TFn extends AnyFunction, TKey = DefaultCacheKey<TFn>> = TFn extends (...args: infer TArgs) => infer TReturn ? (cacheMap: Map<TKey, TReturn>, ...args: TArgs) => TReturn : never;
23
+ type CachedFn<TFn extends AnyFunction, TKey = DefaultCacheKey<TFn>> = TFn extends (...args: infer TArgs) => infer TReturn ? (cacheMap: (TKey extends WeakKey ? WeakMap<TKey, TReturn> : never) | Map<TKey, TReturn>, ...args: TArgs) => TReturn : never;
17
24
  /**
18
25
  * Creates a cached version of a given function.
19
26
  * The returned function stores the results of previous calls in a provided cache map
20
27
  * and returns the cached result when called with the same arguments,
21
28
  * reducing redundant calculations or operations.
22
29
  *
23
- * @remarks A provided function has to accept at least one argument, or it fails typechecking.
24
- * @param fn - The function to be cached. It must conform to the `CacheableFn` type.
30
+ * @param fn - The function to be cached.
25
31
  * @returns A new function that accepts the cache map as the first argument and the original function's arguments as the rest.
32
+ * @remarks A provided function has to accept at least one argument, or it fails typechecking.
33
+ * @typeParam TFn - The type of function to be cache. It extends `AnyFunction` type.
26
34
  */
27
35
  export declare function createCachedFn<TFn extends AnyFunction>(fn: CacheableFn<TFn>): CachedFn<TFn>;
28
36
  /**
@@ -34,11 +42,60 @@ export declare function createCachedFn<TFn extends AnyFunction>(fn: CacheableFn<
34
42
  * key for each set of arguments. If the same key is generated for later
35
43
  * calls, the cached result is returned instead of invoking the original function.
36
44
  *
37
- * @remarks A provided function has to accept at least one argument, or it fails typechecking.
38
- * @param fn - The function to be cached. It must conform to the `CacheableFn` type.
45
+ * @param fn - The function to be cached.
39
46
  * @param keyFn - A function that generates a unique key based on the arguments passed to `fn`.
40
47
  * @returns A new function that accepts the cache map as the first argument and the original function's arguments as the rest.
48
+ * @remarks A provided function has to accept at least one argument, or it fails typechecking.
49
+ * @typeParam TFn - The type of function to be cache. It extends the ` AnyFunction ` type.
50
+ * @typeParam TKey - The type of key generated by the key function.
41
51
  */
42
52
  export declare function createCachedFn<TFn extends AnyFunction, TKey>(fn: CacheableFn<TFn>, keyFn: (...args: Parameters<TFn>) => TKey): CachedFn<TFn, TKey>;
53
+ /**
54
+ * Normalizes a sequence of optional rest arguments by matching them against a series of type predicates.
55
+ *
56
+ * This function takes an array of arguments and attempts to match each argument against the corresponding
57
+ * predicate in the sequence. Arguments that match their predicates are placed at their respective positions
58
+ * in the output array, while unmatched positions are filled with `undefined`. This enables flexible function
59
+ * signatures where arguments can be provided with gaps as long as they're in the right order.
60
+ *
61
+ * The function validates that:
62
+ * - No more arguments are provided than there are predicates
63
+ * - Each argument matches its corresponding predicate in sequence
64
+ * - Any remaining arguments after a successful match also satisfy the subsequent predicates
65
+ *
66
+ * @param predicateSequence - An ordered array of type predicates that define the expected types for each position.
67
+ * @param args - The actual arguments to normalize against the predicate sequence.
68
+ * @param restShift - An optional offset added to argument indices in error messages, useful when these
69
+ * arguments are part of a larger parameter list. Defaults to 0.
70
+ * @returns A tuple where each element is either the matched argument value or `undefined` if no match was found
71
+ * at that position. The length matches the predicate sequence length.
72
+ * @throws {@link !TypeError} If more arguments are provided than predicates in the sequence.
73
+ * @throws {@link !TypeError} If an argument doesn't match any of the remaining predicates in the sequence.
74
+ * @typeParam TPredicateSequence - a tuple of predicate types.
75
+ * @remarks For this function to work, a predicate sequence has to be tuple. Use `as const` to convert array to tuple.
76
+ * @example
77
+ * ```typescript
78
+ * normalizeOptionalRest([isString, isBoolean, isNumber], ['foo'])
79
+ * // Returns: ['foo', undefined, undefined]
80
+ *
81
+ * normalizeOptionalRest([isString, isBoolean, isNumber], [true])
82
+ * // Returns: [undefined, true, undefined]
83
+ *
84
+ * normalizeOptionalRest([isString, isBoolean, isNumber], ['foo', true, 1])
85
+ * // Returns: ['foo', true, 1]
86
+ *
87
+ * normalizeOptionalRest([isString, isBoolean, isNumber] as const, ['foo', 1])
88
+ * // Returns: ['foo', undefined, 1]
89
+ *
90
+ * // Using restShift for better error messages in nested contexts
91
+ * normalizeOptionalRest([isString, isBoolean] as const, ['foo', 'bar'], 2)
92
+ * // Throws: TypeError with message referencing rest[3] instead of rest[1]
93
+ *
94
+ * // Trailing undefined values are ignored
95
+ * normalizeOptionalRest([isString, isBoolean, isNumber] as const, ['foo', true, undefined])
96
+ * // Returns: ['foo', true, undefined]
97
+ * ```
98
+ */
99
+ export declare function normalizeOptionalRest<TPredicateSequence extends ReadonlyArray<Predicate<unknown>>>(predicateSequence: TPredicateSequence, args: readonly unknown[], restShift?: number): NormalizedOptionalRest<TPredicateSequence>;
43
100
  export {};
44
101
  //# sourceMappingURL=function.d.ts.map
package/dist/function.js CHANGED
@@ -1,3 +1,11 @@
1
+ /**
2
+ * This module provides utility functions for working with functions, including caching and memoization.
3
+ *
4
+ * @module
5
+ * @importTarget ./function
6
+ */
7
+ import { assertArray, assertEvery, assertFunction, isFunction, isInteger, isPositive, } from '#guards';
8
+ import { normalizeOptionalRest as _normalizeOptionalRest } from '#guards/assert';
1
9
  /**
2
10
  * A function that does nothing.
3
11
  */
@@ -10,6 +18,8 @@ export const noop = () => { };
10
18
  */
11
19
  export const pass = (value) => value;
12
20
  export function createCachedFn(fn, keyFn = pass) {
21
+ assertFunction(fn, 'fn');
22
+ assertFunction(keyFn, 'keyFn');
13
23
  return (map, ...args) => {
14
24
  const key = keyFn(...args);
15
25
  if (map.has(key))
@@ -19,4 +29,10 @@ export function createCachedFn(fn, keyFn = pass) {
19
29
  return result;
20
30
  };
21
31
  }
32
+ export function normalizeOptionalRest(predicateSequence, args, restShift = 0) {
33
+ assertArray(predicateSequence, isFunction);
34
+ assertArray(args);
35
+ assertEvery(restShift, 'restShift', isInteger, isPositive);
36
+ return _normalizeOptionalRest(predicateSequence, args, restShift);
37
+ }
22
38
  //# sourceMappingURL=function.js.map
@@ -0,0 +1,213 @@
1
+ /**
2
+ * @module
3
+ * Provides assertion functions for runtime type checking and validation.
4
+ * @categoryDescription Assertions
5
+ * Assertion functions for runtime type checking and validation.
6
+ */
7
+ import type { Primitive } from 'type-fest';
8
+ import type { AnyFunction, NarrowedType, NonNil, Predicate, TypePredicate, UnknownFunction, WithFallback } from '@budsbox/lib-types';
9
+ import type { InvariantFn, InvariantPredicateFn, NormalizedOptionalRest } from './types.js';
10
+ /**
11
+ * {@link InvariantFn} implementation.
12
+ *
13
+ * @inheritDoc {@link InvariantFn}
14
+ */
15
+ export declare const invariant: InvariantFn;
16
+ /**
17
+ * {@link InvariantPredicateFn} implementation.
18
+ *
19
+ * @inheritDoc {@link InvariantPredicateFn}
20
+ */
21
+ export declare const invariantPredicate: InvariantPredicateFn;
22
+ /**
23
+ * Evaluates a given predicate function with the specified value and an optional predicate name.
24
+ * Narrows the type of the value if the predicate is a type guard.
25
+ *
26
+ * @param predicate - A function that takes a value of type `TValue` and returns a boolean.
27
+ * @param value - The value to be passed to the predicate function.
28
+ * @param predicateName - An optional name for the predicate, used for identification or debugging purposes.
29
+ * @returns Returns `true` if the predicate function evaluates the value as valid, otherwise `false`.
30
+ * @throws {@link !TypeError} in the following cases:
31
+ * - If the provided `predicate` is not a function.
32
+ * - If the predicate function does not return a boolean.
33
+ * @typeParam TValue - The type of the value to be tested by the predicate.
34
+ * @typeParam TGuardInput - The type of the input to the predicate in case it's a type guard.
35
+ * @typeParam TNarrowed - The narrowed type of the value if the predicate is a type guard.
36
+ * @category Other
37
+ */
38
+ export declare function callPredicate<TNarrowed>(predicate: TypePredicate<unknown, TNarrowed>, value: unknown, predicateName?: string): value is TNarrowed;
39
+ export declare function callPredicate<TValue extends TGuardInput, TGuardInput, TNarrowed extends TGuardInput>(predicate: TypePredicate<TGuardInput, TNarrowed>, value: TValue, predicateName?: string): value is WithFallback<Extract<TValue, TNarrowed>, TValue & TNarrowed>;
40
+ export declare function callPredicate<TValue>(predicate: Predicate<TValue>, value: TValue, predicateName?: string): boolean;
41
+ export declare function normalizeOptionalRest<TPredicateSequence extends ReadonlyArray<Predicate<unknown>>>(predicateSequence: TPredicateSequence, args: readonly unknown[], restShift?: number): NormalizedOptionalRest<TPredicateSequence>;
42
+ /**
43
+ * Asserts that the given value is defined (not undefined).
44
+ *
45
+ * @param value - The value to be checked for being defined.
46
+ * @param name - An optional name or description of the value included in the error message if the assertion fails.
47
+ * @throws {@link !TypeError} If the value is undefined.
48
+ * @typeParam T - The type of the value being asserted.
49
+ * @category Assertions
50
+ */
51
+ export declare function assertDef<T>(value: T, name?: string): asserts value is NonNil<T> | (null & T);
52
+ /**
53
+ * Asserts that the provided value is neither null nor undefined.
54
+ *
55
+ * @param value - The value to check.
56
+ * @param name - The name of the value for the error message.
57
+ * @throws {@link !TypeError} If the value is null or undefined.
58
+ * @category Assertions
59
+ */
60
+ export declare function assertNotNil(value: unknown, name?: string): asserts value is NonNil;
61
+ /**
62
+ * Asserts that the provided value is a string.
63
+ *
64
+ * @param value - The value to check.
65
+ * @param name - The name of the value for the error message.
66
+ * @throws {@link !TypeError} If the value is not a string.
67
+ * @category Assertions
68
+ */
69
+ export declare function assertString(value: unknown, name?: string): asserts value is string;
70
+ /**
71
+ * Asserts that the provided value is a number and not NaN.
72
+ *
73
+ * @param value - The value to check.
74
+ * @param name - The name of the value for the error message.
75
+ * @throws {@link !TypeError} If the value is not a number or NaN.
76
+ * @remarks Throws a {@link !TypeError} if the value is NaN.
77
+ * @category Assertions
78
+ */
79
+ export declare function assertNumber(value: unknown, name?: string): asserts value is number;
80
+ /**
81
+ * Asserts that the provided value is a symbol.
82
+ *
83
+ * @param value - The value to be checked.
84
+ * @param name - An optional name for the value, used in the error message if the assertion fails. Defaults to 'value'.
85
+ * @throws {@link !TypeError} If the value is not a symbol.
86
+ * @category Assertions
87
+ */
88
+ export declare function assertSymbol(value: unknown, name?: string): asserts value is symbol;
89
+ /**
90
+ * Asserts that the provided value is a valid property key (string, number, or symbol).
91
+ *
92
+ * @param value - The value to check.
93
+ * @param name - The name of the value for the error message.
94
+ * @throws {@link !TypeError} If the value is not a valid property key.
95
+ * @category Assertions
96
+ */
97
+ export declare function assertPropKey(value: unknown, name?: string): asserts value is PropertyKey;
98
+ /**
99
+ * Asserts that the provided value is a boolean.
100
+ *
101
+ * @param value - The value to check.
102
+ * @param name - The name of the value for the error message.
103
+ * @throws {@link !TypeError} If the value is not a boolean.
104
+ * @category Assertions
105
+ */
106
+ export declare function assertBoolean(value: unknown, name?: string): asserts value is boolean;
107
+ /**
108
+ * Asserts that the provided value is a primitive type (string, number, boolean, bigint, symbol, null, or undefined).
109
+ *
110
+ * @param value - The value to check.
111
+ * @param name - The name of the value for the error message.
112
+ * @throws {@link !TypeError} If the value is not a primitive type.
113
+ * @category Assertions
114
+ */
115
+ export declare function assertPrimitive(value: unknown, name?: string): asserts value is Primitive;
116
+ /**
117
+ * Asserts that the provided value is an object.
118
+ *
119
+ * @param value - The value to check.
120
+ * @param name - The name of the value for the error message.
121
+ * @throws {@link !TypeError} If the value is not an object.
122
+ * @category Assertions
123
+ */
124
+ export declare function assertObject(value: unknown, name?: string): asserts value is object;
125
+ /**
126
+ * Asserts that the provided value is an array.
127
+ *
128
+ * @param value - The value to check.
129
+ * @param name - The name of the value for the error message.
130
+ * @returns void
131
+ * @throws {@link !TypeError} If the value is not an array.
132
+ * @typeParam T - The type of elements in the array.
133
+ * @category Assertions
134
+ */
135
+ export declare function assertArray<T>(value: T, name?: string): asserts value is WithFallback<Extract<T, readonly unknown[]>, T & unknown[]>;
136
+ export declare function assertArray<TValue, TGuard extends TypePredicate<WithFallback<TValue extends ReadonlyArray<infer TItem> ? TItem : never>>>(value: TValue, typeGuard: TGuard, name?: string): asserts value is WithFallback<Extract<TValue, Array<NarrowedType<TGuard>>>, TValue & Array<NarrowedType<TGuard>>>;
137
+ export declare function assertArray<TValue>(value: TValue, predicate: Predicate<WithFallback<TValue extends ReadonlyArray<infer TItem> ? TItem : never>>, name?: string): asserts value is WithFallback<Extract<TValue, readonly unknown[]>, TValue & unknown[]>;
138
+ /**
139
+ * Asserts that the provided value is a function.
140
+ *
141
+ * @param value - The value to check.
142
+ * @param name - The name of the value for the error message.
143
+ * @returns void
144
+ * @throws {@link !TypeError} If the value is not a function.
145
+ * @typeParam T - The type being checked.
146
+ * @category Assertions
147
+ */
148
+ export declare function assertFunction<T>(value: T, name?: string): asserts value is WithFallback<Extract<T, AnyFunction>, UnknownFunction & T>;
149
+ export declare function assertFunction<TFn extends AnyFunction = UnknownFunction>(value: unknown, name?: string): asserts value is TFn;
150
+ /**
151
+ * Asserts that the provided value is a Date object.
152
+ *
153
+ * @param value - The value to check.
154
+ * @param name - The name of the value for the error message.
155
+ * @throws {@link !TypeError} If the value is not a Date object.
156
+ * @category Assertions
157
+ */
158
+ export declare function assertDate(value: unknown, name?: string): asserts value is Date;
159
+ /**
160
+ * Asserts that the provided value is a RegExp object.
161
+ *
162
+ * @param value - The value to check.
163
+ * @param name - The name of the value for the error message.
164
+ * @throws {@link !TypeError} If the value is not a RegExp object.
165
+ * @category Assertions
166
+ */
167
+ export declare function assertRegExp(value: unknown, name?: string): asserts value is RegExp;
168
+ /**
169
+ * Asserts that the provided value is an Error object.
170
+ *
171
+ * @param value - The value to check.
172
+ * @param name - The name of the value for the error message.
173
+ * @throws {@link !TypeError} If the value is not an Error object.
174
+ * @category Assertions
175
+ */
176
+ export declare function assertError(value: unknown, name?: string): asserts value is Error;
177
+ /**
178
+ * Asserts that the provided value is a Map object.
179
+ *
180
+ * @param value - The value to check.
181
+ * @param name - The name of the value for the error message.
182
+ * @throws {@link !TypeError} If the value is not a Map object.
183
+ * @category Assertions
184
+ */
185
+ export declare function assertMap(value: unknown, name?: string): asserts value is Map<unknown, unknown>;
186
+ /**
187
+ * Asserts that the provided value is a Set object.
188
+ *
189
+ * @param value - The value to check.
190
+ * @param name - The name of the value for the error message.
191
+ * @throws {@link !TypeError} If the value is not a Set object.
192
+ * @category Assertions
193
+ */
194
+ export declare function assertSet(value: unknown, name?: string): asserts value is Set<unknown>;
195
+ /**
196
+ * Asserts that the provided value is WeakMap-like (a WeakMap object).
197
+ *
198
+ * @param value - The value to check.
199
+ * @param name - The name of the value for the error message.
200
+ * @throws {@link !TypeError} If the value is not a WeakMap object.
201
+ * @category Assertions
202
+ */
203
+ export declare function assertWeakMapLike(value: unknown, name?: string): asserts value is WeakMap<WeakKey, unknown>;
204
+ /**
205
+ * Asserts that the provided value is WeakSet-like (a WeakSet object).
206
+ *
207
+ * @param value - The value to check.
208
+ * @param name - The name of the value for the error message.
209
+ * @throws {@link !TypeError} If the value is not a WeakSet object.
210
+ * @category Assertions
211
+ */
212
+ export declare function assertWeakSetLike(value: unknown, name?: string): asserts value is WeakSet<WeakKey>;
213
+ //# sourceMappingURL=assert.d.ts.map