{"version":3,"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 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  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  !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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsEA,IAAM,eAAe,CAAC,OAAO,GAAG,IAAI,IAAI,IAAI,MAAM,QAAW,OAAO,GAAG;AAiBhE,IAAM,SAAS,CAAC,UAAkC,UAAU;AAQ5D,IAAM,YAAY,CAAI,UAA8C,CAAC,OAAO,KAAK;AAQjF,IAAM,cAAc,CAAC,UAAuC,UAAU;AAQtE,IAAM,iBAAiB,CAAI,UAChC,CAAC,YAAY,KAAK;AAQb,IAAM,QAAQ,CAAC,UAAiC,OAAO,KAAK,KAAK,YAAY,KAAK;AAQlF,IAAM,WAAW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