{"version":3,"sources":["../../src/assertDefinedEx.ts","../../src/assertEx.ts"],"sourcesContent":["import type { AssertExErrorFunc, AssertExMessageFunc } from './types.ts'\n\n/**\n * Asserts that a value is defined (not undefined) and returns the value.\n * Throws an error if the value is undefined.\n *\n * @template T - The type of value to check\n * @param expr - Expression to be evaluated for being defined\n * @param messageFunc - Function that returns a message for the error if expression is undefined\n * @throws Error with the message returned by messageFunc\n * @returns The value of the expression (guaranteed to be defined)\n * @example\n * ```typescript\n * // Simple usage with a message function\n * const value = assertDefinedEx(possiblyUndefined, () => 'Value must be defined')\n *\n * // Using with type narrowing\n * const config: Config | undefined = loadConfig()\n * const safeConfig = assertDefinedEx(config, () => 'Config failed to load')\n * // safeConfig is now type Config (not Config | undefined)\n * ```\n */\nfunction assertDefinedEx<T>(expr: T | undefined, messageFunc?: AssertExMessageFunc<T>): T\n\n/**\n * Asserts that a value is defined (not undefined) and returns the value.\n * Throws a custom error if the value is undefined.\n *\n * @template T - The type of value to check\n * @template R - The type of error to throw\n * @param expr - Expression to be evaluated for being defined\n * @param errorFunc - Function that returns a custom error instance if expression is undefined\n * @throws Custom error returned by errorFunc\n * @returns The value of the expression (guaranteed to be defined)\n * @example\n * ```typescript\n * // Using with a custom error\n * const user = assertDefinedEx(getUser(), () => new UserNotFoundError('User not found'))\n * ```\n */\nfunction assertDefinedEx<T, R extends Error>(expr: T | undefined, errorFunc?: AssertExErrorFunc<T, R>): T\n\n/**\n * Implementation of assertDefinedEx that handles all overloads.\n *\n */\nfunction assertDefinedEx<T, R extends Error, P extends AssertExMessageFunc<T> | AssertExErrorFunc<T, R>>(\n  expr: T | undefined,\n  func?: P,\n): T {\n  if (expr !== undefined) return expr\n  if (typeof func === 'function') {\n    const errorOrMessage = func(expr)\n    throw typeof errorOrMessage === 'string' ? new Error(errorOrMessage) : errorOrMessage\n  }\n  if (func !== undefined) {\n    throw new Error('Invalid assertEx usage: second argument must be a function or undefined')\n  }\n  throw new Error('Assertion failed: value is undefined')\n}\n\nexport { assertDefinedEx }\n","import type { AssertExErrorFunc, AssertExMessageFunc } from './types.ts'\n\n/**\n * Asserts that an expression is truthy and returns the value.\n * Throws an error if the expression is falsy.\n *\n * @template T - The type of value to check\n * @param expr - Expression to be evaluated for truthiness\n * @param messageFunc - Function that returns a message for the error if expression is falsy\n * @throws Error with the message returned by messageFunc\n * @returns The value of the expression (guaranteed to be truthy)\n * @example\n * ```typescript\n * // Simple usage with a message function\n * const value = assertEx(possiblyFalsy, () => 'Value must be truthy')\n *\n * // Using with type narrowing\n * const config: Config | null = loadConfig()\n * const safeConfig = assertEx(config, () => 'Config failed to load')\n * // safeConfig is now type Config (not Config | null)\n * ```\n */\nfunction assertEx<T>(expr: T | null | undefined, messageFunc?: AssertExMessageFunc<T>): T\n\n/**\n * Asserts that an expression is truthy and returns the value.\n * Throws a custom error if the expression is falsy.\n *\n * @template T - The type of value to check\n * @template R - The type of error to throw\n * @param expr - Expression to be evaluated for truthiness\n * @param errorFunc - Function that returns a custom error instance if expression is falsy\n * @throws Custom error returned by errorFunc\n * @returns The value of the expression (guaranteed to be truthy)\n * @example\n * ```typescript\n * // Using with a custom error\n * const user = assertEx(getUser(), () => new UserNotFoundError('User not found'))\n * ```\n */\nfunction assertEx<T, R extends Error>(expr: T | null | undefined, errorFunc?: AssertExErrorFunc<T, R>): T\n\n/**\n * Implementation of assertEx that handles all overloads.\n */\nfunction assertEx<T, R extends Error, P extends AssertExMessageFunc<T> | AssertExErrorFunc<T, R>>(\n  expr: T | null | undefined,\n  func?: P,\n): T {\n  // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n  if (expr) return expr\n  if (typeof func === 'function') {\n    const errorOrMessage = func(expr)\n    throw typeof errorOrMessage === 'string' ? new Error(errorOrMessage) : errorOrMessage\n  }\n  if (func !== undefined) {\n    throw new Error('Invalid assertEx usage: second argument must be a function or undefined')\n  }\n  throw new Error('Assertion failed')\n}\n\nexport { assertEx }\n"],"mappings":";AA8CA,SAAS,gBACP,MACA,MACG;AACH,MAAI,SAAS,OAAW,QAAO;AAC/B,MAAI,OAAO,SAAS,YAAY;AAC9B,UAAM,iBAAiB,KAAK,IAAI;AAChC,UAAM,OAAO,mBAAmB,WAAW,IAAI,MAAM,cAAc,IAAI;AAAA,EACzE;AACA,MAAI,SAAS,QAAW;AACtB,UAAM,IAAI,MAAM,yEAAyE;AAAA,EAC3F;AACA,QAAM,IAAI,MAAM,sCAAsC;AACxD;;;ACdA,SAAS,SACP,MACA,MACG;AAEH,MAAI,KAAM,QAAO;AACjB,MAAI,OAAO,SAAS,YAAY;AAC9B,UAAM,iBAAiB,KAAK,IAAI;AAChC,UAAM,OAAO,mBAAmB,WAAW,IAAI,MAAM,cAAc,IAAI;AAAA,EACzE;AACA,MAAI,SAAS,QAAW;AACtB,UAAM,IAAI,MAAM,yEAAyE;AAAA,EAC3F;AACA,QAAM,IAAI,MAAM,kBAAkB;AACpC;","names":[]}