{"version":3,"file":"assertIsArray-TE5jQ7XY.cjs","names":["isArray"],"sources":["../src/assertions/objects/assertIsArray.ts"],"sourcesContent":["import type {\n  IsArray,\n  IsReadonlyArray,\n  IsUnknown\n} from \"@rzl-zone/ts-types-plus\";\nimport type { ArrayFallback } from \"@/_private/types.arrays\";\n\nimport { isArray } from \"@/predicates/is/isArray\";\n\nimport {\n  resolveErrorMessageAssertions,\n  type OptionsAssertIs\n} from \"../_private/assertIs\";\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ntype AssertIsArrayResult<T> =\n  IsUnknown<T> extends true\n    ? unknown[] & T\n    : IsReadonlyArray<T> extends true\n      ? T\n      : T extends []\n        ? T\n        : IsArray<T> extends true\n          ? T\n          : Extract<T, unknown[] | [] | readonly []>;\n\n/** --------------------------------------------------------------------------------\n * * ***Type guard assertion: `assertIsArray`.***\n * ---------------------------------------------------------------------------------\n * **This function is an **assertion function**.**\n *\n * - **Behavior:**\n *     - Validates that the given `value` is an **array**.\n *     - After it returns successfully, TypeScript narrows the type of `value` to `array` **(generic support)**.\n *     - If `value` is an `array` ➔ execution continues normally.\n *     - If `value` is not an `array` ➔ throws a built-in error with either:\n *       - A custom error message (`options.message`), or\n *       - A default message including the actual type.\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 the value is not an array.\n * @returns {boolean} Narrows `value` to an `array` **(generic support)** if no error is thrown.\n *\n * @example\n * ```ts\n * // ✅ Simple usage\n * assertIsArray([]);\n * assertIsArray([\"123\", 456]);\n * assertIsArray(Array.from([\"abc\"]));\n * // No error, value is array\n *\n * // ❌ Throws TypeError (default behavior)\n * // Case 1: Invalid input type — received a string instead of a array\n * assertIsArray(\"42\");\n * // ➔ TypeError: \"Parameter input (`value`) must be of type `array`, but received: `string`.\"\n *\n * // ❌ Throws custom error type (e.g., RangeError)\n * assertIsArray(async function () {}, { errorType: \"RangeError\" });\n * // ➔ RangeError: \"Parameter input (`value`) must be of type `array`, but received: `async-function`.\"\n *\n * // ❌ Throws a TypeError with a custom string static message\n * assertIsArray(\"123\", { message: \"Must be a array!\" });\n * // ➔ TypeError: \"Must be a array!\"\n *\n * // ❌ Throws a TypeError with a custom message function and formatCase\n * assertIsArray(/regex/, {\n *   message: ({ currentType, validType }) => {\n *     return `Expected ${validType} but got (${currentType}).`\n *   },\n *   formatCase: \"toPascalCaseSpace\"\n * });\n * // ➔ TypeError: \"Expected array but got (Reg Exp).\"\n *\n * // ❌ Throws a TypeError with a custom useAcronyms option\n * // Case 1:\n * assertIsArray(new URL(\"https://example.com\"),{\n *   message: ({ currentType, validType }) => {\n *     return `Expected ${validType} but got (${currentType}).`\n *   },\n * });\n * // ➔ TypeError: \"Expected array but got (url).\"\n * assertIsArray(new URL(\"https://example.com\"), {\n *   useAcronyms: true,\n *   message: ({ currentType, validType }) => {\n *     return `Expected ${validType} but got (${currentType}).`\n *   },\n * });\n * // ➔ TypeError: \"Expected array but got (URL).\"\n *\n * // Case 2:\n * assertIsArray(new URLSearchParams, {\n *   formatCase: \"toPascalCase\",\n *   message: ({ currentType, validType }) => {\n *     return `Expected ${validType} but got (${currentType}).`\n *   },\n * });\n * // ➔ TypeError: \"Expected array but got (UrlSearchParams).\"\n * assertIsArray(new URLSearchParams, {\n *   useAcronyms: true,\n *   formatCase: \"toPascalCase\",\n *   message: ({ currentType, validType }) => {\n *     return `Expected ${validType} but got (${currentType}).`\n *   },\n * });\n * // ➔ TypeError: \"Expected array but got (URLSearchParams).\"\n * ```\n * -------------------------------------------------------\n * ✅ ***Real-world usage example***:\n * ```ts\n * const mixedValue: string | number[] | undefined = getUserInput();\n *\n * // Runtime assertion: throws if `mixedValue` is not a `number[]`\n * assertIsArray(mixedValue, {\n *   errorType: \"RangeError\",\n *   message: \"Must be array!\"\n * });\n *\n * // ✅ If no error thrown, TypeScript narrows `mixedValue` to `number[]` here\n * const result: number[] = mixedValue; // ➔ Safe type assignment\n * console.log(result.push(1, 2, 3));   // ➔ Safe to use array methods\n * ```\n */\nexport function assertIsArray(\n  value: [],\n  options?: OptionsAssertIs\n): asserts value is [];\nexport function assertIsArray<T>(\n  value: T,\n  options?: OptionsAssertIs\n): asserts value is ArrayFallback<T>;\nexport function assertIsArray(\n  value: unknown,\n  options?: OptionsAssertIs\n): asserts value is unknown[];\nexport function assertIsArray<T>(value: T, options?: OptionsAssertIs) {\n  if (isArray(value)) return;\n\n  resolveErrorMessageAssertions({ value, options, requiredValidType: \"array\" });\n}\n"],"mappings":";;;;;;;;;;;;;AAyJA,SAAgB,cAAiB,OAAU,SAA2B;CACpE,IAAIA,uBAAQ,KAAK,GAAG;CAEpB,6CAA8B;EAAE;EAAO;EAAS,mBAAmB;CAAQ,CAAC;AAC9E"}
