@xylabs/assert 5.1.1 → 5.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/neutral/index.mjs
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/assertDefinedEx.ts", "../../src/assertEx.ts"],
|
|
4
|
+
"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"],
|
|
5
|
+
"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;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/assert",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.3",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xylabs",
|
|
@@ -40,12 +40,12 @@
|
|
|
40
40
|
"README.md"
|
|
41
41
|
],
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@xylabs/toolchain": "~
|
|
44
|
-
"@xylabs/tsconfig": "~
|
|
43
|
+
"@xylabs/toolchain": "~8.0.4",
|
|
44
|
+
"@xylabs/tsconfig": "~8.0.4",
|
|
45
45
|
"eslint": "^10.3.0",
|
|
46
|
-
"typescript": "^
|
|
47
|
-
"vite": "^8.0.
|
|
48
|
-
"vitest": "^4.1.
|
|
46
|
+
"typescript": "^6.0.3",
|
|
47
|
+
"vite": "^8.0.13",
|
|
48
|
+
"vitest": "^4.1.6"
|
|
49
49
|
},
|
|
50
50
|
"engines": {
|
|
51
51
|
"node": ">=18"
|