{"version":3,"file":"hasOwnProp-S8kSmJ2n.cjs","names":["isString","isObjectOrArray","isFunction","isPlainObject","isNumber","isNaN","isSymbol","isNull","isUndefined","createMessage"],"sources":["../src/predicates/has/hasOwnProp.ts"],"sourcesContent":["import type {\n  AnyFunction,\n  AnyString,\n  IsAny,\n  IsStringLiteral\n} from \"@rzl-zone/ts-types-plus\";\nimport type {\n  DeepRequiredSymbolHasOwnProp,\n  GuardedHasOwnProp,\n  HasOwnPropOptions,\n  NestedKeyOfHasOwnProp,\n  SmartDetectArrayFuncHasOwnProp,\n  SmartDetectUnknownKeyHasOwnProp,\n  NumericKeyHasOwnPropMapped,\n  NumericKeyOfHasOwnProp,\n  SmartDetectStringHasOwnProp\n} from \"./hasOwnProp.types\";\n\nimport { createMessage } from \"@/_private/logger\";\n\nimport { assertIsBoolean } from \"@/assertions/booleans/assertIsBoolean\";\n\nimport { isNaN } from \"../is/isNaN\";\nimport { isNull } from \"../is/isNull\";\nimport { isString } from \"../is/isString\";\nimport { isNumber } from \"../is/isNumber\";\nimport { isSymbol } from \"../is/isSymbol\";\nimport { isFunction } from \"../is/isFunction\";\nimport { isUndefined } from \"../is/isUndefined\";\nimport { isObjectOrArray } from \"../is/isObjectOrArray\";\nimport { isPlainObject, type IsPlainObjectResult } from \"../is/isPlainObject\";\n\n// ------------------- HAS OWN PROP OVERLOADS -------------------\n\n/** -------------------------------------------------------\n * * ***Type guard: `hasOwnProp`.***\n * --------------------------------------------------------\n * **A **type-safe** replacement for `Object.prototype.hasOwnProperty` with runtime validation and **TypeScript-aware type narrowing**.**\n *\n * ---\n * - #### *Supported Targets:*\n *       - **Plain objects** ➔ `{ foo: \"bar\" }`.\n *       - **Arrays** ➔ `[ { id: 1 }, { id: 2 } ]`.\n *       - **Strings** ➔ `\"hello\"` (as array-like objects with `.length`, index, etc.).\n *       - **Functions** ➔ callable objects with extra props.\n *       - **Symbols** ➔ own property symbols.\n *       ---\n * - #### *Key Advantages over `in` or `obj.hasOwnProperty(key)`:*\n *       - Supports **dot/bracket path notation** (e.g. `\"user.address.city\"`, `\"addresses[0].zip\"`).\n *       - Handles **symbol** keys safely.\n *       - **Narrows** the type of `obj` in TypeScript (stronger type safety).\n *       - Configurable handling of **`undefined`** and **`null`**.\n *       ---\n * - #### *Runtime Behavior:*\n *       - #### Returns `true` if:\n *            - Value `obj` is an object/array/string/function **and** the property\n *              exists **and**, it passes the `options` checks.\n *            ---\n *       - #### Returns `false` if:\n *            - Value `obj` is not a valid type.\n *            - The property does not exist.\n *            - The value is `undefined` and `discardUndefined: true` (**default**).\n *            - The value is `null` and `discardNull: true`.\n *            - The `key` (after trimming) is an **empty string** ➔ treated as **invalid**.\n *       ---\n * - #### *TypeScript Behavior:*\n *       - #### Inside an `if (hasOwnProp(...)) {}` block:\n *            - The property is **guaranteed to exist**.\n *            - Depending on `options`, the property type is narrowed to exclude\n *              `undefined` and/or `null`.\n *       ---\n * - #### *Caveats:*\n *       - #### Empty keys are invalid:\n *            - If the `key` string is empty (`\"\"`) after trimming whitespace or other characters,\n *              it will **not** be considered a valid property and always returns `false`.\n *            ---\n *       - #### Arrays are limited by TypeScript inference:\n *            - Checking index `[0]` only narrows **that specific index**, not the rest, example:\n *               1. `hasOwnProp(users, \"[0].id\")` does **not** imply `users[1].id` exists.\n *                   - For different indices, use **optional chaining** (`users[1]?.id`).\n *            ---\n *       - #### Autocomplete limitation for array indices:\n *            - Autocompletion for `[index]` is only supported up to **5** (`[0]` ➔ `[4]`).\n *            - This limit is intentional for **performance and safety:**\n *               1. Generating infinite union types for all possible indices would cause\n *                 **TypeScript IntelliSense to hang or crash**.\n *                   - You can still check higher indices manually (e.g. `\"[999].id\"`),\n *                     but they will not show up in IntelliSense suggestions.\n *\n * ---\n * @param {HasOwnPropOptions} [options] - ***Optional configuration object.***\n * @param {HasOwnPropOptions[\"discardUndefined\"]} [options.discardUndefined=true]\n *  ***If `true`, properties with `undefined` values are treated as **missing**, default: `true`.***\n * @param {HasOwnPropOptions[\"discardNull\"]} [options.discardNull=false]\n *  ***If `true`, properties with `null` values are treated as **missing**, default: `false`.***\n * @param {*} obj ***The `object`, `array`, `string`, `function`, or `other value` to check against.***\n * @param {PropertyKey} key\n *  ***The property key to check, can be:***\n *    - `string` (supports dot/bracket paths, e.g. `\"user.address.city\"`, `\"[0].id\"`).\n *    - `number` (array-like index).\n *    - `symbol` (own property symbols).\n *\n * ---\n * @returns {boolean} Return `true` if the property exists (and passes `options`), otherwise `false`.\n *\n * ---\n * @example\n *\n * - #### Objects:\n *   ```ts\n *   const obj: { name?: string | null } = {};\n *\n *   if (hasOwnProp(obj, \"name\")) {\n *     // obj is now ➔ { name: string | null }\n *     console.log(obj.name); // string | null\n *   }\n *\n *   if (hasOwnProp(obj, \"name\", { discardUndefined: true, discardNull: true })) {\n *     // obj is now ➔ { name: string }\n *     console.log(obj.name.toUpperCase()); // safe\n *   }\n *   ```\n * - #### Arrays:\n *   ```ts\n *   const users = [{ id: 1 }, { id: 2 }];\n *\n *   if (hasOwnProp(users, \"[1].id\")) {\n *     // ➔ users[1].id is guaranteed to exist\n *     console.log(users[1].id); // number\n *   }\n *\n *   // Caveat: narrowing only applies to checked index\n *   if (hasOwnProp(users, \"[0].id\")) {\n *     console.log(users[0].id); // safe\n *     console.log(users[1].id); // not guaranteed!\n *   }\n *\n *   // Solution: optional chaining\n *   console.log(users[1]?.id);\n *   // ➔ safe, even without narrowing\n *   ```\n *\n * - #### Symbols:\n *   ```ts\n *   const secret = Symbol(\"secret\");\n *   const obj2 = { [secret]: 42 };\n *\n *   if (hasOwnProp(obj2, secret)) {\n *     console.log(obj2[secret] + 1);\n *     // ➔ 43\n *   }\n *   ```\n * - #### Strings:\n *   ```ts\n *   if (hasOwnProp(\"hello\", \"length\")) {\n *     console.log(\"hello\".length);\n *     // ➔ 5\n *   }\n *\n *   if (hasOwnProp(\"hello\", 1)) {\n *     console.log(\"hello\"[1]);\n *     // ➔ \"e\"\n *   }\n *   ```\n * - #### Functions:\n *   ```ts\n *   function fn() {}\n *   fn.extra = 123;\n *\n *   if (hasOwnProp(fn, \"extra\")) {\n *     console.log(fn.extra);\n *     // ➔ 123\n *   }\n *   ```\n * - #### Empty key:\n *   ```ts\n *   const obj = { a: 1 };\n *\n *   hasOwnProp(obj, \"\");\n *   // ➔ false (invalid key)\n *   hasOwnProp(obj, \"   \");\n *   // ➔ false (trimmed to empty)\n *   ```\n */\nexport function hasOwnProp<Obj>(\n  obj: IsAny<Obj> extends true ? Obj : never,\n  key: PropertyKey,\n  options?: HasOwnPropOptions<boolean, boolean>\n  /** @ts-expect-error we force `any` to `unknown` at result */\n): obj is unknown;\n\nexport function hasOwnProp<Obj extends null | undefined>(\n  obj: Obj,\n  key: PropertyKey,\n  options?: HasOwnPropOptions<boolean, boolean>\n): false;\n\nexport function hasOwnProp<\n  Obj extends object | AnyFunction,\n  Key extends NestedKeyOfHasOwnProp<Obj>,\n  DiscardUndefined extends boolean = true,\n  DiscardNull extends boolean = false\n>(\n  obj: Obj | null | undefined,\n  key: Key,\n  options?: HasOwnPropOptions<DiscardUndefined, DiscardNull>\n  /** @ts-expect-error we force to override recursive type result */\n): obj is GuardedHasOwnProp<Obj, Key, DiscardUndefined, DiscardNull>;\n\nexport function hasOwnProp<\n  Obj extends object,\n  Num extends NumericKeyOfHasOwnProp<Obj>,\n  DiscardUndefined extends boolean = true,\n  DiscardNull extends boolean = false\n>(\n  obj: Obj | null | undefined,\n  key: Num,\n  options?: HasOwnPropOptions<DiscardUndefined, DiscardNull>\n  /** @ts-expect-error we force to override recursive type result */\n): obj is NumericKeyHasOwnPropMapped<Obj, Num, DiscardUndefined, DiscardNull>;\n\nexport function hasOwnProp<\n  Obj extends object | AnyFunction,\n  Sym extends symbol,\n  DiscardUndefined extends boolean = true,\n  DiscardNull extends boolean = false\n>(\n  obj: Obj | null | undefined,\n  key: Sym,\n  options?: HasOwnPropOptions<DiscardUndefined, DiscardNull>\n  /** @ts-expect-error we force to override recursive type result */\n): obj is DeepRequiredSymbolHasOwnProp<Obj, Sym, DiscardUndefined, DiscardNull>;\n\nexport function hasOwnProp<\n  Obj extends string | null | undefined,\n  Key extends string | number\n>(\n  obj: Obj | null | undefined,\n  key: Key,\n  options?: HasOwnPropOptions<boolean, boolean>\n  /** @ts-expect-error we force to override recursive type result */\n): obj is IsStringLiteral<SmartDetectStringHasOwnProp<Obj, Key>> extends true\n  ? AnyString | SmartDetectStringHasOwnProp<Obj, Key>\n  : SmartDetectStringHasOwnProp<Obj, Key>;\n\nexport function hasOwnProp<\n  Obj extends unknown[] | AnyFunction,\n  Key extends PropertyKey\n>(\n  obj: Obj,\n  key: Key,\n  options?: HasOwnPropOptions<boolean, boolean>\n): obj is SmartDetectArrayFuncHasOwnProp<Obj, Key>;\n\nexport function hasOwnProp<\n  Obj extends unknown | AnyFunction,\n  Key extends PropertyKey,\n  DiscardUndefined extends boolean = true,\n  DiscardNull extends boolean = false\n>(\n  obj: Obj,\n  key:\n    | Key\n    | \"length\"\n    | (IsPlainObjectResult<Obj> extends never ? never : keyof Obj),\n  options?: HasOwnPropOptions<DiscardUndefined, DiscardNull>\n  /** @ts-expect-error we force to override recursive type result */\n): obj is SmartDetectUnknownKeyHasOwnProp<\n  Obj,\n  Key,\n  DiscardUndefined,\n  DiscardNull\n>;\n\n// ------------------- IMPLEMENTATION -------------------\nexport function hasOwnProp(\n  obj: unknown,\n  key: PropertyKey,\n  options: HasOwnPropOptions<boolean, boolean> = {}\n): unknown {\n  if (!isString(obj) && !isObjectOrArray(obj) && !isFunction(obj)) return false;\n\n  if (!isPlainObject(options)) options = {};\n\n  // defaults: undef ➔ true, null ➔ false\n  const discardUndefined =\n    options.discardUndefined === undefined ? true : options.discardUndefined;\n  const discardNull =\n    options.discardNull === undefined ? false : options.discardNull;\n\n  assertIsBoolean(discardUndefined, {\n    message: ({ currentType, validType }) =>\n      errorMsg(\n        `Parameter \\`discardUndefined\\` property of the \\`options\\` (third parameter) must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n      )\n  });\n\n  assertIsBoolean(discardNull, {\n    message: ({ currentType, validType }) =>\n      errorMsg(\n        `Parameter \\`discardNull\\` property of the \\`options\\` (third parameter) must be of type \\`${validType}\\`, but received: \\`${currentType}\\`.`\n      )\n  });\n\n  // Parse key ➔ path\n  const path: (string | number | symbol)[] = [];\n  //todo: keep use manually check for length string value for avoid Maximum infinity loop function.!!!\n  if (\n    (isString(key) && key.trim().length > 0) ||\n    isNumber(key, { includeNaN: true })\n  ) {\n    const strKey = isNumber(key, { includeNaN: true }) ? String(key) : key;\n    strKey.split(\".\").forEach((k) => {\n      const bracketMatch = k.match(/^\\[(\\d+)\\]$/);\n      const symbolMatch = k.match(/^Symbol\\((.+)\\)$/);\n      if (bracketMatch) path.push(Number(bracketMatch[1]));\n      else if (symbolMatch) path.push(Symbol.for(symbolMatch[1]));\n      else if (!isNaN(Number(k))) path.push(Number(k));\n      else path.push(k);\n    });\n  } else if (isSymbol(key)) {\n    path.push(key);\n  } else {\n    return false;\n  }\n\n  // Traverse\n  let current: unknown =\n    isString(obj) && obj.trim().length > 0 ? Object(obj) : obj;\n  for (const k of path) {\n    if (\n      (isString(k) && k.trim().length > 0) ||\n      isNumber(k, { includeNaN: true })\n    ) {\n      if (\n        isNull(current) ||\n        !Object.prototype.hasOwnProperty.call(current, k)\n      ) {\n        return false;\n      }\n      current = (current as Record<PropertyKey, unknown>)[k];\n    } else if (isSymbol(k)) {\n      if (\n        isNull(current) ||\n        (typeof current !== \"object\" && !isFunction(current))\n      ) {\n        return false;\n      }\n      const symbols = Object.getOwnPropertySymbols(current);\n      const matched = symbols.find(\n        (s) => s === k || s.description === k.description\n      );\n      if (!matched) return false;\n      current = (current as Record<PropertyKey, unknown>)[matched];\n    } else {\n      return false;\n    }\n  }\n  // early fail for undefined if requested\n  if (discardUndefined && isUndefined(current)) return false;\n\n  // final null check (only if requested)\n  if (discardNull && isNull(current)) return false;\n\n  return true;\n}\n\n/**\n * @internal ***`Not part of the public API.`***\n */\nconst errorMs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