@xylabs/error
Advanced tools
@@ -6,3 +6,3 @@ // src/assert.ts | ||
| const assertString = typeof assert === "string" ? assert : typeof assert === "boolean" ? defaultMessage : assert(value, defaultMessage); | ||
| if (isString(assertString) || assertString === true) { | ||
| if (isString(assertString) || assertString) { | ||
| throw new Error(assertString === true ? defaultMessage : assertString); | ||
@@ -9,0 +9,0 @@ } |
| { | ||
| "version": 3, | ||
| "sources": ["../../src/assert.ts", "../../src/handleError.ts"], | ||
| "sourcesContent": ["import { isString, isUndefined } from '@xylabs/typeof'\n\ntype AssertCallback = (value: unknown, message: string) => string | boolean\n\n/** Configuration for assertion behavior: a static message string, a boolean toggle, or a callback. */\nexport type AssertConfig = string | AssertCallback | boolean\n\n/**\n * Throws an Error based on the assert configuration when a value fails validation.\n * @param value - The value being validated\n * @param assert - Assertion config controlling the error message\n * @param defaultMessage - Fallback message if no custom message is provided\n */\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (!isUndefined(assert)) {\n const assertString\n = typeof assert === 'string'\n ? assert\n : typeof assert === 'boolean'\n ? defaultMessage\n : assert(value, defaultMessage)\n if (isString(assertString) || assertString === true) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n", "import { isError } from '@xylabs/typeof'\n\n/**\n * Invokes the handler if the value is an Error, otherwise re-throws it.\n * @param error - The caught value to inspect\n * @param handler - Callback invoked with the Error if it is one\n * @returns The handler's return value\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const handleError = <T>(error: any, handler: (error: Error) => T) => {\n if (isError(error)) {\n return handler(error)\n }\n throw error\n}\n\n/**\n * Async version of handleError. Invokes the async handler if the value is an Error, otherwise re-throws it.\n * @param error - The caught value to inspect\n * @param handler - Async callback invoked with the Error if it is one\n * @returns The handler's resolved return value\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const handleErrorAsync = async <T>(error: any, handler: (error: Error) => Promise<T>) => {\n if (isError(error)) {\n return await handler(error)\n }\n throw error\n}\n"], | ||
| "mappings": ";AAAA,SAAS,UAAU,mBAAmB;AAa/B,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,CAAC,YAAY,MAAM,GAAG;AACxB,UAAM,eACF,OAAO,WAAW,WAChB,SACA,OAAO,WAAW,YAChB,iBACA,OAAO,OAAO,cAAc;AACpC,QAAI,SAAS,YAAY,KAAK,iBAAiB,MAAM;AACnD,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AACT;;;AC3BA,SAAS,eAAe;AASjB,IAAM,cAAc,CAAI,OAAY,YAAiC;AAC1E,MAAI,QAAQ,KAAK,GAAG;AAClB,WAAO,QAAQ,KAAK;AAAA,EACtB;AACA,QAAM;AACR;AASO,IAAM,mBAAmB,OAAU,OAAY,YAA0C;AAC9F,MAAI,QAAQ,KAAK,GAAG;AAClB,WAAO,MAAM,QAAQ,KAAK;AAAA,EAC5B;AACA,QAAM;AACR;", | ||
| "sourcesContent": ["import { isString, isUndefined } from '@xylabs/typeof'\n\ntype AssertCallback = (value: unknown, message: string) => string | boolean\n\n/** Configuration for assertion behavior: a static message string, a boolean toggle, or a callback. */\nexport type AssertConfig = string | AssertCallback | boolean\n\n/**\n * Throws an Error based on the assert configuration when a value fails validation.\n * @param value - The value being validated\n * @param assert - Assertion config controlling the error message\n * @param defaultMessage - Fallback message if no custom message is provided\n */\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (!isUndefined(assert)) {\n const assertString\n = typeof assert === 'string'\n ? assert\n : typeof assert === 'boolean'\n ? defaultMessage\n : assert(value, defaultMessage)\n if (isString(assertString) || assertString) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n", "import { isError } from '@xylabs/typeof'\n\n/**\n * Invokes the handler if the value is an Error, otherwise re-throws it.\n * @param error - The caught value to inspect\n * @param handler - Callback invoked with the Error if it is one\n * @returns The handler's return value\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const handleError = <T>(error: any, handler: (error: Error) => T) => {\n if (isError(error)) {\n return handler(error)\n }\n throw error\n}\n\n/**\n * Async version of handleError. Invokes the async handler if the value is an Error, otherwise re-throws it.\n * @param error - The caught value to inspect\n * @param handler - Async callback invoked with the Error if it is one\n * @returns The handler's resolved return value\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const handleErrorAsync = async <T>(error: any, handler: (error: Error) => Promise<T>) => {\n if (isError(error)) {\n return await handler(error)\n }\n throw error\n}\n"], | ||
| "mappings": ";AAAA,SAAS,UAAU,mBAAmB;AAa/B,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,CAAC,YAAY,MAAM,GAAG;AACxB,UAAM,eACF,OAAO,WAAW,WAChB,SACA,OAAO,WAAW,YAChB,iBACA,OAAO,OAAO,cAAc;AACpC,QAAI,SAAS,YAAY,KAAK,cAAc;AAC1C,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AACT;;;AC3BA,SAAS,eAAe;AASjB,IAAM,cAAc,CAAI,OAAY,YAAiC;AAC1E,MAAI,QAAQ,KAAK,GAAG;AAClB,WAAO,QAAQ,KAAK;AAAA,EACtB;AACA,QAAM;AACR;AASO,IAAM,mBAAmB,OAAU,OAAY,YAA0C;AAC9F,MAAI,QAAQ,KAAK,GAAG;AAClB,WAAO,MAAM,QAAQ,KAAK;AAAA,EAC5B;AACA,QAAM;AACR;", | ||
| "names": [] | ||
| } |
+6
-6
| { | ||
| "name": "@xylabs/error", | ||
| "version": "6.1.4", | ||
| "version": "7.0.0", | ||
| "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries", | ||
@@ -48,10 +48,10 @@ "keywords": [ | ||
| "dependencies": { | ||
| "@xylabs/typeof": "~6.1.4" | ||
| "@xylabs/typeof": "~7.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@xylabs/toolchain": "^8.3.0", | ||
| "@xylabs/tsconfig": "^8.3.0", | ||
| "browserslist": ">= 4.21.0", | ||
| "@xylabs/toolchain": "^8.4.1", | ||
| "@xylabs/tsconfig": "^8.4.1", | ||
| "browserslist": "4.28.4", | ||
| "eslint": "^10.5.0", | ||
| "eslint-import-resolver-typescript": "^4.4", | ||
| "eslint-import-resolver-typescript": "^4.4.5", | ||
| "typescript": "^6.0.3", | ||
@@ -58,0 +58,0 @@ "vite": "^8.1.0", |
18389
-0.14%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
Updated