@tool-belt/type-predicates
Version:
A comprehensive collection of performant type guards and assertions with excellent TypeScript support
1,230 lines (1,061 loc) • 36.7 kB
TypeScript
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsAnyArrayBuffer(input: unknown, options?: ErrorMessage): asserts input is ArrayBuffer | SharedArrayBuffer;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsArgumentsObject(input: unknown, options?: ErrorMessage): asserts input is IArguments;
/**
* @category Type Assertion
* @example
*
* ```typescript
* // doesn't throw, value is typed as unknown[]
* assertIsArray(['xyz']);
*
* // doesn't throw, value is typed as string[]
* assertIsArray<string>(['xyz'], { valueValidator: isString });
*
* // throws
* assertIsArray<string>(['xyz', 1], { valueValidator: isString });
* ```
*
* @throws TypeError
*/
export declare function assertIsArray(input: unknown, options?: ErrorMessage): asserts input is unknown[];
export declare function assertIsArray<T>(input: unknown, options: (ErrorMessage & ValueValidator) | ValueValidator): asserts input is T[];
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsArrayBuffer(input: unknown, options?: ErrorMessage): asserts input is ArrayBuffer;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsArrayBufferView(input: unknown, options?: ErrorMessage): asserts input is ArrayBufferView;
/**
* @remarks
* This assertion works only in ES2018 and above
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsAsyncFunction<T = unknown>(input: unknown, options?: ErrorMessage): asserts input is AsyncFunction<T>;
/**
* @remarks
* This assertion works only in ES2018 and above
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsAsyncGenerator<Y = unknown, R = unknown, N = unknown>(input: unknown, options?: ErrorMessage): asserts input is AsyncGenerator<Y, R, N>;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsAsyncGeneratorFunction<Y = unknown, R = unknown, N = unknown>(input: unknown, options?: ErrorMessage): asserts input is TypedAsyncGeneratorFunction<Y, R, N>;
/**
* @remarks
* This guard tests for Symbol.asyncIterator. See:
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator}
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsAsyncIterable<T = unknown>(input: unknown, options?: ErrorMessage): asserts input is AsyncIterable<T>;
/**
* @category Type Assertion
* @example
*
* ```typescript
* // does not throw
* assertIsBigInt(BigInt(9007199254740991));
*
* // throws
* assertIsBigInt(9007199254740991n);
* ```
*
* @throws TypeError
*/
export declare function assertIsBigInt(input: unknown, options?: ErrorMessage): asserts input is bigint;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsBigInt64Array(input: unknown, options?: ErrorMessage): asserts input is BigInt64Array;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsBigIntObject(input: unknown, options?: ErrorMessage): asserts input is bigint;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsBigUint64Array(input: unknown, options?: ErrorMessage): asserts input is BigUint64Array;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsBoolean(input: unknown, options?: ErrorMessage): asserts input is boolean;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsBooleanObject(input: unknown, options?: ErrorMessage): asserts input is boolean;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsBoxedPrimitive(input: unknown, options?: ErrorMessage): asserts input is bigint | boolean | number | string | symbol;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsBuffer(input: unknown, options?: ErrorMessage): asserts input is Buffer;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsDataView(input: unknown, options?: ErrorMessage): asserts input is DataView;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsDate(input: unknown, options?: ErrorMessage): asserts input is Date;
/**
* @remarks
* This assertion asserts that the value is not null, use assertIsNotNullish to
* also exclude undefined
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsDefined<T>(input: T | undefined, options?: ErrorMessage): asserts input is T;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsEmptyArray(input: unknown, options?: ErrorMessage): asserts input is [];
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsEmptyObject(input: unknown, options?: ErrorMessage): asserts input is Record<string, never>;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsEmptyString(input: unknown, options?: ErrorMessage): asserts input is '';
/**
* ```typescript
* // does not throw, value is typed as Error
* assertIsError(new Error());
*
* // does not throw, value is typed as Error
* // Use type assertion for specific error types
* const error = new TypeError();
* assertIsError(error);
* const typeError = error as TypeError;
*
* // For custom errors, use type assertion after the check
* class MyError extends Error {}
* const myError = new MyError();
* assertIsError(myError);
* const typedError = myError as MyError;
* ```
*
* /**
*
* @category Type Assertion
* @example
*
* ```typescript
* // does not throw, value is typed as Error
* assertIsError(new Error());
*
* // does not throw, value is typed as Error
* // Use type assertion for specific error types
* const error = new TypeError();
* assertIsError(error);
* const typeError = error as TypeError;
*
* // For custom errors, use type assertion after the check
* class MyError extends Error {}
* const myError = new MyError();
* assertIsError(myError);
* const typedError = myError as MyError;
* ```
*
* @throws {TypeError} Will throw an error if the input is not an Error object
*/
export declare function assertIsError(input: unknown, options?: ErrorMessage): asserts input is Error;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsFinite(input: unknown, options?: ErrorMessage): asserts input is number;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsFloat32Array(input: unknown, options?: ErrorMessage): asserts input is Float32Array;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsFloat64Array(input: unknown, options?: ErrorMessage): asserts input is Float64Array;
/**
* @remarks
* This guard works only in ES2018 and above
* @category Type Assertion
* @example
*
* ```typescript
* // does not throw, value is typed as (...args: unknown[]) => unknown
* assertIsFunction(() => true);
*
* // Use type assertion for specific function types
* const myFunc = (x: number): string => x.toString();
* assertIsFunction(myFunc);
* const typedFunc = myFunc as (x: number) => string;
*
* // throws - use isAsyncFunction for async functions
* assertIsFunction(async () => Promise.resolve(null));
*
* // throws - use isGeneratorFunction for generator functions
* assertIsFunction(function* () {});
*
* // throws - use isAsyncGeneratorFunction for async generator functions
* assertIsFunction(async function* () {});
*
* // throws - use isConstructor for class constructors
* assertIsFunction(MyClass);
* ```
*
* @throws {TypeError} Will throw an error if the input is not a function
*/
export declare function assertIsFunction(input: unknown, options?: ErrorMessage): asserts input is (...args: unknown[]) => unknown;
/**
* @remarks
* This assertion works only in ES2018 and above
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsGenerator<Y = unknown, R = unknown, N = unknown>(input: unknown, options?: ErrorMessage): asserts input is Generator<Y, R, N>;
/**
* @remarks
* This assertion works only in ES2018 and above
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsGeneratorFunction<Y = unknown, R = unknown, N = unknown>(input: unknown, options?: ErrorMessage): asserts input is TypedGeneratorFunction<Y, R, N>;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsInt16Array(input: unknown, options?: ErrorMessage): asserts input is Int16Array;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsInt32Array(input: unknown, options?: ErrorMessage): asserts input is Int32Array;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsInt8Array(input: unknown, options?: ErrorMessage): asserts input is Int8Array;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsInteger(input: unknown, options?: ErrorMessage): asserts input is number;
/**
* @remarks
* This guard tests for Symbol.iterator, which defines the Iterable protocol.
* See:
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols}
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsIterable<T = unknown>(input: unknown, options?: ErrorMessage): asserts input is Iterable<T>;
/**
* @remarks
* This assertion works only in ES2018 and above
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsIterator<Y = unknown, R = unknown, N = unknown>(input: unknown, options?: ErrorMessage): asserts input is Iterator<Y, R, N>;
/**
* @category Type Assertion
* @example
*
* ```typescript
* // does not throw, value is typed as Map<unknown, unknown>
* assertIsMap(new Map([['xyz', 'abc']]));
*
* // does not throw, value is typed as Map<string, string | number>
* assertIsMap<string, string>(
* new Map([
* ['abc', 'def'],
* ['xyz', 100],
* ]),
* {
* keyValidator: isString,
* valueValidator: isUnion(isString, isNumber),
* },
* );
* ```
*
* @throws TypeError
*/
export declare function assertIsMap(input: unknown, options?: ErrorMessage): asserts input is Map<unknown, unknown>;
export declare function assertIsMap<K>(input: unknown, options: (ErrorMessage & KeyValidator) | KeyValidator): asserts input is Map<K, unknown>;
export declare function assertIsMap<V>(input: unknown, options: (ErrorMessage & ValueValidator) | ValueValidator): asserts input is Map<string, V>;
export declare function assertIsMap<K, V>(input: unknown, options: (ErrorMessage & KeyValidator & ValueValidator) | (KeyValidator & ValueValidator)): asserts input is Map<K, V>;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsMapIterator(input: unknown, options?: ErrorMessage): asserts input is IterableIterator<[unknown, unknown]>;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsNaN(input: unknown, options?: ErrorMessage): asserts input is number;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsNativeError(input: unknown, options?: ErrorMessage): asserts input is Error;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsNonEmptyArray(input: unknown, options?: ErrorMessage): asserts input is [unknown, ...unknown[]];
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsNonEmptyString(input: unknown, options?: ErrorMessage): asserts input is string;
/**
* @remarks
* This assertion asserts that the value is not null, use assertIsNotNullish to
* also exclude undefined
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsNotNull<T>(input: null | T, options?: ErrorMessage): asserts input is T;
/**
* @remarks
* Tests false for undefined and null, true for all other values
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsNotNullish<T>(input: null | T | undefined, options?: ErrorMessage): asserts input is T;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsNull(input: unknown, options?: ErrorMessage): asserts input is null;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsNullish(input: unknown, options?: ErrorMessage): asserts input is null | undefined;
/**
* @category Type Assertion
* @example
*
* ```typescript
* // does not throw
* assertIsNumber(1);
*
* // throws
* assertIsNumber(new Number(1));
* ```
*
* @throws TypeError
*/
export declare function assertIsNumber(input: unknown, options?: ErrorMessage): asserts input is number;
/**
* @category Type Assertion
* @example
*
* ```typescript
* // does not throw
* assertIsNumberObject(new Number(1));
*
* // throws
* assertIsNumberObject(1);
* ```
*
* @throws TypeError
*/
export declare function assertIsNumberObject(input: unknown, options?: ErrorMessage): asserts input is number;
/**
* @remarks
* Tests true for all objects that have a typeof 'object' excluding null
* @category Type Assertion
* @example
*
* ```typescript
* // does not throw, value is typed as object
* assertIsObject({});
*
* // does not throw, value is typed as object
* assertIsObject([]);
*
* // throws
* assertIsObject(null);
* ```
*
* @throws TypeError
*/
export declare function assertIsObject(input: unknown, options?: ErrorMessage): asserts input is object;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsPlainObject(input: unknown, options?: ErrorMessage): asserts input is Record<string, unknown>;
/**
* @remarks
* Works with custom promises as well, e.g. AxiosPromise or BlueBird
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsPromise<T = unknown>(input: unknown, options?: ErrorMessage): asserts input is Promise<T>;
/**
* @category Type Assertion
* @example
*
* ```typescript
* // does not throw, value is typed as Record<string | symbol, unknown>
* assertIsRecord({ key1: 'aaa', key2: 123 });
*
* // does not throw, value is typed as Record<string, string | number>
* assertIsRecord<string, string | number>(
* { key1: 'aaa', key2: 123 },
* {
* keyValidator: isString,
* valueValidator: isUnion(isString, isNumber),
* },
* );
* ```
*
* @throws TypeError
*/
export declare function assertIsRecord(input: unknown, options?: ErrorMessage): asserts input is Record<string | symbol, unknown>;
export declare function assertIsRecord<K extends string | symbol>(input: unknown, options: (ErrorMessage & KeyValidator) | KeyValidator): asserts input is Record<K, unknown>;
export declare function assertIsRecord<V>(input: unknown, options: (ErrorMessage & ValueValidator) | ValueValidator): asserts input is Record<string, V>;
export declare function assertIsRecord<K extends string | symbol, V>(input: unknown, options: (ErrorMessage & KeyValidator & ValueValidator) | (KeyValidator & ValueValidator)): asserts input is Record<K, V>;
/**
* @category Type Assertion
* @example
*
* ```typescript
* // does not throw
* assertIsRegExp(new RegExp('abc'));
*
* // does not throw
* assertIsRegExp(/'abc'/);
* ```
*
* @throws TypeError
*/
export declare function assertIsRegExp(input: unknown, options?: ErrorMessage): asserts input is RegExp;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsSafeInteger(input: unknown, options?: ErrorMessage): asserts input is number;
/**
* @category Type Assertion
* @example
*
* ```typescript
* // doesn't throw, value is typed as Set<unknown>
* assertIsSet(new Set(['xyz']));
*
* // doesn't throw, value is typed as Set<string>
* assertIsSet<string>(new Set(['xyz']), { valueValidator: isString });
* ```
*
* @throws TypeError
*/
export declare function assertIsSet(input: unknown, options?: ErrorMessage): asserts input is Set<unknown>;
export declare function assertIsSet<T>(input: unknown, options: (ErrorMessage & ValueValidator) | ValueValidator): asserts input is Set<T>;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsSetIterator(input: unknown, options?: ErrorMessage): asserts input is IterableIterator<unknown>;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsSharedArrayBuffer(input: unknown, options?: ErrorMessage): asserts input is SharedArrayBuffer;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsString(input: unknown, options?: ErrorMessage): asserts input is string;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsStringObject(input: unknown, options?: ErrorMessage): asserts input is string;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsSymbol(input: unknown, options?: ErrorMessage): asserts input is symbol;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsSymbolObject(input: unknown, options?: ErrorMessage): asserts input is symbol;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsTypedArray(input: unknown, options?: ErrorMessage): asserts input is TypedArray;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsUint16Array(input: unknown, options?: ErrorMessage): asserts input is Uint16Array;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsUint32Array(input: unknown, options?: ErrorMessage): asserts input is Uint32Array;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsUint8Array(input: unknown, options?: ErrorMessage): asserts input is Uint8Array;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsUint8ClampedArray(input: unknown, options?: ErrorMessage): asserts input is Uint8ClampedArray;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsUndefined(input: unknown, options?: ErrorMessage): asserts input is undefined;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsWeakMap<K extends object, V = unknown>(input: unknown, options?: ErrorMessage): asserts input is WeakMap<K, V>;
/**
* @category Type Assertion
* @throws TypeError
*/
export declare function assertIsWeakSet<T extends object>(input: unknown, options?: ErrorMessage): asserts input is WeakSet<T>;
export declare type AsyncFunction<T = unknown> = (...args: unknown[]) => Promise<T>;
/**
* @category Utility
* @example
*
* ```typescript
* // myTypeGuard === (input: unknown, { throwError: boolean }) => input is MyClass
* const myTypeGuard = createTypeGuard<MyClass>(
* (value) => isObject(value) && Reflect.get(value, 'myProp'),
* MyClass.name,
* );
* ```
*/
export declare function createTypeGuard<T, O extends TypeGuardOptions | undefined = undefined>(validator: TypeValidator, options?: O): TypeGuard<T, O>;
export declare interface ErrorMessage {
message: string | undefined;
}
/** @category Type Guard */
export declare const isAnyArrayBuffer: TypeGuard<ArrayBuffer | SharedArrayBuffer>;
/** @category Type Guard */
export declare const isArgumentsObject: TypeGuard<IArguments, undefined>;
/**
* @category Type Guard
* @example
*
* ```typescript
* // true, typed as unknown[]
* isArray(['xyz']);
*
* // true, typed as string[]
* isArray<string>(['xyz'], { valueValidator: isString });
* ```
*/
export declare function isArray(input: unknown): input is unknown[];
export declare function isArray<T>(input: unknown, options: ValueValidator): input is T[];
/** @category Type Guard */
export declare const isArrayBuffer: TypeGuard<ArrayBuffer, undefined>;
/** @category Type Guard */
export declare const isArrayBufferView: TypeGuard<ArrayBufferView<ArrayBufferLike>, undefined>;
/**
* @remarks
* This guard works only in ES2018 and above
* @category Type Guard
*/
export declare function isAsyncFunction<T = unknown>(input: unknown): input is AsyncFunction<T>;
/**
* @remarks
* This guard works only in ES2018 and above
* @category Type Guard
*/
export declare function isAsyncGenerator<Y = unknown, R = unknown, N = unknown>(input: unknown): input is AsyncGenerator<Y, R, N>;
/**
* @remarks
* This guard works only in ES2018 and above
* @category Type Guard
*/
export declare function isAsyncGeneratorFunction<Y = unknown, R = unknown, N = unknown>(input: unknown): input is TypedAsyncGeneratorFunction<Y, R, N>;
/**
* @remarks
* This guard tests for Symbol.asyncIterator. See:
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator}
* @category Type Guard
*/
export declare function isAsyncIterable<T = unknown>(input: unknown): input is AsyncIterable<T>;
/**
* @category Type Guard
* @example
*
* ```typescript
* // true
* isBigInt(BigInt(9007199254740991));
*
* // true
* isBigInt(9007199254740991n);
* ```
*/
export declare const isBigInt: TypeGuard<bigint, undefined>;
/** @category Type Guard */
export declare const isBigInt64Array: (input: unknown) => input is BigInt64Array;
/** @category Type Guard */
export declare const isBigIntObject: TypeGuard<bigint, undefined>;
/** @category Type Guard */
export declare const isBigUint64Array: (input: unknown) => input is BigUint64Array;
/**
* @category Type Guard
* @example
*
* ```typescript
* // true
* isBoolean(false);
*
* // false
* isBoolean(new Boolean(false));
* ```
*/
export declare const isBoolean: TypeGuard<boolean, undefined>;
/**
* @category Type Guard
* @example
*
* ```typescript
* // true
* isBooleanObject(new Boolean(true));
*
* // false
* isBooleanObject(true);
* ```
*/
export declare const isBooleanObject: TypeGuard<boolean, undefined>;
/** @category Type Guard */
export declare const isBoxedPrimitive: TypeGuard<string | number | bigint | boolean | symbol, undefined>;
/** @category Type Guard */
export declare const isBuffer: TypeGuard<Buffer<ArrayBufferLike>, undefined>;
/** @category Type Guard */
export declare const isDataView: TypeGuard<DataView<ArrayBufferLike>, undefined>;
/** @category Type Guard */
export declare const isDate: TypeGuard<Date, undefined>;
/** @category Type Guard */
export declare function isDefined<T>(input: T | undefined): input is T;
/** @category Type Guard */
export declare const isEmptyArray: TypeGuard<[], undefined>;
/** @category Type Guard */
export declare const isEmptyObject: TypeGuard<Record<string, never>, undefined>;
/** @category Type Guard */
export declare const isEmptyString: TypeGuard<"", undefined>;
/**
* @category Type Guard
* @example
*
* ```typescript
* // true
* isError(new Error());
*
* // true, value is typed as Error
* isError(new TypeError());
*
* // true, value is still typed as Error (use type assertion if needed)
* const error = new TypeError();
* if (isError(error)) {
* // error is now typed as Error
* }
*
* // For custom errors, you can use type assertion
* class MyCustomError extends Error {}
* const customError = new MyCustomError();
* if (isError(customError)) {
* // customError is typed as Error
* const myError = customError as MyCustomError;
* }
* ```
*/
export declare function isError(input: unknown): input is Error;
/** @category Type Guard */
declare const isFinite_2: TypeGuard<number, undefined>;
export { isFinite_2 as isFinite }
/** @category Type Guard */
export declare const isFloat32Array: (input: unknown) => input is Float32Array;
/** @category Type Guard */
export declare const isFloat64Array: (input: unknown) => input is Float64Array;
/**
* @remarks
* This guard works only in ES2018 and above
* @category Type Guard
* @example
*
* ```typescript
* // true, value is typed as (...args: unknown[]) => unknown
* isFunction(() => null);
*
* // false - use isAsyncFunction for async functions
* isFunction(async () => Promise.resolve(null));
*
* // false - use isGeneratorFunction for generator functions
* isFunction(function* () {});
*
* // false - use isAsyncGeneratorFunction for async generator functions
* isFunction(async function* () {});
*
* // false - use isConstructor for class constructors
* isFunction(MyClass);
*
* // Type assertion can be used for specific function types
* const specificFn = (x: number): string => x.toString();
* if (isFunction(specificFn)) {
* // specificFn is now typed as (...args: unknown[]) => unknown
* // Use type assertion if needed: (specificFn as (x: number) => string)(42);
* }
* ```
*/
export declare function isFunction(input: unknown): input is (...args: unknown[]) => unknown;
/** @category Type Guard */
export declare function isGenerator<Y = unknown, R = unknown, N = unknown>(input: unknown): input is Generator<Y, R, N>;
/** @category Type Guard */
export declare function isGeneratorFunction<Y = unknown, R = unknown, N = unknown>(input: unknown): input is TypedGeneratorFunction<Y, R, N>;
/** @category Type Guard */
export declare const isInt16Array: (input: unknown) => input is Int16Array;
/** @category Type Guard */
export declare const isInt32Array: (input: unknown) => input is Int32Array;
/** @category Type Guard */
export declare const isInt8Array: (input: unknown) => input is Int8Array;
/** @category Type Guard */
export declare const isInteger: TypeGuard<number, undefined>;
/**
* @remarks
* This guard tests for Symbol.iterator, which defines the Iterable protocol.
* See:
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols}
* @category Type Guard
*/
export declare function isIterable<T = unknown>(input: unknown): input is Iterable<T>;
/**
* @remarks
* This guard tests for the presence of a '.next' method on the object, which
* defines the Iteration protocol. See:
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols}.
*
* At present it is not possible to distinguish between Iterator and
* AsyncIterator using reflection.
* @category Type Guard
*/
export declare function isIterator<Y = unknown, R = unknown, N = unknown>(input: unknown): input is Iterator<Y, R, N>;
/**
* @category Type Guard
* @example
*
* ```typescript
* // true, value is typed as Map<unknown, unknown>
* isMap(new Map([['xyz', 'abc']]));
*
* // true, value is typed as Map<string, string | number>
* isMap<string, string>(
* new Map([
* ['abc', 'def'],
* ['xyz', 100],
* ]),
* {
* keyValidator: isString,
* valueValidator: isUnion(isString, isNumber),
* },
* );
* ```
*/
export declare function isMap(input: unknown): input is Map<unknown, unknown>;
export declare function isMap<K>(input: unknown, options: KeyValidator): input is Map<K, unknown>;
export declare function isMap<V>(input: unknown, options: ValueValidator): input is Map<unknown, V>;
export declare function isMap<K, V>(input: unknown, options: KeyValidator & ValueValidator): input is Map<K, V>;
/** @category Type Guard */
export declare const isMapIterator: TypeGuard<IterableIterator<[unknown, unknown]>, undefined>;
/** @category Type Guard */
declare const isNaN_2: TypeGuard<number, undefined>;
export { isNaN_2 as isNaN }
/** @category Type Guard */
export declare const isNativeError: TypeGuard<Error, undefined>;
/** @category Type Guard */
export declare const isNonEmptyArray: TypeGuard<[unknown, ...unknown[]], undefined>;
/** @category Type Guard */
export declare const isNonEmptyString: TypeGuard<string, undefined>;
/**
* @remarks
* This guard checks that the value is not null, use isNotNullish to also
* exclude undefined
* @category Type Guard
*/
export declare function isNotNull<T>(input: null | T): input is T;
/**
* @remarks
* Tests false for undefined and null, true for all other values
* @category Type Guard
*/
export declare function isNotNullish<T>(input: null | T | undefined): input is NonNullable<T>;
/** @category Type Guard */
export declare const isNull: TypeGuard<null, undefined>;
/**
* @remarks
* Tests true for undefined and null, false for all other falsy values
* @category Type Guard
*/
export declare const isNullish: TypeGuard<null | undefined>;
/**
* @category Type Guard
* @example
*
* ```typescript
* // true
* isNumber(1);
*
* // false
* isNumber(new Number(1));
*
* // false
* isNumber(new BigInt(9007199254740991n));
* ```
*/
export declare const isNumber: TypeGuard<number, undefined>;
/**
* @category Type Guard
* @example
*
* ```typescript
* // true
* isNumberObject(new Number(1));
*
* // false
* isNumberObject(1);
* ```
*/
export declare const isNumberObject: TypeGuard<number, undefined>;
/**
* @remarks
* Tests true for all objects that have a typeof 'object' excluding null
* @category Type Guard
* @example
*
* ```typescript
* // true
* isObject({});
*
* // true
* isObject([]);
*
* // false
* isObject(null);
* ```
*/
export declare const isObject: TypeGuard<object, undefined>;
/**
* Checks if the value is a plain object (not a class instance)
*
* @category Type Guard
* @example
*
* ```typescript
* // true
* isPlainObject({});
* isPlainObject({ a: 1 });
* isPlainObject(Object.create(null));
* isPlainObject(Object.create(Object.prototype));
*
* // false
* isPlainObject(new Date());
* isPlainObject([]);
* isPlainObject(null);
* isPlainObject(undefined);
* ```
*/
export declare const isPlainObject: TypeGuard<Record<string, unknown>, undefined>;
/**
* @remarks
* Works with custom promises as well, e.g. AxiosPromise or Bluebird
* @category Type Guard
*/
export declare function isPromise<T = unknown>(input: unknown): input is Promise<T>;
/**
* @category Type Guard
* @example
*
* ```typescript
* * // true, value is typed as Record<string | symbol, unknown>
* isRecord(
* { key1: 'aaa', key2: 123 },
* );
*
* // true, value is typed as Record<string, string | number>
* isRecord<string, string | number>(
* { key1: 'aaa', key2: 123 },
* {
* keyValidator: isString,
* valueValidator: isUnion(isString, isNumber),
* },
* );
* ```
*/
export declare function isRecord(input: unknown): input is Record<string | symbol, unknown>;
export declare function isRecord<K extends string | symbol>(input: unknown, options: KeyValidator): input is Record<K, unknown>;
export declare function isRecord<V>(input: unknown, options: ValueValidator): input is Record<string, V>;
export declare function isRecord<K extends string | symbol, V>(input: unknown, options: KeyValidator & ValueValidator): input is Record<K, V>;
/**
* @category Type Guard
* @example
*
* ```typescript
* // true
* isRegExp(new RegExp('somePattern'));
*
* // true
* isRegExp(/somePattern/);
* ```
*/
export declare const isRegExp: TypeGuard<RegExp, undefined>;
/** @category Type Guard */
export declare const isSafeInteger: TypeGuard<number, undefined>;
/**
* ```typescript
* // true, value is typed as Set<unknown>
* isSet(new Set(['xyz']));
*
* // true, value is typed as Set<string>
* isSet<string>(new Set(['xyz']), { valueValidator: isString });
* ```
*
* /**
*
* @category Type Guard
* @example
*
* ```typescript
* // true, value is typed as Set<unknown>
* isSet(new Set(['xyz']));
*
* // true, value is typed as Set<string>
* isSet<string>(new Set(['xyz']), { valueValidator: isString });
* ```
*/
export declare function isSet(input: unknown): input is Set<unknown>;
export declare function isSet<T>(input: unknown, options: ValueValidator): input is Set<T>;
/** @category Type Guard */
export declare const isSetIterator: TypeGuard<IterableIterator<unknown>, undefined>;
/** @category Type Guard */
export declare const isSharedArrayBuffer: TypeGuard<SharedArrayBuffer, undefined>;
/**
* ```typescript
* // true
* isString('xyz');
*
* // false
* isString(new String('xyz'));
* ```
*
* /**
*
* @category Type Guard
* @example
*
* ```typescript
* // true
* isString('xyz');
*
* // false
* isString(new String('xyz'));
* ```
*/
export declare const isString: TypeGuard<string, undefined>;
/**
* @category Type Guard
* @example
*
* ```typescript
* // true
* isStringObject(new String('xyz'));
*
* // false
* isStringObject('xyz');
* ```
*/
export declare const isStringObject: TypeGuard<string, undefined>;
/** @category Type Guard */
export declare const isSymbol: TypeGuard<symbol, undefined>;
/** @category Type Guard */
export declare const isSymbolObject: TypeGuard<symbol, undefined>;
/** @category Type Guard */
export declare const isTypedArray: TypeGuard<TypedArray, undefined>;
/** @category Type Guard */
export declare const isUint16Array: (input: unknown) => input is Uint16Array;
/** @category Type Guard */
export declare const isUint32Array: (input: unknown) => input is Uint32Array;
/** @category Type Guard */
export declare const isUint8Array: (input: unknown) => input is Uint8Array;
/** @category Type Guard */
export declare const isUint8ClampedArray: (input: unknown) => input is Uint8ClampedArray;
/** @category Type Guard */
export declare const isUndefined: TypeGuard<undefined, undefined>;
/**
* @category Utility
* @example
*
* ```typescript
* // unionTypeGuard === <T>(input: unknown, ...args: unknown[]) => input is T
* const unionTypeGuard = isUnion<string | number | symbol>(
* isString,
* isNumber,
* isSymbol,
* );
* ```
*/
export declare function isUnion<T>(...guards: TypeGuard<T>[]): TypeGuard<T>;
/** @category Type Guard */
export declare function isWeakMap<K extends object, V = unknown>(input: unknown): input is WeakMap<K, V>;
/** @category Type Guard */
export declare function isWeakSet<T extends object>(input: unknown): input is WeakSet<T>;
export declare interface KeyValidator {
keyValidator: TypeValidator;
}
export declare type TypeAssertion<T, O extends TypeAssertionOptions | undefined = undefined> = (input: unknown, options?: O) => asserts input is T;
export declare type TypeAssertionOptions = Partial<ErrorMessage> & TypeGuardOptions;
export declare type TypedArray = BigInt64Array | BigUint64Array | Float32Array | Float64Array | Int16Array | Int32Array | Int8Array | Uint16Array | Uint32Array | Uint8Array | Uint8ClampedArray;
export declare type TypedAsyncGeneratorFunction<Y, R, N> = (...args: unknown[]) => AsyncGenerator<Y, R, N>;
export declare type TypedGeneratorFunction<Y, R, N> = (...args: unknown[]) => Generator<Y, R, N>;
export declare type TypeGuard<T, O extends TypeGuardOptions | undefined = undefined> = (input: unknown, options?: O) => input is T;
export declare type TypeGuardOptions = Partial<KeyValidator & ValueValidator>;
export declare type TypeValidator = (input: unknown, ...args: unknown[]) => boolean;
export declare interface ValueValidator {
valueValidator: TypeValidator;
}
export { }