{"version":3,"file":"assertIsString-EZG51Yvm.cjs","names":["isString"],"sources":["../src/assertions/strings/assertIsString.ts"],"sourcesContent":["import { isString } from \"@/predicates/is/isString\";\nimport {\n  resolveErrorMessageAssertions,\n  type OptionsAssertIs\n} from \"../_private/assertIs\";\n\n/** --------------------------------------------------------------------------------\n * * ***Type guard assertion: `assertIsString`.***\n * ---------------------------------------------------------------------------------\n * **This function is an **assertion function**.**\n *\n * - **Behavior:**\n *     - Validates that the given `value` is a **primitive-string**.\n *     - After it returns successfully, TypeScript narrows the type of `value` to `primitive-string`.\n *     - If `value` is a `primitive-string` ➔ execution continues normally.\n *     - If `value` is not a `primitive-string` ➔ throws a built-in error with either:\n *       - A custom error message (`options.message`), or\n *       - A default message including the actual type.\n * - **Note:**\n *     - A \"string\" refers strictly to a JavaScript `primitive-string` type (e.g., `\"hello\"`, `\"\"`, `\"123\"`).\n *     - This function excludes `String` objects created with `new String()`.\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 * @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 a primitive string.\n * @returns {boolean} Narrows `value` to `string` if no error is thrown.\n *\n * @example\n * ```ts\n * // ✅ Simple usage\n * assertIsString(\"hello\");\n * // No error, value is string\n *\n * // ❌ Throws TypeError (default behavior)\n * // Case 1: Invalid input type — received a string instead of a string\n * assertIsString(42);\n * // ➔ TypeError: \"Parameter input (`value`) must be of type `string`, but received: `number`.\"\n *\n * // Case 3: The new String() is a String object (constructor), not a primitive string\n * assertIsString(new String(\"abc\"));\n * // ➔ TypeError: \"Parameter input (`value`) must be of type `string`, but received: `string-constructor`.\"\n *\n * // ❌ Throws custom error type (e.g., RangeError)\n * assertIsString(async function () {}, { errorType: \"RangeError\" });\n * // ➔ RangeError: \"Parameter input (`value`) must be of type `string`, but received: `async-function`.\"\n *\n * // ❌ Throws a TypeError with a custom string static message\n * assertIsString(123, { message: \"Must be a string!\" });\n * // ➔ TypeError: \"Must be a string!\"\n *\n * // ❌ Throws a TypeError with a custom message function and formatCase\n * assertIsString(/regex/, {\n *   message: ({ currentType, validType }) => {\n *     return `Expected ${validType} but got (${currentType}).`\n *   },\n *   formatCase: \"toPascalCaseSpace\"\n * });\n * // ➔ TypeError: \"Expected string but got (Reg Exp).\"\n *\n * // ❌ Throws a TypeError with a custom useAcronyms option\n * // Case 1:\n * assertIsString(new URL(\"https://example.com\"),{\n *   message: ({ currentType, validType }) => {\n *     return `Expected ${validType} but got (${currentType}).`\n *   },\n * });\n * // ➔ TypeError: \"Expected string but got (url).\"\n * assertIsString(new URL(\"https://example.com\"), {\n *   useAcronyms: true,\n *   message: ({ currentType, validType }) => {\n *     return `Expected ${validType} but got (${currentType}).`\n *   },\n * });\n * // ➔ TypeError: \"Expected string but got (URL).\"\n *\n * // Case 2:\n * assertIsString(new URLSearchParams, {\n *   formatCase: \"toPascalCase\",\n *   message: ({ currentType, validType }) => {\n *     return `Expected ${validType} but got (${currentType}).`\n *   },\n * });\n * // ➔ TypeError: \"Expected string but got (UrlSearchParams).\"\n * assertIsString(new URLSearchParams, {\n *   useAcronyms: true,\n *   formatCase: \"toPascalCase\",\n *   message: ({ currentType, validType }) => {\n *     return `Expected ${validType} but got (${currentType}).`\n *   },\n * });\n * // ➔ TypeError: \"Expected string but got (URLSearchParams).\"\n * ```\n * -------------------------------------------------------\n * ✅ ***Real-world usage with generic narrowing***:\n * ```ts\n * const mixedValue: string | boolean | undefined = getUserInput();\n *\n * // Runtime assertion: throws if `mixedValue` is not a `string`\n * assertIsString(mixedValue, {\n *   errorType: \"RangeError\",\n *   message: \"Must be a string!\"\n * });\n *\n * // ✅ If no error thrown, TypeScript narrows `mixedValue` to `string` here\n * const result: string = mixedValue; // ➔ Safe type assignment\n * console.log(result.toUpperCase()); // ➔ Safe to call String.prototype methods\n * ```\n */\nexport const assertIsString: (\n  value: unknown,\n  options?: OptionsAssertIs\n) => asserts value is string = (\n  value: unknown,\n  options?: OptionsAssertIs\n): asserts value is string => {\n  if (isString(value)) return;\n\n  resolveErrorMessageAssertions({\n    value,\n    options,\n    requiredValidType: \"string\"\n  });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6HA,MAAa,kBAIX,OACA,YAC4B;CAC5B,IAAIA,wBAAS,KAAK,GAAG;CAErB,6CAA8B;EAC5B;EACA;EACA,mBAAmB;CACrB,CAAC;AACH"}
