{"version":3,"file":"assertIsPlainObject-B18wIxEr.cjs","names":["isPlainObject"],"sources":["../src/assertions/objects/assertIsPlainObject.ts"],"sourcesContent":["import {\n  isPlainObject,\n  type IsPlainObjectResult\n} from \"@/predicates/is/isPlainObject\";\nimport {\n  type OptionsAssertIs,\n  resolveErrorMessageAssertions\n} from \"../_private/assertIs\";\n\n/** --------------------------------------------------------------------------------\n * * ***Type guard assertion: `assertIsPlainObject`.***\n * ---------------------------------------------------------------------------------\n * **This function is an **assertion function**.**\n *\n * - **Behavior:**\n *     - Validates that the given `value` is a **plain-object**.\n *     - After it returns successfully, TypeScript narrows the type of `value` to `plain-object` **(generic support)**.\n *     - If `value` is a `plain-object` ➔ execution continues normally.\n *     - If `value` is not a `plain-object` ➔ throws a built-in error with either:\n *       - A custom error message (`options.message`), or\n *       - A default message including the actual type.\n * - **A valid `plain object` is:**\n *     - Created by the `Object` constructor, or\n *     - Has a `[[Prototype]]` of `null` (e.g. `Object.create(null)`).\n *      - **Returns `undefined` (valid) for:**\n *          - Empty object literals: `{}`\n *          - Objects with null prototype: `Object.create(null)`\n *      - **Returns `throws` for:**\n *          - Arrays (`[]`, `new Array()`)\n *          - Functions (regular, arrow, or class constructors)\n *          - Built-in objects: `Date`, `RegExp`, `Error`, `Map`, `Set`, `WeakMap`, `WeakSet`\n *          - Boxed primitives: `new String()`, `new Number()`, `new Boolean()`\n *          - `null` or `undefined`\n *          - Symbols\n *          - Class instances\n * - **Error type selection (`options.errorType`):**\n *     - You can override the type of error thrown when validation fails.\n *     - Must be one of the standard JavaScript built-in errors:\n *       - [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) |\n *         [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) |\n *         [`EvalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError) |\n *         [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) |\n *         [`ReferenceError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError) |\n *         [`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError) |\n *         [`URIError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError).\n *     - **Default:** `\"TypeError\"` if not provided or invalid.\n *\n * @template T - The input type being asserted.\n * @param {*} value - ***The value to validate.***\n * @param {OptionsAssertIs} [options]\n *  ***Optional configuration:***\n *     - `message`: A custom error message (`string` or `function`).\n *     - `errorType`: Built-in JavaScript error type to throw on failure (default `\"TypeError\"`).\n *     - `formatCase`: Controls how detected type names are formatted case in error messages.\n *     - `useAcronyms`: Control uppercase preservation of recognized acronyms during formatting.\n *\n * @throws [`TypeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError) | [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) | [`EvalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError) | [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError) | [`ReferenceError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError) | [`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError) | [`URIError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError) if `value` is not a plain-object.\n * @returns {boolean} Narrows `value` to a `plain-object` **(generic support)** if no error is thrown.\n *\n * @example\n * ```ts\n * // ✅ Simple usage\n * assertIsPlainObject({ a: 1, b: 2 });\n * // No error, value is plain-object\n *\n * // ❌ Throws TypeError (default behavior)\n * // Case 1: Invalid input type — received a string instead of a plain-object\n * assertIsPlainObject(\"42\");\n * // ➔ TypeError: \"Parameter input (`value`) must be of type `plain-object`, but received: `string`.\"\n *\n * // ❌ Throws custom error type (e.g., RangeError)\n * assertIsPlainObject(async function () {}, { errorType: \"RangeError\" });\n * // ➔ RangeError: \"Parameter input (`value`) must be of type `plain-object`, but received: `async-function`.\"\n *\n * // ❌ Throws a TypeError with a custom string static message\n * assertIsPlainObject(\"123\", { message: \"Must be a plain-object!\" });\n * // ➔ TypeError: \"Must be a plain-object!\"\n *\n * // ❌ Throws a TypeError with a custom message function and formatCase\n * assertIsPlainObject(/regex/, {\n *   message: ({ currentType, validType }) => {\n *     return `Expected ${validType} but got (${currentType}).`\n *   },\n *   formatCase: \"toPascalCaseSpace\"\n * });\n * // ➔ TypeError: \"Expected plain-object but got (Reg Exp).\"\n *\n * // ❌ Throws a TypeError with a custom useAcronyms option\n * // Case 1:\n * assertIsPlainObject(new URL(\"https://example.com\"),{\n *   message: ({ currentType, validType }) => {\n *     return `Expected ${validType} but got (${currentType}).`\n *   },\n * });\n * // ➔ TypeError: \"Expected plain-object but got (url).\"\n * assertIsPlainObject(new URL(\"https://example.com\"), {\n *   useAcronyms: true,\n *   message: ({ currentType, validType }) => {\n *     return `Expected ${validType} but got (${currentType}).`\n *   },\n * });\n * // ➔ TypeError: \"Expected plain-object but got (URL).\"\n *\n * // Case 2:\n * assertIsPlainObject(new URLSearchParams, {\n *   formatCase: \"toPascalCase\",\n *   message: ({ currentType, validType }) => {\n *     return `Expected ${validType} but got (${currentType}).`\n *   },\n * });\n * // ➔ TypeError: \"Expected plain-object but got (UrlSearchParams).\"\n * assertIsPlainObject(new URLSearchParams, {\n *   useAcronyms: true,\n *   formatCase: \"toPascalCase\",\n *   message: ({ currentType, validType }) => {\n *     return `Expected ${validType} but got (${currentType}).`\n *   },\n * });\n * // ➔ TypeError: \"Expected plain-object but got (URLSearchParams).\"\n * ```\n * -------------------------------------------------------\n * ✅ ***Real-world usage with generic narrowing***:\n * ```ts\n * type User = { name: string; email: string };\n * const mixedValue: string | User | boolean | number | undefined = getUserInput();\n *\n * // Runtime assertion: throws if `mixedValue` is not a `plain-object`\n * assertIsPlainObject(mixedValue, {\n *   errorType: \"RangeError\",\n *   message: \"Must be plain object!\"\n * });\n *\n * // ✅ If no error thrown, TypeScript narrows `mixedValue` to `User` here\n * const user: User = mixedValue; // ➔ Safe type assignment\n * console.log(user.email);       // ➔ Safe to access object properties\n * ```\n */\nexport function assertIsPlainObject<T>(\n  value: T,\n  options?: OptionsAssertIs\n): asserts value is IsPlainObjectResult<T> {\n  if (isPlainObject(value)) return;\n\n  resolveErrorMessageAssertions({\n    value,\n    options,\n    requiredValidType: \"plain object\"\n  });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyIA,SAAgB,oBACd,OACA,SACyC;CACzC,IAAIA,6BAAc,KAAK,GAAG;CAE1B,6CAA8B;EAC5B;EACA;EACA,mBAAmB;CACrB,CAAC;AACH"}
