@xylabs/assert
Advanced tools
@@ -1,4 +0,2 @@ | ||
| export * from './assertDefinedEx.ts'; | ||
| export * from './assertEx.ts'; | ||
| export type * from './types.ts'; | ||
| export * from '@ariestools/sdk/assert'; | ||
| //# sourceMappingURL=index.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,eAAe,CAAA;AAC7B,mBAAmB,YAAY,CAAA"} | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA"} |
@@ -1,30 +0,3 @@ | ||
| // src/assertDefinedEx.ts | ||
| function assertDefinedEx(expr, func) { | ||
| if (expr !== void 0) return expr; | ||
| if (typeof func === "function") { | ||
| const errorOrMessage = func(expr); | ||
| throw typeof errorOrMessage === "string" ? new Error(errorOrMessage) : errorOrMessage; | ||
| } | ||
| if (func !== void 0) { | ||
| throw new Error("Invalid assertDefinedEx usage: second argument must be a function or undefined"); | ||
| } | ||
| throw new Error("Assertion failed: value is undefined"); | ||
| } | ||
| // src/assertEx.ts | ||
| function assertEx(expr, func) { | ||
| if (expr !== void 0 && expr !== null && expr !== false && expr !== 0 && expr !== "" && expr !== 0n) return expr; | ||
| if (typeof func === "function") { | ||
| const errorOrMessage = func(expr); | ||
| throw typeof errorOrMessage === "string" ? new Error(errorOrMessage) : errorOrMessage; | ||
| } | ||
| if (func !== void 0) { | ||
| throw new Error("Invalid assertEx usage: second argument must be a function or undefined"); | ||
| } | ||
| throw new Error("Assertion failed"); | ||
| } | ||
| export { | ||
| assertDefinedEx, | ||
| assertEx | ||
| }; | ||
| // src/index.ts | ||
| export * from "@ariestools/sdk/assert"; | ||
| //# sourceMappingURL=index.mjs.map |
| { | ||
| "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 assertDefinedEx 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 if (expr !== undefined && expr !== null && expr !== false && expr !== 0 && expr !== '' && expr !== 0n) 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,gFAAgF;AAAA,EAClG;AACA,QAAM,IAAI,MAAM,sCAAsC;AACxD;;;ACdA,SAAS,SACP,MACA,MACG;AACH,MAAI,SAAS,UAAa,SAAS,QAAQ,SAAS,SAAS,SAAS,KAAK,SAAS,MAAM,SAAS,GAAI,QAAO;AAC9G,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;", | ||
| "sources": ["../../src/index.ts"], | ||
| "sourcesContent": ["export * from '@ariestools/sdk/assert'\n"], | ||
| "mappings": ";AAAA,cAAc;", | ||
| "names": [] | ||
| } |
@@ -1,2 +0,2 @@ | ||
| export type * from './types.ts'; | ||
| export type * from '@ariestools/sdk/assert/model'; | ||
| //# sourceMappingURL=model.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/model.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA"} | ||
| {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/model.ts"],"names":[],"mappings":"AAAA,mBAAmB,8BAA8B,CAAA"} |
+21
-9
| { | ||
| "name": "@xylabs/assert", | ||
| "version": "7.0.2", | ||
| "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries", | ||
| "version": "7.0.3", | ||
| "description": "DEPRECATED — use @ariestools/sdk/assert. Backward-compatibility re-export shim.", | ||
| "keywords": [ | ||
@@ -33,7 +33,7 @@ "xylabs", | ||
| }, | ||
| "./package.json": "./package.json", | ||
| "./model": { | ||
| "types": "./dist/neutral/model.d.ts", | ||
| "default": "./dist/neutral/model.mjs" | ||
| }, | ||
| "./package.json": "./package.json" | ||
| } | ||
| }, | ||
@@ -47,5 +47,11 @@ "files": [ | ||
| ], | ||
| "dependencies": { | ||
| "@ariestools/sdk": "~7.0.3" | ||
| }, | ||
| "devDependencies": { | ||
| "@xylabs/toolchain": "^8.5.3", | ||
| "@xylabs/tsconfig": "^8.5.3", | ||
| "@opentelemetry/api": "^1.9.1", | ||
| "@opentelemetry/sdk-trace-base": "^2.8.0", | ||
| "@xylabs/toolchain": "^8.5.5", | ||
| "@xylabs/tsconfig": "^8.5.5", | ||
| "async-mutex": "^0.5.0", | ||
| "browserslist": "4.28.4", | ||
@@ -55,5 +61,10 @@ "eslint": "^10.6.0", | ||
| "typescript": "^6.0.3", | ||
| "vite": "^8.1.0", | ||
| "vitest": "^4.1.9" | ||
| "zod": "^4.4.3" | ||
| }, | ||
| "peerDependencies": { | ||
| "@opentelemetry/api": "^1.9", | ||
| "@opentelemetry/sdk-trace-base": "^2.7", | ||
| "async-mutex": "^0.5", | ||
| "zod": "^4.4" | ||
| }, | ||
| "engines": { | ||
@@ -64,3 +75,4 @@ "node": ">=18" | ||
| "access": "public" | ||
| } | ||
| }, | ||
| "deprecated": "Use @ariestools/sdk/assert instead. @xylabs/assert is a compatibility shim only and will not receive further updates." | ||
| } |
+6
-4
@@ -0,1 +1,3 @@ | ||
| > **Deprecated.** Use [`@ariestools/sdk`](../../ariestools-sdk/README.md) instead. This package is a backward-compatibility re-export shim. | ||
| [![logo][]](https://xylabs.com) | ||
@@ -15,3 +17,3 @@ | ||
| ```sh | ||
| npm install {{name}} | ||
| npm install @xylabs/assert | ||
| ``` | ||
@@ -22,3 +24,3 @@ | ||
| ```sh | ||
| yarn add {{name}} | ||
| yarn add @xylabs/assert | ||
| ``` | ||
@@ -29,3 +31,3 @@ | ||
| ```sh | ||
| pnpm add {{name}} | ||
| pnpm add @xylabs/assert | ||
| ``` | ||
@@ -36,3 +38,3 @@ | ||
| ```sh | ||
| bun add {{name}} | ||
| bun add @xylabs/assert | ||
| ``` | ||
@@ -39,0 +41,0 @@ |
| import type { AssertExErrorFunc, AssertExMessageFunc } from './types.ts'; | ||
| /** | ||
| * Asserts that a value is defined (not undefined) and returns the value. | ||
| * Throws an error if the value is undefined. | ||
| * | ||
| * @template T - The type of value to check | ||
| * @param expr - Expression to be evaluated for being defined | ||
| * @param messageFunc - Function that returns a message for the error if expression is undefined | ||
| * @throws Error with the message returned by messageFunc | ||
| * @returns The value of the expression (guaranteed to be defined) | ||
| * @example | ||
| * ```typescript | ||
| * // Simple usage with a message function | ||
| * const value = assertDefinedEx(possiblyUndefined, () => 'Value must be defined') | ||
| * | ||
| * // Using with type narrowing | ||
| * const config: Config | undefined = loadConfig() | ||
| * const safeConfig = assertDefinedEx(config, () => 'Config failed to load') | ||
| * // safeConfig is now type Config (not Config | undefined) | ||
| * ``` | ||
| */ | ||
| declare function assertDefinedEx<T>(expr: T | undefined, messageFunc?: AssertExMessageFunc<T>): T; | ||
| /** | ||
| * Asserts that a value is defined (not undefined) and returns the value. | ||
| * Throws a custom error if the value is undefined. | ||
| * | ||
| * @template T - The type of value to check | ||
| * @template R - The type of error to throw | ||
| * @param expr - Expression to be evaluated for being defined | ||
| * @param errorFunc - Function that returns a custom error instance if expression is undefined | ||
| * @throws Custom error returned by errorFunc | ||
| * @returns The value of the expression (guaranteed to be defined) | ||
| * @example | ||
| * ```typescript | ||
| * // Using with a custom error | ||
| * const user = assertDefinedEx(getUser(), () => new UserNotFoundError('User not found')) | ||
| * ``` | ||
| */ | ||
| declare function assertDefinedEx<T, R extends Error>(expr: T | undefined, errorFunc?: AssertExErrorFunc<T, R>): T; | ||
| export { assertDefinedEx }; | ||
| //# sourceMappingURL=assertDefinedEx.d.ts.map |
| {"version":3,"file":"assertDefinedEx.d.ts","sourceRoot":"","sources":["../../src/assertDefinedEx.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAExE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,iBAAS,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,SAAS,EAAE,WAAW,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAEzF;;;;;;;;;;;;;;;GAeG;AACH,iBAAS,eAAe,CAAC,CAAC,EAAE,CAAC,SAAS,KAAK,EAAE,IAAI,EAAE,CAAC,GAAG,SAAS,EAAE,SAAS,CAAC,EAAE,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAA;AAqBzG,OAAO,EAAE,eAAe,EAAE,CAAA"} |
| import type { AssertExErrorFunc, AssertExMessageFunc } from './types.ts'; | ||
| /** | ||
| * Asserts that an expression is truthy and returns the value. | ||
| * Throws an error if the expression is falsy. | ||
| * | ||
| * @template T - The type of value to check | ||
| * @param expr - Expression to be evaluated for truthiness | ||
| * @param messageFunc - Function that returns a message for the error if expression is falsy | ||
| * @throws Error with the message returned by messageFunc | ||
| * @returns The value of the expression (guaranteed to be truthy) | ||
| * @example | ||
| * ```typescript | ||
| * // Simple usage with a message function | ||
| * const value = assertEx(possiblyFalsy, () => 'Value must be truthy') | ||
| * | ||
| * // Using with type narrowing | ||
| * const config: Config | null = loadConfig() | ||
| * const safeConfig = assertEx(config, () => 'Config failed to load') | ||
| * // safeConfig is now type Config (not Config | null) | ||
| * ``` | ||
| */ | ||
| declare function assertEx<T>(expr: T | null | undefined, messageFunc?: AssertExMessageFunc<T>): T; | ||
| /** | ||
| * Asserts that an expression is truthy and returns the value. | ||
| * Throws a custom error if the expression is falsy. | ||
| * | ||
| * @template T - The type of value to check | ||
| * @template R - The type of error to throw | ||
| * @param expr - Expression to be evaluated for truthiness | ||
| * @param errorFunc - Function that returns a custom error instance if expression is falsy | ||
| * @throws Custom error returned by errorFunc | ||
| * @returns The value of the expression (guaranteed to be truthy) | ||
| * @example | ||
| * ```typescript | ||
| * // Using with a custom error | ||
| * const user = assertEx(getUser(), () => new UserNotFoundError('User not found')) | ||
| * ``` | ||
| */ | ||
| declare function assertEx<T, R extends Error>(expr: T | null | undefined, errorFunc?: AssertExErrorFunc<T, R>): T; | ||
| export { assertEx }; | ||
| //# sourceMappingURL=assertEx.d.ts.map |
| {"version":3,"file":"assertEx.d.ts","sourceRoot":"","sources":["../../src/assertEx.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAExE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,iBAAS,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,EAAE,WAAW,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;AAEzF;;;;;;;;;;;;;;;GAeG;AACH,iBAAS,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,KAAK,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,EAAE,SAAS,CAAC,EAAE,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAA;AAoBzG,OAAO,EAAE,QAAQ,EAAE,CAAA"} |
| /** | ||
| * @internal | ||
| * A function that takes a possibly null or undefined value and returns an error message string. | ||
| * Used in assertion functions to provide custom error messages. | ||
| * | ||
| * @internal | ||
| * @template T - The type of value being asserted | ||
| * @param value - The value being asserted (may be null or undefined) | ||
| * @returns A string message to be used in the error thrown by the assertion | ||
| * @example | ||
| * ```typescript | ||
| * const messageFunc: AssertExMessageFunc<User> = (user) => | ||
| * `User ${user ? user.id : 'unknown'} is not valid or accessible` | ||
| * ``` | ||
| */ | ||
| export type AssertExMessageFunc<T> = (value?: T | null) => string; | ||
| /** | ||
| * A function that takes a possibly null or undefined value and returns a custom error instance. | ||
| * Used in assertion functions to provide specific error types with custom properties. | ||
| * | ||
| * @internal | ||
| * @template T - The type of value being asserted | ||
| * @template R - The specific error type to be returned, must extend Error | ||
| * @param value - The value being asserted (may be null or undefined) | ||
| * @returns An instance of the custom error type | ||
| * @example | ||
| * ```typescript | ||
| * const errorFunc: AssertExErrorFunc<User, UserNotFoundError> = (user) => | ||
| * new UserNotFoundError(`User ${user?.id || 'unknown'} not found`, { | ||
| * userId: user?.id, | ||
| * timestamp: new Date() | ||
| * }) | ||
| * ``` | ||
| */ | ||
| export type AssertExErrorFunc<T, R extends Error> = (value?: T | null) => R; | ||
| //# sourceMappingURL=types.d.ts.map |
| {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,KAAK,MAAM,CAAA;AAEjE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,EAAE,CAAC,SAAS,KAAK,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,KAAK,CAAC,CAAA"} |
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
292
0.69%15230
-44.87%5
Infinity%10
25%11
-35.29%6
-95.97%1
Infinity%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added