fix
This commit is contained in:
387
book/node_modules/@sindresorhus/is/distribution/index.d.ts
generated
vendored
Normal file
387
book/node_modules/@sindresorhus/is/distribution/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,387 @@
|
||||
import type { ArrayLike, Class, Falsy, NodeStream, NonEmptyString, ObservableLike, Predicate, Primitive, TypedArray, WeakRef, Whitespace } from './types.js';
|
||||
type ExtractFromGlobalConstructors<Name extends string> = Name extends string ? typeof globalThis extends Record<Name, new (...arguments_: any[]) => infer T> ? T : never : never;
|
||||
type NodeBuffer = ExtractFromGlobalConstructors<'Buffer'>;
|
||||
declare const objectTypeNames: readonly ["Function", "Generator", "AsyncGenerator", "GeneratorFunction", "AsyncGeneratorFunction", "AsyncFunction", "Observable", "Array", "Buffer", "Blob", "Object", "RegExp", "Date", "Error", "Map", "Set", "WeakMap", "WeakSet", "WeakRef", "ArrayBuffer", "SharedArrayBuffer", "DataView", "Promise", "URL", "FormData", "URLSearchParams", "HTMLElement", "NaN", "Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "BigInt64Array", "BigUint64Array"];
|
||||
type ObjectTypeName = typeof objectTypeNames[number];
|
||||
declare const primitiveTypeNames: readonly ["null", "undefined", "string", "number", "bigint", "boolean", "symbol"];
|
||||
type PrimitiveTypeName = typeof primitiveTypeNames[number];
|
||||
export type TypeName = ObjectTypeName | PrimitiveTypeName;
|
||||
declare const assertionTypeDescriptions: readonly ["positive number", "negative number", "Class", "string with a number", "null or undefined", "Iterable", "AsyncIterable", "native Promise", "EnumCase", "string with a URL", "truthy", "falsy", "primitive", "integer", "plain object", "TypedArray", "array-like", "tuple-like", "Node.js Stream", "infinite number", "empty array", "non-empty array", "empty string", "empty string or whitespace", "non-empty string", "non-empty string and not whitespace", "empty object", "non-empty object", "empty set", "non-empty set", "empty map", "non-empty map", "PropertyKey", "even integer", "odd integer", "T", "in range", "predicate returns truthy for any value", "predicate returns truthy for all values", "valid Date", "valid length", "whitespace string", "Function", "Generator", "AsyncGenerator", "GeneratorFunction", "AsyncGeneratorFunction", "AsyncFunction", "Observable", "Array", "Buffer", "Blob", "Object", "RegExp", "Date", "Error", "Map", "Set", "WeakMap", "WeakSet", "WeakRef", "ArrayBuffer", "SharedArrayBuffer", "DataView", "Promise", "URL", "FormData", "URLSearchParams", "HTMLElement", "NaN", "Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "BigInt64Array", "BigUint64Array", "null", "undefined", "string", "number", "bigint", "boolean", "symbol"];
|
||||
export type AssertionTypeDescription = typeof assertionTypeDescriptions[number];
|
||||
declare function detect(value: unknown): TypeName;
|
||||
declare const is: typeof detect & {
|
||||
all: typeof isAll;
|
||||
any: typeof isAny;
|
||||
array: typeof isArray;
|
||||
arrayBuffer: typeof isArrayBuffer;
|
||||
arrayLike: typeof isArrayLike;
|
||||
asyncFunction: typeof isAsyncFunction;
|
||||
asyncGenerator: typeof isAsyncGenerator;
|
||||
asyncGeneratorFunction: typeof isAsyncGeneratorFunction;
|
||||
asyncIterable: typeof isAsyncIterable;
|
||||
bigint: typeof isBigint;
|
||||
bigInt64Array: typeof isBigInt64Array;
|
||||
bigUint64Array: typeof isBigUint64Array;
|
||||
blob: typeof isBlob;
|
||||
boolean: typeof isBoolean;
|
||||
boundFunction: typeof isBoundFunction;
|
||||
buffer: typeof isBuffer;
|
||||
class: typeof isClass;
|
||||
dataView: typeof isDataView;
|
||||
date: typeof isDate;
|
||||
detect: typeof detect;
|
||||
directInstanceOf: typeof isDirectInstanceOf;
|
||||
emptyArray: typeof isEmptyArray;
|
||||
emptyMap: typeof isEmptyMap;
|
||||
emptyObject: typeof isEmptyObject;
|
||||
emptySet: typeof isEmptySet;
|
||||
emptyString: typeof isEmptyString;
|
||||
emptyStringOrWhitespace: typeof isEmptyStringOrWhitespace;
|
||||
enumCase: typeof isEnumCase;
|
||||
error: typeof isError;
|
||||
evenInteger: typeof isEvenInteger;
|
||||
falsy: typeof isFalsy;
|
||||
float32Array: typeof isFloat32Array;
|
||||
float64Array: typeof isFloat64Array;
|
||||
formData: typeof isFormData;
|
||||
function: typeof isFunction;
|
||||
generator: typeof isGenerator;
|
||||
generatorFunction: typeof isGeneratorFunction;
|
||||
htmlElement: typeof isHtmlElement;
|
||||
infinite: typeof isInfinite;
|
||||
inRange: typeof isInRange;
|
||||
int16Array: typeof isInt16Array;
|
||||
int32Array: typeof isInt32Array;
|
||||
int8Array: typeof isInt8Array;
|
||||
integer: typeof isInteger;
|
||||
iterable: typeof isIterable;
|
||||
map: typeof isMap;
|
||||
nan: typeof isNan;
|
||||
nativePromise: typeof isNativePromise;
|
||||
negativeNumber: typeof isNegativeNumber;
|
||||
nodeStream: typeof isNodeStream;
|
||||
nonEmptyArray: typeof isNonEmptyArray;
|
||||
nonEmptyMap: typeof isNonEmptyMap;
|
||||
nonEmptyObject: typeof isNonEmptyObject;
|
||||
nonEmptySet: typeof isNonEmptySet;
|
||||
nonEmptyString: typeof isNonEmptyString;
|
||||
nonEmptyStringAndNotWhitespace: typeof isNonEmptyStringAndNotWhitespace;
|
||||
null: typeof isNull;
|
||||
nullOrUndefined: typeof isNullOrUndefined;
|
||||
number: typeof isNumber;
|
||||
numericString: typeof isNumericString;
|
||||
object: typeof isObject;
|
||||
observable: typeof isObservable;
|
||||
oddInteger: typeof isOddInteger;
|
||||
plainObject: typeof isPlainObject;
|
||||
positiveNumber: typeof isPositiveNumber;
|
||||
primitive: typeof isPrimitive;
|
||||
promise: typeof isPromise;
|
||||
propertyKey: typeof isPropertyKey;
|
||||
regExp: typeof isRegExp;
|
||||
safeInteger: typeof isSafeInteger;
|
||||
set: typeof isSet;
|
||||
sharedArrayBuffer: typeof isSharedArrayBuffer;
|
||||
string: typeof isString;
|
||||
symbol: typeof isSymbol;
|
||||
truthy: typeof isTruthy;
|
||||
tupleLike: typeof isTupleLike;
|
||||
typedArray: typeof isTypedArray;
|
||||
uint16Array: typeof isUint16Array;
|
||||
uint32Array: typeof isUint32Array;
|
||||
uint8Array: typeof isUint8Array;
|
||||
uint8ClampedArray: typeof isUint8ClampedArray;
|
||||
undefined: typeof isUndefined;
|
||||
urlInstance: typeof isUrlInstance;
|
||||
urlSearchParams: typeof isUrlSearchParams;
|
||||
urlString: typeof isUrlString;
|
||||
validDate: typeof isValidDate;
|
||||
validLength: typeof isValidLength;
|
||||
weakMap: typeof isWeakMap;
|
||||
weakRef: typeof isWeakRef;
|
||||
weakSet: typeof isWeakSet;
|
||||
whitespaceString: typeof isWhitespaceString;
|
||||
};
|
||||
export declare function isAll(predicate: Predicate, ...values: unknown[]): boolean;
|
||||
export declare function isAny(predicate: Predicate | Predicate[], ...values: unknown[]): boolean;
|
||||
export declare function isArray<T = unknown>(value: unknown, assertion?: (value: T) => value is T): value is T[];
|
||||
export declare function isArrayBuffer(value: unknown): value is ArrayBuffer;
|
||||
export declare function isArrayLike<T = unknown>(value: unknown): value is ArrayLike<T>;
|
||||
export declare function isAsyncFunction<T = unknown>(value: unknown): value is ((...arguments_: any[]) => Promise<T>);
|
||||
export declare function isAsyncGenerator(value: unknown): value is AsyncGenerator;
|
||||
export declare function isAsyncGeneratorFunction(value: unknown): value is ((...arguments_: any[]) => Promise<unknown>);
|
||||
export declare function isAsyncIterable<T = unknown>(value: unknown): value is AsyncIterable<T>;
|
||||
export declare function isBigint(value: unknown): value is bigint;
|
||||
export declare function isBigInt64Array(value: unknown): value is BigInt64Array;
|
||||
export declare function isBigUint64Array(value: unknown): value is BigUint64Array;
|
||||
export declare function isBlob(value: unknown): value is Blob;
|
||||
export declare function isBoolean(value: unknown): value is boolean;
|
||||
export declare function isBoundFunction(value: unknown): value is Function;
|
||||
/**
|
||||
Note: [Prefer using `Uint8Array` instead of `Buffer`.](https://sindresorhus.com/blog/goodbye-nodejs-buffer)
|
||||
*/
|
||||
export declare function isBuffer(value: unknown): value is NodeBuffer;
|
||||
export declare function isClass<T = unknown>(value: unknown): value is Class<T>;
|
||||
export declare function isDataView(value: unknown): value is DataView;
|
||||
export declare function isDate(value: unknown): value is Date;
|
||||
export declare function isDirectInstanceOf<T>(instance: unknown, class_: Class<T>): instance is T;
|
||||
export declare function isEmptyArray(value: unknown): value is never[];
|
||||
export declare function isEmptyMap(value: unknown): value is Map<never, never>;
|
||||
export declare function isEmptyObject<Key extends keyof any = string>(value: unknown): value is Record<Key, never>;
|
||||
export declare function isEmptySet(value: unknown): value is Set<never>;
|
||||
export declare function isEmptyString(value: unknown): value is '';
|
||||
export declare function isEmptyStringOrWhitespace(value: unknown): value is '' | Whitespace;
|
||||
export declare function isEnumCase<T = unknown>(value: unknown, targetEnum: T): value is T[keyof T];
|
||||
export declare function isError(value: unknown): value is Error;
|
||||
export declare function isEvenInteger(value: unknown): value is number;
|
||||
export declare function isFalsy(value: unknown): value is Falsy;
|
||||
export declare function isFloat32Array(value: unknown): value is Float32Array;
|
||||
export declare function isFloat64Array(value: unknown): value is Float64Array;
|
||||
export declare function isFormData(value: unknown): value is FormData;
|
||||
export declare function isFunction(value: unknown): value is Function;
|
||||
export declare function isGenerator(value: unknown): value is Generator;
|
||||
export declare function isGeneratorFunction(value: unknown): value is GeneratorFunction;
|
||||
export declare function isHtmlElement(value: unknown): value is HTMLElement;
|
||||
export declare function isInfinite(value: unknown): value is number;
|
||||
export declare function isInRange(value: number, range: number | [number, number]): value is number;
|
||||
export declare function isInt16Array(value: unknown): value is Int16Array;
|
||||
export declare function isInt32Array(value: unknown): value is Int32Array;
|
||||
export declare function isInt8Array(value: unknown): value is Int8Array;
|
||||
export declare function isInteger(value: unknown): value is number;
|
||||
export declare function isIterable<T = unknown>(value: unknown): value is Iterable<T>;
|
||||
export declare function isMap<Key = unknown, Value = unknown>(value: unknown): value is Map<Key, Value>;
|
||||
export declare function isNan(value: unknown): boolean;
|
||||
export declare function isNativePromise<T = unknown>(value: unknown): value is Promise<T>;
|
||||
export declare function isNegativeNumber(value: unknown): value is number;
|
||||
export declare function isNodeStream(value: unknown): value is NodeStream;
|
||||
export declare function isNonEmptyArray<T = unknown, Item = unknown>(value: T | Item[]): value is [Item, ...Item[]];
|
||||
export declare function isNonEmptyMap<Key = unknown, Value = unknown>(value: unknown): value is Map<Key, Value>;
|
||||
export declare function isNonEmptyObject<Key extends keyof any = string, Value = unknown>(value: unknown): value is Record<Key, Value>;
|
||||
export declare function isNonEmptySet<T = unknown>(value: unknown): value is Set<T>;
|
||||
export declare function isNonEmptyString(value: unknown): value is NonEmptyString;
|
||||
export declare function isNonEmptyStringAndNotWhitespace(value: unknown): value is NonEmptyString;
|
||||
export declare function isNull(value: unknown): value is null;
|
||||
export declare function isNullOrUndefined(value: unknown): value is null | undefined;
|
||||
export declare function isNumber(value: unknown): value is number;
|
||||
export declare function isNumericString(value: unknown): value is `${number}`;
|
||||
export declare function isObject(value: unknown): value is object;
|
||||
export declare function isObservable(value: unknown): value is ObservableLike;
|
||||
export declare function isOddInteger(value: unknown): value is number;
|
||||
export declare function isPlainObject<Value = unknown>(value: unknown): value is Record<PropertyKey, Value>;
|
||||
export declare function isPositiveNumber(value: unknown): value is number;
|
||||
export declare function isPrimitive(value: unknown): value is Primitive;
|
||||
export declare function isPromise<T = unknown>(value: unknown): value is Promise<T>;
|
||||
export declare function isPropertyKey(value: unknown): value is PropertyKey;
|
||||
export declare function isRegExp(value: unknown): value is RegExp;
|
||||
export declare function isSafeInteger(value: unknown): value is number;
|
||||
export declare function isSet<T = unknown>(value: unknown): value is Set<T>;
|
||||
export declare function isSharedArrayBuffer(value: unknown): value is SharedArrayBuffer;
|
||||
export declare function isString(value: unknown): value is string;
|
||||
export declare function isSymbol(value: unknown): value is symbol;
|
||||
export declare function isTruthy<T>(value: T | Falsy): value is T;
|
||||
type TypeGuard<T> = (value: unknown) => value is T;
|
||||
type ResolveTypesOfTypeGuardsTuple<TypeGuardsOfT, ResultOfT extends unknown[] = []> = TypeGuardsOfT extends [TypeGuard<infer U>, ...infer TOthers] ? ResolveTypesOfTypeGuardsTuple<TOthers, [...ResultOfT, U]> : TypeGuardsOfT extends undefined[] ? ResultOfT : never;
|
||||
export declare function isTupleLike<T extends Array<TypeGuard<unknown>>>(value: unknown, guards: [...T]): value is ResolveTypesOfTypeGuardsTuple<T>;
|
||||
export declare function isTypedArray(value: unknown): value is TypedArray;
|
||||
export declare function isUint16Array(value: unknown): value is Uint16Array;
|
||||
export declare function isUint32Array(value: unknown): value is Uint32Array;
|
||||
export declare function isUint8Array(value: unknown): value is Uint8Array;
|
||||
export declare function isUint8ClampedArray(value: unknown): value is Uint8ClampedArray;
|
||||
export declare function isUndefined(value: unknown): value is undefined;
|
||||
export declare function isUrlInstance(value: unknown): value is URL;
|
||||
export declare function isUrlSearchParams(value: unknown): value is URLSearchParams;
|
||||
export declare function isUrlString(value: unknown): value is string;
|
||||
export declare function isValidDate(value: unknown): value is Date;
|
||||
export declare function isValidLength(value: unknown): value is number;
|
||||
export declare function isWeakMap<Key extends object = object, Value = unknown>(value: unknown): value is WeakMap<Key, Value>;
|
||||
export declare function isWeakRef(value: unknown): value is WeakRef<object>;
|
||||
export declare function isWeakSet(value: unknown): value is WeakSet<object>;
|
||||
export declare function isWhitespaceString(value: unknown): value is Whitespace;
|
||||
type Assert = {
|
||||
undefined: (value: unknown, message?: string) => asserts value is undefined;
|
||||
string: (value: unknown, message?: string) => asserts value is string;
|
||||
number: (value: unknown, message?: string) => asserts value is number;
|
||||
positiveNumber: (value: unknown, message?: string) => asserts value is number;
|
||||
negativeNumber: (value: unknown, message?: string) => asserts value is number;
|
||||
bigint: (value: unknown, message?: string) => asserts value is bigint;
|
||||
function: (value: unknown, message?: string) => asserts value is Function;
|
||||
null: (value: unknown, message?: string) => asserts value is null;
|
||||
class: <T = unknown>(value: unknown, message?: string) => asserts value is Class<T>;
|
||||
boolean: (value: unknown, message?: string) => asserts value is boolean;
|
||||
symbol: (value: unknown, message?: string) => asserts value is symbol;
|
||||
numericString: (value: unknown, message?: string) => asserts value is `${number}`;
|
||||
array: <T = unknown>(value: unknown, assertion?: (element: unknown) => asserts element is T, message?: string) => asserts value is T[];
|
||||
buffer: (value: unknown, message?: string) => asserts value is NodeBuffer;
|
||||
blob: (value: unknown, message?: string) => asserts value is Blob;
|
||||
nullOrUndefined: (value: unknown, message?: string) => asserts value is null | undefined;
|
||||
object: <Key extends keyof any = string, Value = unknown>(value: unknown, message?: string) => asserts value is Record<Key, Value>;
|
||||
iterable: <T = unknown>(value: unknown, message?: string) => asserts value is Iterable<T>;
|
||||
asyncIterable: <T = unknown>(value: unknown, message?: string) => asserts value is AsyncIterable<T>;
|
||||
generator: (value: unknown, message?: string) => asserts value is Generator;
|
||||
asyncGenerator: (value: unknown, message?: string) => asserts value is AsyncGenerator;
|
||||
nativePromise: <T = unknown>(value: unknown, message?: string) => asserts value is Promise<T>;
|
||||
promise: <T = unknown>(value: unknown, message?: string) => asserts value is Promise<T>;
|
||||
generatorFunction: (value: unknown, message?: string) => asserts value is GeneratorFunction;
|
||||
asyncGeneratorFunction: (value: unknown, message?: string) => asserts value is AsyncGeneratorFunction;
|
||||
asyncFunction: (value: unknown, message?: string) => asserts value is Function;
|
||||
boundFunction: (value: unknown, message?: string) => asserts value is Function;
|
||||
regExp: (value: unknown, message?: string) => asserts value is RegExp;
|
||||
date: (value: unknown, message?: string) => asserts value is Date;
|
||||
error: (value: unknown, message?: string) => asserts value is Error;
|
||||
map: <Key = unknown, Value = unknown>(value: unknown, message?: string) => asserts value is Map<Key, Value>;
|
||||
set: <T = unknown>(value: unknown, message?: string) => asserts value is Set<T>;
|
||||
weakMap: <Key extends object = object, Value = unknown>(value: unknown, message?: string) => asserts value is WeakMap<Key, Value>;
|
||||
weakSet: <T extends object = object>(value: unknown, message?: string) => asserts value is WeakSet<T>;
|
||||
weakRef: <T extends object = object>(value: unknown, message?: string) => asserts value is WeakRef<T>;
|
||||
int8Array: (value: unknown, message?: string) => asserts value is Int8Array;
|
||||
uint8Array: (value: unknown, message?: string) => asserts value is Uint8Array;
|
||||
uint8ClampedArray: (value: unknown, message?: string) => asserts value is Uint8ClampedArray;
|
||||
int16Array: (value: unknown, message?: string) => asserts value is Int16Array;
|
||||
uint16Array: (value: unknown, message?: string) => asserts value is Uint16Array;
|
||||
int32Array: (value: unknown, message?: string) => asserts value is Int32Array;
|
||||
uint32Array: (value: unknown, message?: string) => asserts value is Uint32Array;
|
||||
float32Array: (value: unknown, message?: string) => asserts value is Float32Array;
|
||||
float64Array: (value: unknown, message?: string) => asserts value is Float64Array;
|
||||
bigInt64Array: (value: unknown, message?: string) => asserts value is BigInt64Array;
|
||||
bigUint64Array: (value: unknown, message?: string) => asserts value is BigUint64Array;
|
||||
arrayBuffer: (value: unknown, message?: string) => asserts value is ArrayBuffer;
|
||||
sharedArrayBuffer: (value: unknown, message?: string) => asserts value is SharedArrayBuffer;
|
||||
dataView: (value: unknown, message?: string) => asserts value is DataView;
|
||||
enumCase: <T = unknown>(value: unknown, targetEnum: T, message?: string) => asserts value is T[keyof T];
|
||||
urlInstance: (value: unknown, message?: string) => asserts value is URL;
|
||||
urlString: (value: unknown, message?: string) => asserts value is string;
|
||||
truthy: <T>(value: T | Falsy, message?: string) => asserts value is T;
|
||||
falsy: (value: unknown, message?: string) => asserts value is Falsy;
|
||||
nan: (value: unknown, message?: string) => asserts value is number;
|
||||
primitive: (value: unknown, message?: string) => asserts value is Primitive;
|
||||
integer: (value: unknown, message?: string) => asserts value is number;
|
||||
safeInteger: (value: unknown, message?: string) => asserts value is number;
|
||||
plainObject: <Value = unknown>(value: unknown, message?: string) => asserts value is Record<PropertyKey, Value>;
|
||||
typedArray: (value: unknown, message?: string) => asserts value is TypedArray;
|
||||
arrayLike: <T = unknown>(value: unknown, message?: string) => asserts value is ArrayLike<T>;
|
||||
tupleLike: <T extends Array<TypeGuard<unknown>>>(value: unknown, guards: [...T], message?: string) => asserts value is ResolveTypesOfTypeGuardsTuple<T>;
|
||||
htmlElement: (value: unknown, message?: string) => asserts value is HTMLElement;
|
||||
observable: (value: unknown, message?: string) => asserts value is ObservableLike;
|
||||
nodeStream: (value: unknown, message?: string) => asserts value is NodeStream;
|
||||
infinite: (value: unknown, message?: string) => asserts value is number;
|
||||
emptyArray: (value: unknown, message?: string) => asserts value is never[];
|
||||
nonEmptyArray: <T = unknown, Item = unknown>(value: T | Item[], message?: string) => asserts value is [Item, ...Item[]];
|
||||
emptyString: (value: unknown, message?: string) => asserts value is '';
|
||||
emptyStringOrWhitespace: (value: unknown, message?: string) => asserts value is '' | Whitespace;
|
||||
nonEmptyString: (value: unknown, message?: string) => asserts value is string;
|
||||
nonEmptyStringAndNotWhitespace: (value: unknown, message?: string) => asserts value is string;
|
||||
emptyObject: <Key extends keyof any = string>(value: unknown, message?: string) => asserts value is Record<Key, never>;
|
||||
nonEmptyObject: <Key extends keyof any = string, Value = unknown>(value: unknown, message?: string) => asserts value is Record<Key, Value>;
|
||||
emptySet: (value: unknown, message?: string) => asserts value is Set<never>;
|
||||
nonEmptySet: <T = unknown>(value: unknown, message?: string) => asserts value is Set<T>;
|
||||
emptyMap: (value: unknown, message?: string) => asserts value is Map<never, never>;
|
||||
nonEmptyMap: <Key = unknown, Value = unknown>(value: unknown, message?: string) => asserts value is Map<Key, Value>;
|
||||
propertyKey: (value: unknown, message?: string) => asserts value is PropertyKey;
|
||||
formData: (value: unknown, message?: string) => asserts value is FormData;
|
||||
urlSearchParams: (value: unknown, message?: string) => asserts value is URLSearchParams;
|
||||
validDate: (value: unknown, message?: string) => asserts value is Date;
|
||||
validLength: (value: unknown, message?: string) => asserts value is number;
|
||||
whitespaceString: (value: unknown, message?: string) => asserts value is string;
|
||||
evenInteger: (value: number, message?: string) => asserts value is number;
|
||||
oddInteger: (value: number, message?: string) => asserts value is number;
|
||||
directInstanceOf: <T>(instance: unknown, class_: Class<T>, message?: string) => asserts instance is T;
|
||||
inRange: (value: number, range: number | [number, number], message?: string) => asserts value is number;
|
||||
any: (predicate: Predicate | Predicate[], ...values: unknown[]) => void | never;
|
||||
all: (predicate: Predicate, ...values: unknown[]) => void | never;
|
||||
};
|
||||
export declare const assert: Assert;
|
||||
export declare function assertAll(predicate: Predicate, ...values: unknown[]): void | never;
|
||||
export declare function assertAny(predicate: Predicate | Predicate[], ...values: unknown[]): void | never;
|
||||
export declare function assertArray<T = unknown>(value: unknown, assertion?: (element: unknown, message?: string) => asserts element is T, message?: string): asserts value is T[];
|
||||
export declare function assertArrayBuffer(value: unknown, message?: string): asserts value is ArrayBuffer;
|
||||
export declare function assertArrayLike<T = unknown>(value: unknown, message?: string): asserts value is ArrayLike<T>;
|
||||
export declare function assertAsyncFunction(value: unknown, message?: string): asserts value is Function;
|
||||
export declare function assertAsyncGenerator(value: unknown, message?: string): asserts value is AsyncGenerator;
|
||||
export declare function assertAsyncGeneratorFunction(value: unknown, message?: string): asserts value is AsyncGeneratorFunction;
|
||||
export declare function assertAsyncIterable<T = unknown>(value: unknown, message?: string): asserts value is AsyncIterable<T>;
|
||||
export declare function assertBigint(value: unknown, message?: string): asserts value is bigint;
|
||||
export declare function assertBigInt64Array(value: unknown, message?: string): asserts value is BigInt64Array;
|
||||
export declare function assertBigUint64Array(value: unknown, message?: string): asserts value is BigUint64Array;
|
||||
export declare function assertBlob(value: unknown, message?: string): asserts value is Blob;
|
||||
export declare function assertBoolean(value: unknown, message?: string): asserts value is boolean;
|
||||
export declare function assertBoundFunction(value: unknown, message?: string): asserts value is Function;
|
||||
/**
|
||||
Note: [Prefer using `Uint8Array` instead of `Buffer`.](https://sindresorhus.com/blog/goodbye-nodejs-buffer)
|
||||
*/
|
||||
export declare function assertBuffer(value: unknown, message?: string): asserts value is NodeBuffer;
|
||||
export declare function assertClass<T>(value: unknown, message?: string): asserts value is Class<T>;
|
||||
export declare function assertDataView(value: unknown, message?: string): asserts value is DataView;
|
||||
export declare function assertDate(value: unknown, message?: string): asserts value is Date;
|
||||
export declare function assertDirectInstanceOf<T>(instance: unknown, class_: Class<T>, message?: string): asserts instance is T;
|
||||
export declare function assertEmptyArray(value: unknown, message?: string): asserts value is never[];
|
||||
export declare function assertEmptyMap(value: unknown, message?: string): asserts value is Map<never, never>;
|
||||
export declare function assertEmptyObject<Key extends keyof any = string>(value: unknown, message?: string): asserts value is Record<Key, never>;
|
||||
export declare function assertEmptySet(value: unknown, message?: string): asserts value is Set<never>;
|
||||
export declare function assertEmptyString(value: unknown, message?: string): asserts value is '';
|
||||
export declare function assertEmptyStringOrWhitespace(value: unknown, message?: string): asserts value is '' | Whitespace;
|
||||
export declare function assertEnumCase<T = unknown>(value: unknown, targetEnum: T, message?: string): asserts value is T[keyof T];
|
||||
export declare function assertError(value: unknown, message?: string): asserts value is Error;
|
||||
export declare function assertEvenInteger(value: number, message?: string): asserts value is number;
|
||||
export declare function assertFalsy(value: unknown, message?: string): asserts value is Falsy;
|
||||
export declare function assertFloat32Array(value: unknown, message?: string): asserts value is Float32Array;
|
||||
export declare function assertFloat64Array(value: unknown, message?: string): asserts value is Float64Array;
|
||||
export declare function assertFormData(value: unknown, message?: string): asserts value is FormData;
|
||||
export declare function assertFunction(value: unknown, message?: string): asserts value is Function;
|
||||
export declare function assertGenerator(value: unknown, message?: string): asserts value is Generator;
|
||||
export declare function assertGeneratorFunction(value: unknown, message?: string): asserts value is GeneratorFunction;
|
||||
export declare function assertHtmlElement(value: unknown, message?: string): asserts value is HTMLElement;
|
||||
export declare function assertInfinite(value: unknown, message?: string): asserts value is number;
|
||||
export declare function assertInRange(value: number, range: number | [number, number], message?: string): asserts value is number;
|
||||
export declare function assertInt16Array(value: unknown, message?: string): asserts value is Int16Array;
|
||||
export declare function assertInt32Array(value: unknown, message?: string): asserts value is Int32Array;
|
||||
export declare function assertInt8Array(value: unknown, message?: string): asserts value is Int8Array;
|
||||
export declare function assertInteger(value: unknown, message?: string): asserts value is number;
|
||||
export declare function assertIterable<T = unknown>(value: unknown, message?: string): asserts value is Iterable<T>;
|
||||
export declare function assertMap<Key = unknown, Value = unknown>(value: unknown, message?: string): asserts value is Map<Key, Value>;
|
||||
export declare function assertNan(value: unknown, message?: string): asserts value is number;
|
||||
export declare function assertNativePromise<T = unknown>(value: unknown, message?: string): asserts value is Promise<T>;
|
||||
export declare function assertNegativeNumber(value: unknown, message?: string): asserts value is number;
|
||||
export declare function assertNodeStream(value: unknown, message?: string): asserts value is NodeStream;
|
||||
export declare function assertNonEmptyArray<T = unknown, Item = unknown>(value: T | Item[], message?: string): asserts value is [Item, ...Item[]];
|
||||
export declare function assertNonEmptyMap<Key = unknown, Value = unknown>(value: unknown, message?: string): asserts value is Map<Key, Value>;
|
||||
export declare function assertNonEmptyObject<Key extends keyof any = string, Value = unknown>(value: unknown, message?: string): asserts value is Record<Key, Value>;
|
||||
export declare function assertNonEmptySet<T = unknown>(value: unknown, message?: string): asserts value is Set<T>;
|
||||
export declare function assertNonEmptyString(value: unknown, message?: string): asserts value is string;
|
||||
export declare function assertNonEmptyStringAndNotWhitespace(value: unknown, message?: string): asserts value is string;
|
||||
export declare function assertNull(value: unknown, message?: string): asserts value is null;
|
||||
export declare function assertNullOrUndefined(value: unknown, message?: string): asserts value is null | undefined;
|
||||
export declare function assertNumber(value: unknown, message?: string): asserts value is number;
|
||||
export declare function assertNumericString(value: unknown, message?: string): asserts value is `${number}`;
|
||||
export declare function assertObject(value: unknown, message?: string): asserts value is object;
|
||||
export declare function assertObservable(value: unknown, message?: string): asserts value is ObservableLike;
|
||||
export declare function assertOddInteger(value: number, message?: string): asserts value is number;
|
||||
export declare function assertPlainObject<Value = unknown>(value: unknown, message?: string): asserts value is Record<PropertyKey, Value>;
|
||||
export declare function assertPositiveNumber(value: unknown, message?: string): asserts value is number;
|
||||
export declare function assertPrimitive(value: unknown, message?: string): asserts value is Primitive;
|
||||
export declare function assertPromise<T = unknown>(value: unknown, message?: string): asserts value is Promise<T>;
|
||||
export declare function assertPropertyKey(value: unknown, message?: string): asserts value is number;
|
||||
export declare function assertRegExp(value: unknown, message?: string): asserts value is RegExp;
|
||||
export declare function assertSafeInteger(value: unknown, message?: string): asserts value is number;
|
||||
export declare function assertSet<T = unknown>(value: unknown, message?: string): asserts value is Set<T>;
|
||||
export declare function assertSharedArrayBuffer(value: unknown, message?: string): asserts value is SharedArrayBuffer;
|
||||
export declare function assertString(value: unknown, message?: string): asserts value is string;
|
||||
export declare function assertSymbol(value: unknown, message?: string): asserts value is symbol;
|
||||
export declare function assertTruthy<T>(value: T | Falsy, message?: string): asserts value is T;
|
||||
export declare function assertTupleLike<T extends Array<TypeGuard<unknown>>>(value: unknown, guards: [...T], message?: string): asserts value is ResolveTypesOfTypeGuardsTuple<T>;
|
||||
export declare function assertTypedArray(value: unknown, message?: string): asserts value is TypedArray;
|
||||
export declare function assertUint16Array(value: unknown, message?: string): asserts value is Uint16Array;
|
||||
export declare function assertUint32Array(value: unknown, message?: string): asserts value is Uint32Array;
|
||||
export declare function assertUint8Array(value: unknown, message?: string): asserts value is Uint8Array;
|
||||
export declare function assertUint8ClampedArray(value: unknown, message?: string): asserts value is Uint8ClampedArray;
|
||||
export declare function assertUndefined(value: unknown, message?: string): asserts value is undefined;
|
||||
export declare function assertUrlInstance(value: unknown, message?: string): asserts value is URL;
|
||||
export declare function assertUrlSearchParams(value: unknown, message?: string): asserts value is URLSearchParams;
|
||||
export declare function assertUrlString(value: unknown, message?: string): asserts value is string;
|
||||
export declare function assertValidDate(value: unknown, message?: string): asserts value is Date;
|
||||
export declare function assertValidLength(value: unknown, message?: string): asserts value is number;
|
||||
export declare function assertWeakMap<Key extends object = object, Value = unknown>(value: unknown, message?: string): asserts value is WeakMap<Key, Value>;
|
||||
export declare function assertWeakRef<T extends object = object>(value: unknown, message?: string): asserts value is WeakRef<T>;
|
||||
export declare function assertWeakSet<T extends object = object>(value: unknown, message?: string): asserts value is WeakSet<T>;
|
||||
export declare function assertWhitespaceString(value: unknown, message?: string): asserts value is string;
|
||||
export default is;
|
||||
export type { ArrayLike, Class, NodeStream, ObservableLike, Predicate, Primitive, TypedArray, } from './types.js';
|
1300
book/node_modules/@sindresorhus/is/distribution/index.js
generated
vendored
Normal file
1300
book/node_modules/@sindresorhus/is/distribution/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
50
book/node_modules/@sindresorhus/is/distribution/types.d.ts
generated
vendored
Normal file
50
book/node_modules/@sindresorhus/is/distribution/types.d.ts
generated
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
/**
|
||||
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
||||
*/
|
||||
export type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
||||
/**
|
||||
Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
|
||||
*/
|
||||
type Constructor<T, Arguments extends unknown[] = any[]> = new (...arguments_: Arguments) => T;
|
||||
/**
|
||||
Matches a [`class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
|
||||
*/
|
||||
export type Class<T, Arguments extends unknown[] = any[]> = Constructor<T, Arguments> & {
|
||||
prototype: T;
|
||||
};
|
||||
/**
|
||||
Matches any [typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), like `Uint8Array` or `Float64Array`.
|
||||
*/
|
||||
export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
|
||||
declare global {
|
||||
interface SymbolConstructor {
|
||||
readonly observable: symbol;
|
||||
}
|
||||
}
|
||||
/**
|
||||
Matches a value that is like an [Observable](https://github.com/tc39/proposal-observable).
|
||||
*/
|
||||
export type ObservableLike = {
|
||||
subscribe(observer: (value: unknown) => void): void;
|
||||
[Symbol.observable](): ObservableLike;
|
||||
};
|
||||
export type Falsy = false | 0 | 0n | '' | null | undefined;
|
||||
export type WeakRef<T extends object> = {
|
||||
readonly [Symbol.toStringTag]: 'WeakRef';
|
||||
deref(): T | undefined;
|
||||
};
|
||||
export type ArrayLike<T> = {
|
||||
readonly [index: number]: T;
|
||||
readonly length: number;
|
||||
};
|
||||
export type NodeStream = {
|
||||
pipe<T extends NodeJS.WritableStream>(destination: T, options?: {
|
||||
end?: boolean;
|
||||
}): T;
|
||||
} & NodeJS.EventEmitter;
|
||||
export type Predicate = (value: unknown) => boolean;
|
||||
export type NonEmptyString = string & {
|
||||
0: string;
|
||||
};
|
||||
export type Whitespace = ' ';
|
||||
export {};
|
2
book/node_modules/@sindresorhus/is/distribution/types.js
generated
vendored
Normal file
2
book/node_modules/@sindresorhus/is/distribution/types.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
// Extracted from https://github.com/sindresorhus/type-fest/blob/78019f42ea888b0cdceb41a4a78163868de57555/index.d.ts
|
||||
export {};
|
9
book/node_modules/@sindresorhus/is/license
generated
vendored
Normal file
9
book/node_modules/@sindresorhus/is/license
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
81
book/node_modules/@sindresorhus/is/package.json
generated
vendored
Normal file
81
book/node_modules/@sindresorhus/is/package.json
generated
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
{
|
||||
"name": "@sindresorhus/is",
|
||||
"version": "7.0.1",
|
||||
"description": "Type check values",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/is",
|
||||
"funding": "https://github.com/sindresorhus/is?sponsor=1",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"types": "./distribution/index.d.ts",
|
||||
"default": "./distribution/index.js"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "del distribution && tsc",
|
||||
"test": "tsc --noEmit && xo && ava",
|
||||
"prepare": "npm run build"
|
||||
},
|
||||
"files": [
|
||||
"distribution"
|
||||
],
|
||||
"keywords": [
|
||||
"type",
|
||||
"types",
|
||||
"is",
|
||||
"check",
|
||||
"checking",
|
||||
"validate",
|
||||
"validation",
|
||||
"utility",
|
||||
"util",
|
||||
"typeof",
|
||||
"instanceof",
|
||||
"object",
|
||||
"assert",
|
||||
"assertion",
|
||||
"test",
|
||||
"kind",
|
||||
"primitive",
|
||||
"verify",
|
||||
"compare",
|
||||
"typescript",
|
||||
"typeguards",
|
||||
"types"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@sindresorhus/tsconfig": "^6.0.0",
|
||||
"@types/jsdom": "^21.1.7",
|
||||
"@types/node": "^20.14.10",
|
||||
"@types/zen-observable": "^0.8.7",
|
||||
"ava": "^6.1.3",
|
||||
"del-cli": "^5.1.0",
|
||||
"expect-type": "^0.19.0",
|
||||
"jsdom": "^24.1.0",
|
||||
"rxjs": "^7.8.1",
|
||||
"tempy": "^3.1.0",
|
||||
"tsimp": "^2.0.11",
|
||||
"typescript": "^5.5.3",
|
||||
"xo": "^0.58.0",
|
||||
"zen-observable": "^0.10.0"
|
||||
},
|
||||
"ava": {
|
||||
"environmentVariables": {
|
||||
"TSIMP_DIAG": "error"
|
||||
},
|
||||
"extensions": {
|
||||
"ts": "module"
|
||||
},
|
||||
"nodeArguments": [
|
||||
"--import=tsimp/import"
|
||||
]
|
||||
}
|
||||
}
|
765
book/node_modules/@sindresorhus/is/readme.md
generated
vendored
Normal file
765
book/node_modules/@sindresorhus/is/readme.md
generated
vendored
Normal file
@ -0,0 +1,765 @@
|
||||
# is
|
||||
|
||||
> Type check values
|
||||
|
||||
For example, `is.string('🦄') //=> true`
|
||||
|
||||
<img src="header.gif" width="182" align="right">
|
||||
|
||||
## Highlights
|
||||
|
||||
- Written in TypeScript
|
||||
- [Extensive use of type guards](#type-guards)
|
||||
- [Supports type assertions](#type-assertions)
|
||||
- [Aware of generic type parameters](#generic-type-parameters) (use with caution)
|
||||
- Actively maintained
|
||||
- 
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install @sindresorhus/is
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import is from '@sindresorhus/is';
|
||||
|
||||
is('🦄');
|
||||
//=> 'string'
|
||||
|
||||
is(new Map());
|
||||
//=> 'Map'
|
||||
|
||||
is.number(6);
|
||||
//=> true
|
||||
```
|
||||
|
||||
[Assertions](#type-assertions) perform the same type checks, but throw an error if the type does not match.
|
||||
|
||||
```js
|
||||
import {assert} from '@sindresorhus/is';
|
||||
|
||||
assert.string(2);
|
||||
//=> Error: Expected value which is `string`, received value of type `number`.
|
||||
```
|
||||
|
||||
Assertions (except `assertAll` and `assertAny`) also support an optional custom error message.
|
||||
|
||||
```js
|
||||
import {assert} from '@sindresorhus/is';
|
||||
|
||||
assert.nonEmptyString(process.env.API_URL, 'The API_URL environment variable is required.');
|
||||
//=> Error: The API_URL environment variable is required.
|
||||
```
|
||||
|
||||
And with TypeScript:
|
||||
|
||||
```ts
|
||||
import {assert} from '@sindresorhus/is';
|
||||
|
||||
assert.string(foo);
|
||||
// `foo` is now typed as a `string`.
|
||||
```
|
||||
|
||||
### Named exports
|
||||
|
||||
Named exports allow tooling to perform tree-shaking, potentially reducing bundle size by including only code from the methods that are used.
|
||||
|
||||
Every method listed below is available as a named export. Each method is prefixed by either `is` or `assert` depending on usage.
|
||||
|
||||
For example:
|
||||
|
||||
```js
|
||||
import {assertNull, isUndefined} from '@sindresorhus/is';
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### is(value)
|
||||
|
||||
Returns the type of `value`.
|
||||
|
||||
Primitives are lowercase and object types are camelcase.
|
||||
|
||||
Example:
|
||||
|
||||
- `'undefined'`
|
||||
- `'null'`
|
||||
- `'string'`
|
||||
- `'symbol'`
|
||||
- `'Array'`
|
||||
- `'Function'`
|
||||
- `'Object'`
|
||||
|
||||
This method is also exported as `detect`. You can import it like this:
|
||||
|
||||
```js
|
||||
import {detect} from '@sindresorhus/is';
|
||||
```
|
||||
|
||||
Note: It will throw an error if you try to feed it object-wrapped primitives, as that's a bad practice. For example `new String('foo')`.
|
||||
|
||||
### is.{method}
|
||||
|
||||
All the below methods accept a value and return a boolean for whether the value is of the desired type.
|
||||
|
||||
#### Primitives
|
||||
|
||||
##### .undefined(value)
|
||||
##### .null(value)
|
||||
|
||||
##### .string(value)
|
||||
##### .number(value)
|
||||
|
||||
Note: `is.number(NaN)` returns `false`. This intentionally deviates from `typeof` behavior to increase user-friendliness of `is` type checks.
|
||||
|
||||
##### .boolean(value)
|
||||
##### .symbol(value)
|
||||
##### .bigint(value)
|
||||
|
||||
#### Built-in types
|
||||
|
||||
##### .array(value, assertion?)
|
||||
|
||||
Returns true if `value` is an array and all of its items match the assertion (if provided).
|
||||
|
||||
```js
|
||||
is.array(value); // Validate `value` is an array.
|
||||
is.array(value, is.number); // Validate `value` is an array and all of its items are numbers.
|
||||
```
|
||||
|
||||
##### .function(value)
|
||||
|
||||
##### .buffer(value)
|
||||
|
||||
> [!NOTE]
|
||||
> [Prefer using `Uint8Array` instead of `Buffer`.](https://sindresorhus.com/blog/goodbye-nodejs-buffer)
|
||||
|
||||
##### .blob(value)
|
||||
##### .object(value)
|
||||
|
||||
Keep in mind that [functions are objects too](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions).
|
||||
|
||||
##### .numericString(value)
|
||||
|
||||
Returns `true` for a string that represents a number satisfying `is.number`, for example, `'42'` and `'-8.3'`.
|
||||
|
||||
Note: `'NaN'` returns `false`, but `'Infinity'` and `'-Infinity'` return `true`.
|
||||
|
||||
##### .regExp(value)
|
||||
##### .date(value)
|
||||
##### .error(value)
|
||||
##### .nativePromise(value)
|
||||
##### .promise(value)
|
||||
|
||||
Returns `true` for any object with a `.then()` and `.catch()` method. Prefer this one over `.nativePromise()` as you usually want to allow userland promise implementations too.
|
||||
|
||||
##### .generator(value)
|
||||
|
||||
Returns `true` for any object that implements its own `.next()` and `.throw()` methods and has a function definition for `Symbol.iterator`.
|
||||
|
||||
##### .generatorFunction(value)
|
||||
|
||||
##### .asyncFunction(value)
|
||||
|
||||
Returns `true` for any `async` function that can be called with the `await` operator.
|
||||
|
||||
```js
|
||||
is.asyncFunction(async () => {});
|
||||
//=> true
|
||||
|
||||
is.asyncFunction(() => {});
|
||||
//=> false
|
||||
```
|
||||
|
||||
##### .asyncGenerator(value)
|
||||
|
||||
```js
|
||||
is.asyncGenerator(
|
||||
(async function * () {
|
||||
yield 4;
|
||||
})()
|
||||
);
|
||||
//=> true
|
||||
|
||||
is.asyncGenerator(
|
||||
(function * () {
|
||||
yield 4;
|
||||
})()
|
||||
);
|
||||
//=> false
|
||||
```
|
||||
|
||||
##### .asyncGeneratorFunction(value)
|
||||
|
||||
```js
|
||||
is.asyncGeneratorFunction(async function * () {
|
||||
yield 4;
|
||||
});
|
||||
//=> true
|
||||
|
||||
is.asyncGeneratorFunction(function * () {
|
||||
yield 4;
|
||||
});
|
||||
//=> false
|
||||
```
|
||||
|
||||
##### .boundFunction(value)
|
||||
|
||||
Returns `true` for any `bound` function.
|
||||
|
||||
```js
|
||||
is.boundFunction(() => {});
|
||||
//=> true
|
||||
|
||||
is.boundFunction(function () {}.bind(null));
|
||||
//=> true
|
||||
|
||||
is.boundFunction(function () {});
|
||||
//=> false
|
||||
```
|
||||
|
||||
##### .map(value)
|
||||
##### .set(value)
|
||||
##### .weakMap(value)
|
||||
##### .weakSet(value)
|
||||
##### .weakRef(value)
|
||||
|
||||
#### Typed arrays
|
||||
|
||||
##### .int8Array(value)
|
||||
##### .uint8Array(value)
|
||||
##### .uint8ClampedArray(value)
|
||||
##### .int16Array(value)
|
||||
##### .uint16Array(value)
|
||||
##### .int32Array(value)
|
||||
##### .uint32Array(value)
|
||||
##### .float32Array(value)
|
||||
##### .float64Array(value)
|
||||
##### .bigInt64Array(value)
|
||||
##### .bigUint64Array(value)
|
||||
|
||||
#### Structured data
|
||||
|
||||
##### .arrayBuffer(value)
|
||||
##### .sharedArrayBuffer(value)
|
||||
##### .dataView(value)
|
||||
|
||||
##### .enumCase(value, enum)
|
||||
|
||||
TypeScript-only. Returns `true` if `value` is a member of `enum`.
|
||||
|
||||
```ts
|
||||
enum Direction {
|
||||
Ascending = 'ascending',
|
||||
Descending = 'descending'
|
||||
}
|
||||
|
||||
is.enumCase('ascending', Direction);
|
||||
//=> true
|
||||
|
||||
is.enumCase('other', Direction);
|
||||
//=> false
|
||||
```
|
||||
|
||||
#### Emptiness
|
||||
|
||||
##### .emptyString(value)
|
||||
|
||||
Returns `true` if the value is a `string` and the `.length` is 0.
|
||||
|
||||
##### .emptyStringOrWhitespace(value)
|
||||
|
||||
Returns `true` if `is.emptyString(value)` or if it's a `string` that is all whitespace.
|
||||
|
||||
##### .nonEmptyString(value)
|
||||
|
||||
Returns `true` if the value is a `string` and the `.length` is more than 0.
|
||||
|
||||
##### .nonEmptyStringAndNotWhitespace(value)
|
||||
|
||||
Returns `true` if the value is a `string` that is not empty and not whitespace.
|
||||
|
||||
```js
|
||||
const values = ['property1', '', null, 'property2', ' ', undefined];
|
||||
|
||||
values.filter(is.nonEmptyStringAndNotWhitespace);
|
||||
//=> ['property1', 'property2']
|
||||
```
|
||||
|
||||
##### .emptyArray(value)
|
||||
|
||||
Returns `true` if the value is an `Array` and the `.length` is 0.
|
||||
|
||||
##### .nonEmptyArray(value)
|
||||
|
||||
Returns `true` if the value is an `Array` and the `.length` is more than 0.
|
||||
|
||||
##### .emptyObject(value)
|
||||
|
||||
Returns `true` if the value is an `Object` and `Object.keys(value).length` is 0.
|
||||
|
||||
Please note that `Object.keys` returns only own enumerable properties. Hence something like this can happen:
|
||||
|
||||
```js
|
||||
const object1 = {};
|
||||
|
||||
Object.defineProperty(object1, 'property1', {
|
||||
value: 42,
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
is.emptyObject(object1);
|
||||
//=> true
|
||||
```
|
||||
|
||||
##### .nonEmptyObject(value)
|
||||
|
||||
Returns `true` if the value is an `Object` and `Object.keys(value).length` is more than 0.
|
||||
|
||||
##### .emptySet(value)
|
||||
|
||||
Returns `true` if the value is a `Set` and the `.size` is 0.
|
||||
|
||||
##### .nonEmptySet(Value)
|
||||
|
||||
Returns `true` if the value is a `Set` and the `.size` is more than 0.
|
||||
|
||||
##### .emptyMap(value)
|
||||
|
||||
Returns `true` if the value is a `Map` and the `.size` is 0.
|
||||
|
||||
##### .nonEmptyMap(value)
|
||||
|
||||
Returns `true` if the value is a `Map` and the `.size` is more than 0.
|
||||
|
||||
#### Miscellaneous
|
||||
|
||||
##### .directInstanceOf(value, class)
|
||||
|
||||
Returns `true` if `value` is a direct instance of `class`.
|
||||
|
||||
```js
|
||||
is.directInstanceOf(new Error(), Error);
|
||||
//=> true
|
||||
|
||||
class UnicornError extends Error {}
|
||||
|
||||
is.directInstanceOf(new UnicornError(), Error);
|
||||
//=> false
|
||||
```
|
||||
|
||||
##### .urlInstance(value)
|
||||
|
||||
Returns `true` if `value` is an instance of the [`URL` class](https://developer.mozilla.org/en-US/docs/Web/API/URL).
|
||||
|
||||
```js
|
||||
const url = new URL('https://example.com');
|
||||
|
||||
is.urlInstance(url);
|
||||
//=> true
|
||||
```
|
||||
|
||||
##### .urlString(value)
|
||||
|
||||
Returns `true` if `value` is a URL string.
|
||||
|
||||
Note: this only does basic checking using the [`URL` class](https://developer.mozilla.org/en-US/docs/Web/API/URL) constructor.
|
||||
|
||||
```js
|
||||
const url = 'https://example.com';
|
||||
|
||||
is.urlString(url);
|
||||
//=> true
|
||||
|
||||
is.urlString(new URL(url));
|
||||
//=> false
|
||||
```
|
||||
|
||||
##### .truthy(value)
|
||||
|
||||
Returns `true` for all values that evaluate to true in a boolean context:
|
||||
|
||||
```js
|
||||
is.truthy('🦄');
|
||||
//=> true
|
||||
|
||||
is.truthy(undefined);
|
||||
//=> false
|
||||
```
|
||||
|
||||
##### .falsy(value)
|
||||
|
||||
Returns `true` if `value` is one of: `false`, `0`, `''`, `null`, `undefined`, `NaN`.
|
||||
|
||||
##### .nan(value)
|
||||
##### .nullOrUndefined(value)
|
||||
##### .primitive(value)
|
||||
|
||||
JavaScript primitives are as follows:
|
||||
|
||||
- `null`
|
||||
- `undefined`
|
||||
- `string`
|
||||
- `number`
|
||||
- `boolean`
|
||||
- `symbol`
|
||||
- `bigint`
|
||||
|
||||
##### .integer(value)
|
||||
|
||||
##### .safeInteger(value)
|
||||
|
||||
Returns `true` if `value` is a [safe integer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger).
|
||||
|
||||
##### .plainObject(value)
|
||||
|
||||
An object is plain if it's created by either `{}`, `new Object()`, or `Object.create(null)`.
|
||||
|
||||
##### .iterable(value)
|
||||
##### .asyncIterable(value)
|
||||
##### .class(value)
|
||||
|
||||
Returns `true` if the value is a class constructor.
|
||||
|
||||
##### .typedArray(value)
|
||||
|
||||
##### .arrayLike(value)
|
||||
|
||||
A `value` is array-like if it is not a function and has a `value.length` that is a safe integer greater than or equal to 0.
|
||||
|
||||
```js
|
||||
is.arrayLike(document.forms);
|
||||
//=> true
|
||||
|
||||
function foo() {
|
||||
is.arrayLike(arguments);
|
||||
//=> true
|
||||
}
|
||||
foo();
|
||||
```
|
||||
|
||||
##### .tupleLike(value, guards)
|
||||
|
||||
A `value` is tuple-like if it matches the provided `guards` array both in `.length` and in types.
|
||||
|
||||
```js
|
||||
is.tupleLike([1], [is.number]);
|
||||
//=> true
|
||||
```
|
||||
|
||||
```js
|
||||
function foo() {
|
||||
const tuple = [1, '2', true];
|
||||
if (is.tupleLike(tuple, [is.number, is.string, is.boolean])) {
|
||||
tuple // [number, string, boolean]
|
||||
}
|
||||
}
|
||||
|
||||
foo();
|
||||
```
|
||||
|
||||
##### .positiveNumber(value)
|
||||
|
||||
Check if `value` is a number and is more than 0.
|
||||
|
||||
##### .negativeNumber(value)
|
||||
|
||||
Check if `value` is a number and is less than 0.
|
||||
|
||||
##### .inRange(value, range)
|
||||
|
||||
Check if `value` (number) is in the given `range`. The range is an array of two values, lower bound and upper bound, in no specific order.
|
||||
|
||||
```js
|
||||
is.inRange(3, [0, 5]);
|
||||
is.inRange(3, [5, 0]);
|
||||
is.inRange(0, [-2, 2]);
|
||||
```
|
||||
|
||||
##### .inRange(value, upperBound)
|
||||
|
||||
Check if `value` (number) is in the range of `0` to `upperBound`.
|
||||
|
||||
```js
|
||||
is.inRange(3, 10);
|
||||
```
|
||||
|
||||
##### .htmlElement(value)
|
||||
|
||||
Returns `true` if `value` is an [HTMLElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement).
|
||||
|
||||
##### .nodeStream(value)
|
||||
|
||||
Returns `true` if `value` is a Node.js [stream](https://nodejs.org/api/stream.html).
|
||||
|
||||
```js
|
||||
import fs from 'node:fs';
|
||||
|
||||
is.nodeStream(fs.createReadStream('unicorn.png'));
|
||||
//=> true
|
||||
```
|
||||
|
||||
##### .observable(value)
|
||||
|
||||
Returns `true` if `value` is an `Observable`.
|
||||
|
||||
```js
|
||||
import {Observable} from 'rxjs';
|
||||
|
||||
is.observable(new Observable());
|
||||
//=> true
|
||||
```
|
||||
|
||||
##### .infinite(value)
|
||||
|
||||
Check if `value` is `Infinity` or `-Infinity`.
|
||||
|
||||
##### .evenInteger(value)
|
||||
|
||||
Returns `true` if `value` is an even integer.
|
||||
|
||||
##### .oddInteger(value)
|
||||
|
||||
Returns `true` if `value` is an odd integer.
|
||||
|
||||
##### .propertyKey(value)
|
||||
|
||||
Returns `true` if `value` can be used as an object property key (either `string`, `number`, or `symbol`).
|
||||
|
||||
##### .formData(value)
|
||||
|
||||
Returns `true` if `value` is an instance of the [`FormData` class](https://developer.mozilla.org/en-US/docs/Web/API/FormData).
|
||||
|
||||
```js
|
||||
const data = new FormData();
|
||||
|
||||
is.formData(data);
|
||||
//=> true
|
||||
```
|
||||
|
||||
##### .urlSearchParams(value)
|
||||
|
||||
Returns `true` if `value` is an instance of the [`URLSearchParams` class](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams).
|
||||
|
||||
```js
|
||||
const searchParams = new URLSearchParams();
|
||||
|
||||
is.urlSearchParams(searchParams);
|
||||
//=> true
|
||||
```
|
||||
|
||||
##### .any(predicate | predicate[], ...values)
|
||||
|
||||
Using a single `predicate` argument, returns `true` if **any** of the input `values` returns true in the `predicate`:
|
||||
|
||||
```js
|
||||
is.any(is.string, {}, true, '🦄');
|
||||
//=> true
|
||||
|
||||
is.any(is.boolean, 'unicorns', [], new Map());
|
||||
//=> false
|
||||
```
|
||||
|
||||
Using an array of `predicate[]`, returns `true` if **any** of the input `values` returns true for **any** of the `predicates` provided in an array:
|
||||
|
||||
```js
|
||||
is.any([is.string, is.number], {}, true, '🦄');
|
||||
//=> true
|
||||
|
||||
is.any([is.boolean, is.number], 'unicorns', [], new Map());
|
||||
//=> false
|
||||
```
|
||||
|
||||
##### .all(predicate, ...values)
|
||||
|
||||
Returns `true` if **all** of the input `values` returns true in the `predicate`:
|
||||
|
||||
```js
|
||||
is.all(is.object, {}, new Map(), new Set());
|
||||
//=> true
|
||||
|
||||
is.all(is.string, '🦄', [], 'unicorns');
|
||||
//=> false
|
||||
```
|
||||
|
||||
##### .validDate(value)
|
||||
|
||||
Returns `true` if the value is a valid date.
|
||||
|
||||
All [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/Date) objects have an internal timestamp value which is the number of milliseconds since the [Unix epoch](https://developer.mozilla.org/en-US/docs/Glossary/Unix_time). When a new `Date` is constructed with bad inputs, no error is thrown. Instead, a new `Date` object is returned. But the internal timestamp value is set to `NaN`, which is an `'Invalid Date'`. Bad inputs can be an non-parsable date string, a non-numeric value or a number that is outside of the expected range for a date value.
|
||||
|
||||
```js
|
||||
const valid = new Date('2000-01-01');
|
||||
|
||||
is.date(valid);
|
||||
//=> true
|
||||
valid.getTime();
|
||||
//=> 946684800000
|
||||
valid.toUTCString();
|
||||
//=> 'Sat, 01 Jan 2000 00:00:00 GMT'
|
||||
is.validDate(valid);
|
||||
//=> true
|
||||
|
||||
const invalid = new Date('Not a parsable date string');
|
||||
|
||||
is.date(invalid);
|
||||
//=> true
|
||||
invalid.getTime();
|
||||
//=> NaN
|
||||
invalid.toUTCString();
|
||||
//=> 'Invalid Date'
|
||||
is.validDate(invalid);
|
||||
//=> false
|
||||
```
|
||||
|
||||
##### .validLength(value)
|
||||
|
||||
Returns `true` if the value is a safe integer that is greater than or equal to zero.
|
||||
|
||||
This can be useful to confirm that a value is a valid count of something, ie. 0 or more.
|
||||
|
||||
##### .whitespaceString(value)
|
||||
|
||||
Returns `true` if the value is a string with only whitespace characters.
|
||||
|
||||
## Type guards
|
||||
|
||||
When using `is` together with TypeScript, [type guards](http://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types) are being used extensively to infer the correct type inside if-else statements.
|
||||
|
||||
```ts
|
||||
import is from '@sindresorhus/is';
|
||||
|
||||
const padLeft = (value: string, padding: string | number) => {
|
||||
if (is.number(padding)) {
|
||||
// `padding` is typed as `number`
|
||||
return Array(padding + 1).join(' ') + value;
|
||||
}
|
||||
|
||||
if (is.string(padding)) {
|
||||
// `padding` is typed as `string`
|
||||
return padding + value;
|
||||
}
|
||||
|
||||
throw new TypeError(`Expected 'padding' to be of type 'string' or 'number', got '${is(padding)}'.`);
|
||||
}
|
||||
|
||||
padLeft('🦄', 3);
|
||||
//=> ' 🦄'
|
||||
|
||||
padLeft('🦄', '🌈');
|
||||
//=> '🌈🦄'
|
||||
```
|
||||
|
||||
## Type assertions
|
||||
|
||||
The type guards are also available as [type assertions](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions), which throw an error for unexpected types. It is a convenient one-line version of the often repetitive "if-not-expected-type-throw" pattern.
|
||||
|
||||
```ts
|
||||
import {assert} from '@sindresorhus/is';
|
||||
|
||||
const handleMovieRatingApiResponse = (response: unknown) => {
|
||||
assert.plainObject(response);
|
||||
// `response` is now typed as a plain `object` with `unknown` properties.
|
||||
|
||||
assert.number(response.rating);
|
||||
// `response.rating` is now typed as a `number`.
|
||||
|
||||
assert.string(response.title);
|
||||
// `response.title` is now typed as a `string`.
|
||||
|
||||
return `${response.title} (${response.rating * 10})`;
|
||||
};
|
||||
|
||||
handleMovieRatingApiResponse({rating: 0.87, title: 'The Matrix'});
|
||||
//=> 'The Matrix (8.7)'
|
||||
|
||||
// This throws an error.
|
||||
handleMovieRatingApiResponse({rating: '🦄'});
|
||||
```
|
||||
|
||||
## Generic type parameters
|
||||
|
||||
The type guards and type assertions are aware of [generic type parameters](https://www.typescriptlang.org/docs/handbook/generics.html), such as `Promise<T>` and `Map<Key, Value>`. The default is `unknown` for most cases, since `is` cannot check them at runtime. If the generic type is known at compile-time, either implicitly (inferred) or explicitly (provided), `is` propagates the type so it can be used later.
|
||||
|
||||
Use generic type parameters with caution. They are only checked by the TypeScript compiler, and not checked by `is` at runtime. This can lead to unexpected behavior, where the generic type is _assumed_ at compile-time, but actually is something completely different at runtime. It is best to use `unknown` (default) and type-check the value of the generic type parameter at runtime with `is` or `assert`.
|
||||
|
||||
```ts
|
||||
import {assert} from '@sindresorhus/is';
|
||||
|
||||
async function badNumberAssumption(input: unknown) {
|
||||
// Bad assumption about the generic type parameter fools the compile-time type system.
|
||||
assert.promise<number>(input);
|
||||
// `input` is a `Promise` but only assumed to be `Promise<number>`.
|
||||
|
||||
const resolved = await input;
|
||||
// `resolved` is typed as `number` but was not actually checked at runtime.
|
||||
|
||||
// Multiplication will return NaN if the input promise did not actually contain a number.
|
||||
return 2 * resolved;
|
||||
}
|
||||
|
||||
async function goodNumberAssertion(input: unknown) {
|
||||
assert.promise(input);
|
||||
// `input` is typed as `Promise<unknown>`
|
||||
|
||||
const resolved = await input;
|
||||
// `resolved` is typed as `unknown`
|
||||
|
||||
assert.number(resolved);
|
||||
// `resolved` is typed as `number`
|
||||
|
||||
// Uses runtime checks so only numbers will reach the multiplication.
|
||||
return 2 * resolved;
|
||||
}
|
||||
|
||||
badNumberAssumption(Promise.resolve('An unexpected string'));
|
||||
//=> NaN
|
||||
|
||||
// This correctly throws an error because of the unexpected string value.
|
||||
goodNumberAssertion(Promise.resolve('An unexpected string'));
|
||||
```
|
||||
|
||||
## FAQ
|
||||
|
||||
### Why yet another type checking module?
|
||||
|
||||
There are hundreds of type checking modules on npm, unfortunately, I couldn't find any that fit my needs:
|
||||
|
||||
- Includes both type methods and ability to get the type
|
||||
- Types of primitives returned as lowercase and object types as camelcase
|
||||
- Covers all built-ins
|
||||
- Unsurprising behavior
|
||||
- Well-maintained
|
||||
- Comprehensive test suite
|
||||
|
||||
For the ones I found, pick 3 of these.
|
||||
|
||||
The most common mistakes I noticed in these modules was using `instanceof` for type checking, forgetting that functions are objects, and omitting `symbol` as a primitive.
|
||||
|
||||
### Why not just use `instanceof` instead of this package?
|
||||
|
||||
`instanceof` does not work correctly for all types and it does not work across [realms](https://stackoverflow.com/a/49832343/64949). Examples of realms are iframes, windows, web workers, and the `vm` module in Node.js.
|
||||
|
||||
## Related
|
||||
|
||||
- [environment](https://github.com/sindresorhus/environment) - Check which JavaScript environment your code is running in at runtime
|
||||
- [is-stream](https://github.com/sindresorhus/is-stream) - Check if something is a Node.js stream
|
||||
- [is-observable](https://github.com/sindresorhus/is-observable) - Check if a value is an Observable
|
||||
- [file-type](https://github.com/sindresorhus/file-type) - Detect the file type of a Buffer/Uint8Array
|
||||
- [is-ip](https://github.com/sindresorhus/is-ip) - Check if a string is an IP address
|
||||
- [is-array-sorted](https://github.com/sindresorhus/is-array-sorted) - Check if an Array is sorted
|
||||
- [is-error-constructor](https://github.com/sindresorhus/is-error-constructor) - Check if a value is an error constructor
|
||||
- [is-empty-iterable](https://github.com/sindresorhus/is-empty-iterable) - Check if an Iterable is empty
|
||||
- [is-blob](https://github.com/sindresorhus/is-blob) - Check if a value is a Blob - File-like object of immutable, raw data
|
||||
- [has-emoji](https://github.com/sindresorhus/has-emoji) - Check whether a string has any emoji
|
||||
|
||||
## Maintainers
|
||||
|
||||
- [Sindre Sorhus](https://github.com/sindresorhus)
|
||||
- [Giora Guttsait](https://github.com/gioragutt)
|
||||
- [Brandon Smith](https://github.com/brandon93s)
|
Reference in New Issue
Block a user