{"version":3,"file":"index.cjs","names":[],"sources":["../index.ts"],"sourcesContent":["import type { EmptyObject, Get, Paths, UnknownRecord } from 'type-fest';\n\n/**\n * Represents a value that can be of type `A` or `undefined`.\n *\n * @template A - The type of the value.\n */\nexport type Undefinable<A> = A | undefined;\n\n/**\n * Represents a value that can be of type `A` or `null`.\n *\n * @template A - The type of the value.\n */\nexport type Nullable<A> = A | null;\n\n/**\n * Represents a value that can be of type `A` or be null/undefined.\n *\n * @template A - The type of the value.\n */\nexport type Nilable<A> = A | Nil;\n\n/**\n * Represents a value of type `A` that is guaranteed to be neither null nor undefined.\n *\n * @template A - The type to be filtered.\n */\nexport type NotNilable<A> = Exclude<A, Nil>;\n\n/**\n * Represents a value that is either null or undefined.\n */\nexport type Nil = null | undefined;\n\n/**\n * Represents an array that contains at least one element.\n *\n * @template T - The type of the array elements.\n */\nexport type NonEmptyArray<T> = [T, ...T[]];\n\n/**\n * Represents an array that can be null or undefined, and its elements can also be null or undefined.\n *\n * @template T - The type of the non-null/undefined elements in the array.\n */\nexport type NilableArray<T> = Nilable<Nilable<T>[]>;\n\n/**\n * Retrieves the type of a deeply nested property from an object while removing null and undefined.\n *\n * @template T - The object type.\n * @template P - The path to the nested property as a string literal.\n *\n * @remarks\n * This type recursively traverses the object along the given path and applies `NonNullable` to the resulting type.\n * It may fail for excessively deep property paths or in the presence of circular references. In such cases, consider\n * using nested `NonNullable` definitions to avoid errors such as:\n * - TS2589: Type instantiation is excessively deep and possibly infinite.\n * - TS2615: Type of property 'XYZ' circularly references itself in mapped type.\n */\nexport type NestedNonNullable<T, P extends Paths<T> & string> = NonNullable<Get<T, P>>;\n\n/**\n * Represents a value that is falsy.\n */\nexport type Falsy = typeof Number.NaN | '' | 0n | false | null | undefined;\n\n// eslint-disable-next-line @typescript-eslint/no-magic-numbers\nconst FALSY_VALUES = [false, 0, -0, 0n, '', null, undefined, Number.NaN] as const;\n\n/**\n * Represents a value that is truthy.\n *\n * @template T - The type of the value.\n */\nexport type Truthy<T> = Exclude<T, Falsy>;\n\n/* ========== type guards ========== */\n\n/**\n * Checks if the provided value is null.\n *\n * @param value - The value to check.\n * @returns True if the value is null, false otherwise.\n */\nexport const isNull = (value: unknown): value is null => value === null;\n\n/**\n * Checks if the provided value is not null.\n *\n * @param value - The value to check.\n * @returns True if the value is not null, false otherwise.\n */\nexport const isNotNull = <T>(value: unknown): value is Exclude<T, null> => !isNull(value);\n\n/**\n * Checks if the provided value is undefined.\n *\n * @param value - The value to check.\n * @returns True if the value is undefined, false otherwise.\n */\nexport const isUndefined = (value: unknown): value is undefined => value === undefined;\n\n/**\n * Checks if the provided value is not undefined.\n *\n * @param value - The value to check.\n * @returns True if the value is not undefined, false otherwise.\n */\nexport const isNotUndefined = <T>(value: Undefinable<T>): value is Exclude<T, undefined> =>\n  !isUndefined(value);\n\n/**\n * Checks if the provided value is null or undefined.\n *\n * @param value - The value to check.\n * @returns True if the value is null or undefined, false otherwise.\n */\nexport const isNil = (value: unknown): value is Nil => isNull(value) || isUndefined(value);\n\n/**\n * Checks if the provided value is neither null nor undefined.\n *\n * @param value - The value to check.\n * @returns True if the value is not null or undefined, false otherwise.\n */\nexport const isNotNil = <T>(value: Nil | T): value is T => !isNil(value);\n\n/**\n * Checks if the provided value is a string.\n *\n * @param value - The value to check.\n * @returns True if the value is a string, false otherwise.\n */\nexport const isString = (value: unknown): value is string => typeof value === 'string';\n\n/**\n * Checks if the provided value is not a string.\n *\n * @param value - The value to check.\n * @returns True if the value is not a string, false otherwise.\n */\nexport const isNotString = (value: unknown): value is Exclude<unknown, string> => !isString(value);\n\n/**\n * Checks if the provided value is an empty string.\n *\n * @param value - The value to check.\n * @returns True if the value is an empty string, false otherwise.\n */\nexport const isEmptyString = (value: unknown): value is '' => isString(value) && value === '';\n\n/**\n * Checks if the provided value is a non-empty string.\n *\n * @param value - The value to check.\n * @returns True if the value is a non-empty string, false otherwise.\n */\nexport const isNonEmptyString = (value: unknown): value is string =>\n  isString(value) && !isEmptyString(value);\n\n/**\n * Checks if the provided value is a number.\n *\n * @param value - The value to check.\n * @returns True if the value is a number, false otherwise.\n */\nexport const isNumber = (value: unknown): value is number => typeof value === 'number';\n\n/**\n * Checks if the provided value is not a number.\n *\n * @param value - The value to check.\n * @returns True if the value is not a number, false otherwise.\n */\nexport const isNotNumber = (value: unknown): value is Exclude<unknown, number> => !isNumber(value);\n\n/**\n * Checks if the provided value is NaN (Not a Number).\n *\n * @param value - The value to check.\n * @returns True if the value is NaN, false otherwise.\n */\nexport const isNaN = (value: unknown): value is number => Number.isNaN(value);\n\n/**\n * Checks if the provided value is an integer.\n *\n * @param value - The value to check.\n * @returns True if the value is an integer, false otherwise.\n */\nexport const isInteger = (value: unknown): value is number => Number.isInteger(value);\n\n/**\n * Checks if the provided value is a non-null object that is not an array.\n *\n * @param value - The value to check.\n * @returns True if the value is an object (but not an array), false otherwise.\n */\nexport const isRecord = (value: unknown): value is EmptyObject | Record<string, unknown> =>\n  isNotNil(value) && typeof value === 'object' && !(value instanceof Array);\n\n/**\n * Checks if the provided value is not an object.\n *\n * @param value - The value to check.\n * @returns True if the value is not a record (object), false otherwise.\n */\nexport const isNotRecord = (\n  value: unknown,\n): value is Exclude<unknown, EmptyObject | Record<string, unknown>> => !isRecord(value);\n\n/**\n * Checks if the provided value is an object with no own properties.\n *\n * @param value - The value to check.\n * @returns True if the value is an empty object, false otherwise.\n */\nexport const isEmptyRecord = (value: unknown): value is EmptyObject =>\n  isRecord(value) && Object.keys(value).length === 0;\n\n/**\n * Checks if the provided value is an object with at least one own property.\n *\n * @param value - The value to check.\n * @returns True if the value is a non-empty object, false otherwise.\n */\nexport const isNonEmptyRecord = (value: unknown): value is Record<string, unknown> =>\n  isRecord(value) && Object.keys(value).length > 0;\n\n/**\n * Checks if the provided value is an array.\n *\n * @param value - The value to check.\n * @returns True if the value is an array, false otherwise.\n */\nexport const isArray = (value: unknown): value is unknown[] =>\n  isNotNil(value) && typeof value === 'object' && value instanceof Array;\n\n/**\n * Checks if the provided value is not an array.\n *\n * @param value - The value to check.\n * @returns True if the value is not an array, false otherwise.\n */\nexport const isNotArray = (value: unknown): value is Exclude<unknown, unknown[]> => !isArray(value);\n\n/**\n * Checks if the provided value is an empty array.\n *\n * @param value - The value to check.\n * @returns True if the value is an empty array, false otherwise.\n */\nexport const isEmptyArray = (value: unknown): value is never[] =>\n  isArray(value) && value.length === 0;\n\n/**\n * Checks if the provided value is a non-empty array.\n *\n * @param value - The value to check. Can be null or undefined.\n * @returns True if the value is a non-empty array, false otherwise.\n */\nexport const isNonEmptyArray = <T>(\n  value: Nilable<T[] | UnknownRecord>,\n): value is NonEmptyArray<T> => isArray(value) && value.length > 0;\n\n/**\n * Checks if the provided value is a function.\n *\n * @param value - The value to check.\n * @returns True if the value is a function, false otherwise.\n */\nexport const isFunction = (value: unknown): value is (...args: unknown[]) => unknown =>\n  isNotNil(value) && typeof value === 'function';\n\n/**\n * Checks if the provided value is not a function.\n *\n * @param value - The value to check.\n * @returns True if the value is not a function, false otherwise.\n */\nexport const isNotFunction = (\n  value: unknown,\n): value is Exclude<unknown, (...args: unknown[]) => unknown> => !isFunction(value);\n\n/**\n * Checks if the provided value is a boolean.\n *\n * @param value - The value to check.\n * @returns True if the value is a boolean, false otherwise.\n */\nexport const isBoolean = (value: unknown): value is boolean =>\n  isNotNil(value) && typeof value === 'boolean';\n\n/**\n * Checks if the provided value is not a boolean.\n *\n * @param value - The value to check.\n * @returns True if the value is not a boolean, false otherwise.\n */\nexport const isNotBoolean = (value: unknown): value is Exclude<unknown, boolean> =>\n  !isBoolean(value);\n\n/**\n * Checks if the provided value is void.\n *\n * @param value - The value to check.\n * @returns True if the value is void (undefined), false otherwise.\n */\nexport const isVoid = (value: unknown): value is void => value === void 0; // eslint-disable-line no-void\n\n/**\n * Checks if the provided value is not void.\n *\n * @param value - The value to check.\n * @returns True if the value is not void (defined), false otherwise.\n */\nexport const isNotVoid = (value: unknown): value is Exclude<unknown, void> => !isVoid(value);\n\n/**\n * Checks if the provided value is an instance of Error.\n *\n * @param value - The value to check.\n * @returns True if the value is an Error instance, false otherwise.\n */\nexport const isError = (value: unknown): value is Error => {\n  return isNotNil(value) && value instanceof Error;\n};\n\n/**\n * Checks if the provided value is an instance of Date.\n *\n * @param value - The value to check.\n * @returns True if the value is a Date instance, false otherwise.\n */\nexport const isDate = (value: unknown): value is Date => {\n  return isNotNil(value) && value instanceof Date;\n};\n\n/**\n * Checks if the provided value is falsy.\n *\n * @param value - The value to check.\n * @returns True if the value is falsy, false otherwise.\n */\nexport const isFalsy = (value: unknown): value is Falsy =>\n  // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion\n  FALSY_VALUES.includes(value as Falsy) || Number.isNaN(value);\n\n/**\n * Checks if the provided value is truthy.\n *\n * @param value - The value to check.\n * @returns True if the value is truthy, false otherwise.\n */\nexport const isTruthy = (value: unknown): boolean =>\n  // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion\n  !FALSY_VALUES.includes(value as Falsy) && !Number.isNaN(value);\n\n/**\n * Curried function that tests if an input is an object\n * _and_ that a key that was passed in is a property of that object.\n *\n * @param value - The input object to test.\n * @param key - The key to test if it is a property of the input record.\n * @returns A function that takes an unknown input and then tests if the\n * input is an object and whether the key is a property of that object or not.\n */\nexport const hasKey = <Key extends string, Value>(\n  value: unknown,\n  key: Key,\n): value is Record<Key, Value> => isNonEmptyRecord(value) && key in value;\n"],"mappings":";;;;;;;;;;;AAsEA,MAAM,eAAe;CAAC;CAAO;CAAG;CAAI;CAAI;CAAI;CAAM,KAAA;CAAW;CAAW;;;;;;;AAiBxE,MAAa,UAAU,UAAkC,UAAU;;;;;;;AAQnE,MAAa,aAAgB,UAA8C,CAAC,OAAO,MAAM;;;;;;;AAQzF,MAAa,eAAe,UAAuC,UAAU,KAAA;;;;;;;AAQ7E,MAAa,kBAAqB,UAChC,CAAC,YAAY,MAAM;;;;;;;AAQrB,MAAa,SAAS,UAAiC,OAAO,MAAM,IAAI,YAAY,MAAM;;;;;;;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