@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.
@@ -0,0 +1,245 @@
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 { isArray, isBoolean, isDate, isDef, isError, isFunction, isMap, isNotNil, isNumber, isObject, isPrimitive, isPropKey, isRegExp, isSet, isString, isSymbol, isTrue, isWeakMapLike, isWeakSetLike, } from './check.js';
8
+ import { describeComplexPredicate } from './describe.js';
9
+ import { formatAccessString, formatPredicateExpectedMessage, } from './format.js';
10
+ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GENERAL ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
11
+ /**
12
+ * {@link InvariantFn} implementation.
13
+ *
14
+ * @inheritDoc {@link InvariantFn}
15
+ */
16
+ export const invariant = (condition, message = formatPredicateExpectedMessage(isTrue, false, 'condition')) => {
17
+ if (!isTrue(condition))
18
+ throw new TypeError(isFunction(message) ? message() : message);
19
+ };
20
+ /**
21
+ * {@link InvariantPredicateFn} implementation.
22
+ *
23
+ * @inheritDoc {@link InvariantPredicateFn}
24
+ */
25
+ export const invariantPredicate = (predicate, value, valueName = 'value') => {
26
+ invariant(callPredicate(predicate, value), () => formatPredicateExpectedMessage(predicate, value, valueName));
27
+ };
28
+ export function callPredicate(predicate, value, predicateName = 'predicate') {
29
+ if (!isFunction(predicate))
30
+ throw new TypeError(formatPredicateExpectedMessage(isFunction, predicate, predicateName));
31
+ const result = predicate(value);
32
+ if (!isBoolean(result))
33
+ throw new TypeError(formatPredicateExpectedMessage(isBoolean, result, 'predicate result'));
34
+ return result;
35
+ }
36
+ export function normalizeOptionalRest(predicateSequence, args, restShift = 0) {
37
+ if (args.length > predicateSequence.length)
38
+ throw new TypeError(
39
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
40
+ `Too many arguments provided. Expected at most ${predicateSequence.length + restShift}, got ${args.length + restShift}`);
41
+ const output = new Array(predicateSequence.length).fill(undefined);
42
+ let predicateSuccessIndex = -1, argIndex = 0;
43
+ for (let i = 0; i < predicateSequence.length; i++) {
44
+ const predicate = predicateSequence[i];
45
+ if (callPredicate(predicate, args[argIndex])) {
46
+ predicateSuccessIndex = i;
47
+ output[i] = args[argIndex++];
48
+ }
49
+ }
50
+ if (argIndex < args.length &&
51
+ !args.slice(argIndex).every((v) => v === undefined)) {
52
+ invariantPredicate(describeComplexPredicate(() => false, // dummy
53
+ false, ...predicateSequence.slice(predicateSuccessIndex + 1)), args[argIndex], formatAccessString('args', argIndex + restShift));
54
+ }
55
+ return output;
56
+ }
57
+ /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ASSERTIONS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
58
+ /**
59
+ * Asserts that the given value is defined (not undefined).
60
+ *
61
+ * @param value - The value to be checked for being defined.
62
+ * @param name - An optional name or description of the value included in the error message if the assertion fails.
63
+ * @throws {@link !TypeError} If the value is undefined.
64
+ * @typeParam T - The type of the value being asserted.
65
+ * @category Assertions
66
+ */
67
+ export function assertDef(value, name) {
68
+ invariantPredicate(isDef, value, name);
69
+ }
70
+ /**
71
+ * Asserts that the provided value is neither null nor undefined.
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 null or undefined.
76
+ * @category Assertions
77
+ */
78
+ export function assertNotNil(value, name) {
79
+ invariantPredicate(isNotNil, value, name);
80
+ }
81
+ /**
82
+ * Asserts that the provided value is a string.
83
+ *
84
+ * @param value - The value to check.
85
+ * @param name - The name of the value for the error message.
86
+ * @throws {@link !TypeError} If the value is not a string.
87
+ * @category Assertions
88
+ */
89
+ export function assertString(value, name) {
90
+ invariantPredicate(isString, value, name);
91
+ }
92
+ /**
93
+ * Asserts that the provided value is a number and not NaN.
94
+ *
95
+ * @param value - The value to check.
96
+ * @param name - The name of the value for the error message.
97
+ * @throws {@link !TypeError} If the value is not a number or NaN.
98
+ * @remarks Throws a {@link !TypeError} if the value is NaN.
99
+ * @category Assertions
100
+ */
101
+ export function assertNumber(value, name) {
102
+ invariantPredicate(isNumber, value, name);
103
+ }
104
+ /**
105
+ * Asserts that the provided value is a symbol.
106
+ *
107
+ * @param value - The value to be checked.
108
+ * @param name - An optional name for the value, used in the error message if the assertion fails. Defaults to 'value'.
109
+ * @throws {@link !TypeError} If the value is not a symbol.
110
+ * @category Assertions
111
+ */
112
+ export function assertSymbol(value, name) {
113
+ invariantPredicate(isSymbol, value, name);
114
+ }
115
+ /**
116
+ * Asserts that the provided value is a valid property key (string, number, or symbol).
117
+ *
118
+ * @param value - The value to check.
119
+ * @param name - The name of the value for the error message.
120
+ * @throws {@link !TypeError} If the value is not a valid property key.
121
+ * @category Assertions
122
+ */
123
+ export function assertPropKey(value, name) {
124
+ invariantPredicate(isPropKey, value, name);
125
+ }
126
+ /**
127
+ * Asserts that the provided value is a boolean.
128
+ *
129
+ * @param value - The value to check.
130
+ * @param name - The name of the value for the error message.
131
+ * @throws {@link !TypeError} If the value is not a boolean.
132
+ * @category Assertions
133
+ */
134
+ export function assertBoolean(value, name) {
135
+ invariantPredicate(isBoolean, value, name);
136
+ }
137
+ /**
138
+ * Asserts that the provided value is a primitive type (string, number, boolean, bigint, symbol, null, or undefined).
139
+ *
140
+ * @param value - The value to check.
141
+ * @param name - The name of the value for the error message.
142
+ * @throws {@link !TypeError} If the value is not a primitive type.
143
+ * @category Assertions
144
+ */
145
+ export function assertPrimitive(value, name) {
146
+ invariantPredicate(isPrimitive, value, name);
147
+ }
148
+ /**
149
+ * Asserts that the provided value is an object.
150
+ *
151
+ * @param value - The value to check.
152
+ * @param name - The name of the value for the error message.
153
+ * @throws {@link !TypeError} If the value is not an object.
154
+ * @category Assertions
155
+ */
156
+ export function assertObject(value, name) {
157
+ invariantPredicate(isObject, value, name);
158
+ }
159
+ export function assertArray(value, ...rest) {
160
+ const [predicate, name = 'valueName'] = normalizeOptionalRest([isFunction, isString], rest, 1);
161
+ invariantPredicate(isArray, value, name);
162
+ if (isFunction(predicate))
163
+ value.forEach((el, i) => void invariantPredicate(predicate, el, `${name}[${String(i)}]`));
164
+ }
165
+ export function assertFunction(value, name) {
166
+ invariantPredicate(isFunction, value, name);
167
+ }
168
+ /**
169
+ * Asserts that the provided value is a Date 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 a Date object.
174
+ * @category Assertions
175
+ */
176
+ export function assertDate(value, name) {
177
+ invariantPredicate(isDate, value, name);
178
+ }
179
+ /**
180
+ * Asserts that the provided value is a RegExp object.
181
+ *
182
+ * @param value - The value to check.
183
+ * @param name - The name of the value for the error message.
184
+ * @throws {@link !TypeError} If the value is not a RegExp object.
185
+ * @category Assertions
186
+ */
187
+ export function assertRegExp(value, name) {
188
+ invariantPredicate(isRegExp, value, name);
189
+ }
190
+ /**
191
+ * Asserts that the provided value is an Error object.
192
+ *
193
+ * @param value - The value to check.
194
+ * @param name - The name of the value for the error message.
195
+ * @throws {@link !TypeError} If the value is not an Error object.
196
+ * @category Assertions
197
+ */
198
+ export function assertError(value, name) {
199
+ invariantPredicate(isError, value, name);
200
+ }
201
+ /**
202
+ * Asserts that the provided value is a Map object.
203
+ *
204
+ * @param value - The value to check.
205
+ * @param name - The name of the value for the error message.
206
+ * @throws {@link !TypeError} If the value is not a Map object.
207
+ * @category Assertions
208
+ */
209
+ export function assertMap(value, name) {
210
+ invariantPredicate(isMap, value, name);
211
+ }
212
+ /**
213
+ * Asserts that the provided value is a Set object.
214
+ *
215
+ * @param value - The value to check.
216
+ * @param name - The name of the value for the error message.
217
+ * @throws {@link !TypeError} If the value is not a Set object.
218
+ * @category Assertions
219
+ */
220
+ export function assertSet(value, name) {
221
+ invariantPredicate(isSet, value, name);
222
+ }
223
+ /**
224
+ * Asserts that the provided value is WeakMap-like (a WeakMap object).
225
+ *
226
+ * @param value - The value to check.
227
+ * @param name - The name of the value for the error message.
228
+ * @throws {@link !TypeError} If the value is not a WeakMap object.
229
+ * @category Assertions
230
+ */
231
+ export function assertWeakMapLike(value, name) {
232
+ invariantPredicate(isWeakMapLike, value, name);
233
+ }
234
+ /**
235
+ * Asserts that the provided value is WeakSet-like (a WeakSet object).
236
+ *
237
+ * @param value - The value to check.
238
+ * @param name - The name of the value for the error message.
239
+ * @throws {@link !TypeError} If the value is not a WeakSet object.
240
+ * @category Assertions
241
+ */
242
+ export function assertWeakSetLike(value, name) {
243
+ invariantPredicate(isWeakSetLike, value, name);
244
+ }
245
+ //# sourceMappingURL=assert.js.map
@@ -0,0 +1,470 @@
1
+ /**
2
+ * @module
3
+ * This module provides type guards for various JavaScript types.
4
+ * @categoryDescription Checks
5
+ * Type guards for JavaScript primitives and common types.
6
+ */
7
+ import type { Primitive } from 'type-fest';
8
+ import type { AnyFunction, Nil, NonNil, Undef, UnknownFunction, WithFallback } from '@budsbox/lib-types';
9
+ export type { Primitive };
10
+ /**
11
+ * Checks if the provided value is `undefined`.
12
+ *
13
+ * @param value - The value to check for `undefined`.
14
+ * @returns `true` if the value is `undefined`, otherwise `false`.
15
+ * @example
16
+ * ```typescript
17
+ * isUndef(undefined); // true
18
+ * isUndef(null); // false
19
+ * isUndef(0); // false
20
+ * ```
21
+ * @category Checks
22
+ */
23
+ export declare function isUndef(value: unknown): value is Undef;
24
+ /**
25
+ * {@label OVERLOAD_T}
26
+ *
27
+ * Checks if a given value is defined (not `undefined`).
28
+ *
29
+ * @param value - The value to check.
30
+ * @returns `true` if the value is defined, otherwise `false`.
31
+ * @typeParam T - Type of the input value.
32
+ * @example
33
+ * ```typescript
34
+ * isDef(undefined); // false
35
+ * isDef(null); // true
36
+ * isDef(42); // true
37
+ * ```
38
+ * @category Checks
39
+ */
40
+ export declare function isDef<T>(value: T): value is NonNil<T> | (null & T);
41
+ /**
42
+ * Checks if the provided value is `null` or `undefined`.
43
+ *
44
+ * @param value - The value to be checked.
45
+ * @returns `true` if the value is `null` or `undefined`, otherwise `false`.
46
+ * @example
47
+ * ```typescript
48
+ * isNil(null); // true
49
+ * isNil(undefined); // true
50
+ * isNil(false); // false
51
+ * isNil(''); // false
52
+ * ```
53
+ * @category Checks
54
+ */
55
+ export declare function isNil(value: unknown): value is Nil;
56
+ /**
57
+ * {@label OVERLOAD_VALUE}
58
+ *
59
+ * Checks if the provided value is not `null` or `undefined`.
60
+ *
61
+ * @param value - The value to be checked.
62
+ * @returns `true` if the value is not `null` or `undefined`; otherwise, `false`.
63
+ * @example
64
+ * ```typescript
65
+ * isNotNil(null); // false
66
+ * isNotNil(undefined); // false
67
+ * isNotNil(0); // true
68
+ * isNotNil(''); // true
69
+ * ```
70
+ * @category Checks
71
+ */
72
+ export declare function isNotNil(value: unknown): value is NonNil;
73
+ /**
74
+ * Checks if the given value is of type ``boolean``.
75
+ *
76
+ * @param value - The value to check.
77
+ * @returns `true` if the value is a `boolean`, otherwise `false`.
78
+ * @example
79
+ * ```typescript
80
+ * isBoolean(true); // true
81
+ * isBoolean(false); // true
82
+ * isBoolean(1); // false
83
+ * isBoolean('true'); // false
84
+ * ```
85
+ * @category Checks
86
+ */
87
+ export declare function isBoolean(value: unknown): value is boolean;
88
+ /**
89
+ * Checks if the provided value is strictly equal to `true`.
90
+ *
91
+ * @param value - The value to check.
92
+ * @returns `true` if the value is strictly `true`, otherwise `false`.
93
+ * @example
94
+ * ```typescript
95
+ * isTrue(true); // true
96
+ * isTrue(1); // false
97
+ * isTrue('true'); // false
98
+ * isTrue(false); // false
99
+ * ```
100
+ * @category Checks
101
+ */
102
+ export declare function isTrue(value: unknown): value is true;
103
+ /**
104
+ * Determines if the provided value is strictly `false`.
105
+ *
106
+ * @param value - The value to be checked.
107
+ * @returns `true` if the value is `false`, otherwise `false`.
108
+ * @example
109
+ * ```typescript
110
+ * isFalse(false); // true
111
+ * isFalse(0); // false
112
+ * isFalse(''); // false
113
+ * isFalse(true); // false
114
+ * ```
115
+ * @category Checks
116
+ */
117
+ export declare function isFalse(value: unknown): value is false;
118
+ /**
119
+ * Determines if the given value is truthy, i.e., converts to `true` when used in a `boolean` context.
120
+ *
121
+ * @param value - The value to be tested for truthiness.
122
+ * @returns `true` if the value is truthy, `false` otherwise.
123
+ * @example
124
+ * ```typescript
125
+ * isTruly(true); // true
126
+ * isTruly(1); // true
127
+ * isTruly('hello'); // true
128
+ * isTruly(0); // false
129
+ * isTruly(''); // false
130
+ * isTruly(null); // false
131
+ * ```
132
+ * @category Checks
133
+ */
134
+ export declare function isTruly(value: unknown): boolean;
135
+ /**
136
+ * Determines if a given value is falsy.
137
+ * A value is considered falsy if it evaluates to `false` when coerced to a `boolean`.
138
+ *
139
+ * @param value - The value to be tested.
140
+ * @returns `true` if the value is falsy, otherwise `false`.
141
+ * @example
142
+ * ```typescript
143
+ * isFalsy(false); // true
144
+ * isFalsy(0); // true
145
+ * isFalsy(''); // true
146
+ * isFalsy(null); // true
147
+ * isFalsy(undefined); // true
148
+ * isFalsy('hello'); // false
149
+ * ```
150
+ * @category Checks
151
+ */
152
+ export declare function isFalsy(value: unknown): boolean;
153
+ /**
154
+ * Checks if the provided value is a `number` and not {@link NaN}.
155
+ *
156
+ * @param value - The value to be checked.
157
+ * @returns `true` if the value is a `number` and not {@link NaN}, otherwise `false`.
158
+ * @example
159
+ * ```typescript
160
+ * isNumber(42); // true
161
+ * isNumber(3.14); // true
162
+ * isNumber(NaN); // false
163
+ * isNumber('42'); // false
164
+ * isNumber(null); // false
165
+ * ```
166
+ * @category Checks
167
+ */
168
+ export declare function isNumber(value: unknown): value is number;
169
+ /**
170
+ * Checks if a given value is of type `bigint`.
171
+ *
172
+ * @param value - The value to be checked.
173
+ * @returns `true` if the value is a `bigint`, otherwise `false`.
174
+ * @example
175
+ * ```typescript
176
+ * isBigint(42n); // true
177
+ * isBigint(42); // false
178
+ * isBigint('42'); // false
179
+ * isBigint(BigInt(42)); // true
180
+ * ```
181
+ * @category Checks
182
+ */
183
+ export declare function isBigint(value: unknown): value is bigint;
184
+ /**
185
+ * Determines whether a given number is positive.
186
+ *
187
+ * @param num - The `number` or `bigint` to check.
188
+ * @returns `true` if the input is greater than zero, otherwise `false`.
189
+ * @example
190
+ * ```typescript
191
+ * isPositive(42); // true
192
+ * isPositive(0); // false
193
+ * isPositive(-5); // false
194
+ * isPositive(100n); // true
195
+ * ```
196
+ * @category Checks
197
+ */
198
+ export declare function isPositive(num: bigint | number): boolean;
199
+ /**
200
+ * Determines whether a given number is non-negative.
201
+ *
202
+ * @param num - The number to check. It can be a `bigint` or a `number`.
203
+ * @returns `true` if the provided number is greater than or equal to zero, otherwise `false`.
204
+ * @example
205
+ * ```typescript
206
+ * isNonNegative(42); // true
207
+ * isNonNegative(0); // true
208
+ * isNonNegative(-1); // false
209
+ * isNonNegative(0n); // true
210
+ * ```
211
+ * @category Checks
212
+ */
213
+ export declare function isNonNegative(num: bigint | number): boolean;
214
+ /**
215
+ * Checks if the provided value is an integer.
216
+ *
217
+ * @param value - The value to check, which can be a `bigint` or `number`.
218
+ * @returns `true` if the value is an integer, otherwise `false`.
219
+ * @example
220
+ * ```typescript
221
+ * isInteger(42); // true
222
+ * isInteger(3.14); // false
223
+ * isInteger(42n); // true
224
+ * ```
225
+ * @category Checks
226
+ */
227
+ export declare function isInteger(value: unknown): value is bigint | number;
228
+ /**
229
+ * Determines if the provided value is a `string`.
230
+ *
231
+ * @param value - The value to check.
232
+ * @returns `true` if the value is a `string`, otherwise `false`.
233
+ * @example
234
+ * ```typescript
235
+ * isString('hello'); // true
236
+ * isString(42); // false
237
+ * ```
238
+ * @category Checks
239
+ */
240
+ export declare function isString(value: unknown): value is string;
241
+ /**
242
+ * Checks if the provided value is of type ``symbol``.
243
+ *
244
+ * @param value - The value to check.
245
+ * @returns `true` if the value is a `symbol`, otherwise `false`.
246
+ * @example
247
+ * ```typescript
248
+ * isSymbol(Symbol('foo')); // true
249
+ * isSymbol('foo'); // false
250
+ * ```
251
+ * @category Checks
252
+ */
253
+ export declare const isSymbol: (value: unknown) => value is symbol;
254
+ /**
255
+ * Determines whether the given value is a valid JavaScript property key.
256
+ *
257
+ * A property key in JavaScript can be a `string`, `symbol`, or `number`, as these are
258
+ * the types allowed for indexing object properties.
259
+ *
260
+ * @param value - The value to be checked as a potential property key.
261
+ * @returns `true` if the value is a valid property key, otherwise `false`.
262
+ * @example
263
+ * ```typescript
264
+ * isPropKey('foo'); // true
265
+ * isPropKey(123); // true
266
+ * isPropKey(Symbol('bar')); // true
267
+ * isPropKey({}); // false
268
+ * ```
269
+ * @category Checks
270
+ */
271
+ export declare const isPropKey: (value: unknown) => value is PropertyKey;
272
+ /**
273
+ * Checks if a given value is a {@link Primitive} type (`null`, `undefined`, `boolean`, `string`, `number`, `symbol`, or `bigint`).
274
+ *
275
+ * @param value - The value to check.
276
+ * @returns `true` if the value is a {@link Primitive} type, otherwise `false`.
277
+ * @example
278
+ * ```typescript
279
+ * isPrimitive(42); // true
280
+ * isPrimitive('foo'); // true
281
+ * isPrimitive(null); // true
282
+ * isPrimitive({}); // false
283
+ * ```
284
+ * @category Checks
285
+ */
286
+ export declare const isPrimitive: (value: unknown) => value is Primitive;
287
+ /**
288
+ * Checks if the given value is an {@link object}.
289
+ *
290
+ * @param value - The value to check.
291
+ * @returns `true` if the value is an {@link object}, `false` otherwise.
292
+ * @example
293
+ * ```typescript
294
+ * isObject({}); // true
295
+ * isObject([]); // true
296
+ * isObject(null); // false
297
+ * ```
298
+ * @category Checks
299
+ */
300
+ export declare function isObject(value: unknown): value is object;
301
+ /**
302
+ * Checks if the given value is an {@link Array}.
303
+ *
304
+ * @param value - The value to check.
305
+ * @returns `true` if the value is an {@link Array}, otherwise `false`.
306
+ * @typeParam T - Type of the value to be checked.
307
+ * @example
308
+ * ```typescript
309
+ * isArray([1, 2, 3]); // true
310
+ * isArray('foo'); // false
311
+ * ```
312
+ * @category Checks
313
+ */
314
+ export declare function isArray<T>(value: T): value is WithFallback<Extract<T, readonly unknown[]>, T & unknown[]>;
315
+ /**
316
+ * {@label OVERLOAD_T}
317
+ *
318
+ * Determines if the provided value is a function.
319
+ *
320
+ * @param value - The value to check.
321
+ * @returns `true` if the value is a function, otherwise `false`.
322
+ * @typeParam T - The type of the value being checked.
323
+ * @example
324
+ * ```typescript
325
+ * isFunction(() => {}); // true
326
+ * isFunction(42); // false
327
+ * ```
328
+ * @category Checks
329
+ */
330
+ export declare function isFunction<T>(value: T): value is WithFallback<Extract<T, AnyFunction>, UnknownFunction & T>;
331
+ /**
332
+ * {@label OVERLOAD_TFN}
333
+ *
334
+ * Determines if the provided value is of type {@link Function}.
335
+ *
336
+ * @param value - The value to be checked.
337
+ * @returns `true` if the value is a function, otherwise `false`.
338
+ * @typeParam TFn - Function type to narrow to when the check passes.
339
+ * @example
340
+ * ```typescript
341
+ * isFunction<() => void>(() => {}); // true
342
+ * ```
343
+ * @category Checks
344
+ */
345
+ export declare function isFunction<TFn extends AnyFunction = UnknownFunction>(value: unknown): value is TFn;
346
+ /**
347
+ * {@label OVERLOAD_UNKNOWN}
348
+ *
349
+ * Determines if the provided value is a function.
350
+ *
351
+ * @param value - The value to check.
352
+ * @returns `true` if the value is a function, otherwise `false`.
353
+ * @category Checks
354
+ */
355
+ export declare function isFunction(value: unknown): value is AnyFunction;
356
+ /**
357
+ * Checks if the given value is a {@link Date} instance.
358
+ *
359
+ * @param value - The value to check.
360
+ * @returns `true` if the value is a {@link Date} instance, otherwise `false`.
361
+ * @example
362
+ * ```typescript
363
+ * isDate(new Date()); // true
364
+ * isDate('2023-01-01'); // false
365
+ * ```
366
+ * @category Checks
367
+ */
368
+ export declare function isDate(value: unknown): value is Date;
369
+ /**
370
+ * Checks if the given value is a {@link RegExp} instance.
371
+ *
372
+ * @param value - The value to check.
373
+ * @returns `true` if the value is a {@link RegExp} instance, otherwise `false`.
374
+ * @example
375
+ * ```typescript
376
+ * isRegExp(/foo/); // true
377
+ * isRegExp('foo'); // false
378
+ * ```
379
+ * @category Checks
380
+ */
381
+ export declare function isRegExp(value: unknown): value is RegExp;
382
+ /**
383
+ * Checks if the given value is an {@link Error} instance.
384
+ *
385
+ * @param value - The value to check.
386
+ * @returns `true` if the value is an {@link Error} instance, otherwise `false`.
387
+ * @example
388
+ * ```typescript
389
+ * isError(new Error('foo')); // true
390
+ * isError({ message: 'foo' }); // false
391
+ * ```
392
+ * @category Checks
393
+ */
394
+ export declare function isError(value: unknown): value is Error;
395
+ /**
396
+ * Checks if the given value is a {@link Map} instance.
397
+ *
398
+ * @param value - The value to check.
399
+ * @returns `true` if the value is a {@link Map} instance, otherwise `false`.
400
+ * @example
401
+ * ```typescript
402
+ * isMap(new Map()); // true
403
+ * isMap({}); // false
404
+ * ```
405
+ * @category Checks
406
+ */
407
+ export declare function isMap(value: unknown): value is Map<unknown, unknown>;
408
+ /**
409
+ * Checks if the given value is a {@link Set} instance.
410
+ *
411
+ * @param value - The value to check.
412
+ * @returns `true` if the value is a {@link Set} instance, otherwise `false`.
413
+ * @example
414
+ * ```typescript
415
+ * isSet(new Set()); // true
416
+ * isSet([]); // false
417
+ * ```
418
+ * @category Checks
419
+ */
420
+ export declare function isSet(value: unknown): value is Set<unknown>;
421
+ /**
422
+ * Checks if the given value is a {@link WeakMap} or {@link Map} instance.
423
+ *
424
+ * @param value - The value to check.
425
+ * @returns `true` if the value is a {@link WeakMap} or {@link Map} instance, otherwise `false`.
426
+ * @example
427
+ * ```typescript
428
+ * isWeakMapLike(new WeakMap()); // true
429
+ * isWeakMapLike(new Map()); // true
430
+ * isWeakMapLike({}); // false
431
+ * ```
432
+ * @category Checks
433
+ */
434
+ export declare function isWeakMapLike(value: unknown): value is Map<unknown, unknown> | WeakMap<WeakKey, unknown>;
435
+ /**
436
+ * Checks if the given value is a {@link WeakSet} or {@link Set} instance.
437
+ *
438
+ * @param value - The value to check.
439
+ * @returns `true` if the value is a {@link WeakSet} or {@link Set} instance, otherwise `false`.
440
+ * @example
441
+ * ```typescript
442
+ * isWeakSetLike(new WeakSet()); // true
443
+ * isWeakSetLike(new Set()); // true
444
+ * isWeakSetLike([]); // false
445
+ * ```
446
+ * @category Checks
447
+ */
448
+ export declare function isWeakSetLike(value: unknown): value is Set<unknown> | WeakSet<WeakKey>;
449
+ /**
450
+ * Determines whether two values are the same value using the
451
+ * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Equality_comparisons_and_sameness#same-value-zero_equality "SameValueZero" comparison algorithm}.
452
+ *
453
+ * @param x - The first value to be compared.
454
+ * @param y - The second value to be compared.
455
+ * @returns `true` if `x` and `y` are the same value according to the "SameValueZero" comparison, otherwise `false`.
456
+ * @remarks
457
+ * - It differs from strict equality (`===`) in that {@link NaN} is considered equal to itself.
458
+ * - It differs from {@link Object.is} in that it considers `-0` and `+0` equal.
459
+ * - It's the same algorithm used by {@link Set} and {@link Map} to compare elements.
460
+ * @typeParam TValue - The type of the first value being compared.
461
+ * @example
462
+ * ```typescript
463
+ * sameValueZero(0, -0); // true
464
+ * sameValueZero(NaN, NaN); // true
465
+ * sameValueZero(1, '1'); // false
466
+ * ```
467
+ * @category Checks
468
+ */
469
+ export declare const sameValueZero: <TValue>(x: TValue, y: unknown) => y is TValue;
470
+ //# sourceMappingURL=check.d.ts.map