{"version":3,"file":"hasProp.cjs","names":["purry"],"sources":["../src/hasProp.ts"],"sourcesContent":["import type { KeysOfUnion, Simplify } from \"type-fest\";\nimport type { IsBounded } from \"./internal/types/IsBounded\";\nimport { purry } from \"./purry\";\n\n// Arrays route to the `boolean`-returning overload below: their `keyof`\n// includes prototype methods (`push`, `pop`, …) that aren't own properties\n// at runtime, which would otherwise collapse the predicate's else branch to\n// `never`. The leading `extends readonly unknown[]` filter is mirrored on\n// both the predicate type and the parameter type so the type-predicate\n// assignability check stays satisfied.\ntype NonArray<T> = T extends readonly unknown[] ? never : T;\n\ntype HasProp<T, Key extends PropertyKey> = T extends readonly unknown[]\n  ? never\n  : // Distribute over `T`'s union members so members that don't have `Key`\n    // drop out of the narrowed type.\n    T extends unknown\n    ? Key extends keyof T\n      ? // `T &` makes the result structurally a subtype of `T`, satisfying\n        // the type-predicate assignability check.\n        Simplify<T & Required<Pick<T, Key>>>\n      : never\n    : never;\n\n/**\n * Checks if `data` has a prop `key`.\n *\n * Uses [`Object.hasOwn`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)\n * which only checks own properties, skipping properties inherited through the\n * prototype chain.\n *\n * - Use `prop` to read the value.\n *\n * @param data - The object to test.\n * @param key - The key to look up.\n * @signature\n *   hasProp(data, key)\n * @example\n *   hasProp({ a: 1 }, \"a\"); //=> true\n * @dataFirst\n * @category Guard\n */\nexport function hasProp<T extends object, Key extends KeysOfUnion<T>>(\n  // Arrays route to the `boolean`-returning overload below: their `keyof`\n  // includes prototype methods (`push`, `pop`, …) that aren't own properties\n  // at runtime, which would otherwise collapse the predicate's else branch\n  // to `never`. Use `hasAtLeast` to narrow array indices and `isArray` to\n  // discriminate array vs. object unions.\n  data: NonArray<T>,\n  // Bounded literal keys narrow; unbounded keys (`string`, template\n  // literals, etc.) route to the `boolean`-returning overload below so the\n  // predicate doesn't collapse the else-branch to `never`.\n  key: IsBounded<Key> extends true ? Key : never,\n): data is HasProp<T, Key>;\nexport function hasProp<T extends object>(\n  data: T,\n  key: KeysOfUnion<T>,\n): boolean;\n\n/**\n * Checks if `data` has a prop `key`.\n *\n * Uses [`Object.hasOwn`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn)\n * which only checks own properties, skipping properties inherited through the\n * prototype chain.\n *\n * - Use `prop` to read the value.\n *\n * @param key - The key to look up.\n * @signature\n *   hasProp(key)(data)\n * @example\n *   pipe({ a: 1 }, hasProp(\"a\")); //=> true\n *   filter([] as { a?: number }[], hasProp(\"a\")); //=> typed as { a: number }[]\n * @dataLast\n * @category Guard\n */\nexport function hasProp<T extends object, Key extends KeysOfUnion<T>>(\n  key: IsBounded<Key> extends true ? Key : never,\n): (data: NonArray<T>) => data is HasProp<T, Key>;\nexport function hasProp<T extends object>(\n  key: KeysOfUnion<T>,\n): (data: T) => boolean;\n\nexport function hasProp(...args: readonly unknown[]): unknown {\n  return purry(hasPropImplementation, args);\n}\n\nfunction hasPropImplementation<T extends object, Key extends KeysOfUnion<T>>(\n  data: T,\n  key: Key,\n): data is HasProp<T, Key> {\n  return Object.hasOwn(data, key);\n}\n"],"mappings":"kGAoFA,SAAgB,EAAQ,GAAG,EAAmC,CAC5D,OAAOA,EAAAA,MAAM,EAAuB,CAAI,CAC1C,CAEA,SAAS,EACP,EACA,EACyB,CACzB,OAAO,OAAO,OAAO,EAAM,CAAG,CAChC"}