@xylabs/assert
Advanced tools
Comparing version 3.5.1 to 3.5.2
export type AssertExMessageFunc<T> = (value?: T | null) => string; | ||
export type AssertExErrorFunc<T, R extends Error> = (value?: T | null) => R; | ||
/** | ||
* | ||
* Intended for simple null/undefined checks for variables | ||
* | ||
* @param expr - Expression to be evaluated for truthiness | ||
* @param message - Message in Error if expression is false, may be a function that returns a string | ||
* @throws AssertExError | ||
* @returns Value of expression | ||
*/ | ||
declare function assertEx<T>(expr: T | null | undefined): T; | ||
/** @deprecated - replace string with () => string */ | ||
declare function assertEx<T>(expr: T | null | undefined, message?: string): T; | ||
@@ -15,0 +5,0 @@ declare function assertEx<T>(expr: T | null | undefined, messageFunc?: AssertExMessageFunc<T>): T; |
// src/index.ts | ||
function assertEx(expr, messageOrFunc) { | ||
if (expr) | ||
return expr; | ||
if (expr) return expr; | ||
if (typeof messageOrFunc === "function") { | ||
@@ -6,0 +5,0 @@ const errorOrMessage = messageOrFunc(expr); |
export type AssertExMessageFunc<T> = (value?: T | null) => string; | ||
export type AssertExErrorFunc<T, R extends Error> = (value?: T | null) => R; | ||
/** | ||
* | ||
* Intended for simple null/undefined checks for variables | ||
* | ||
* @param expr - Expression to be evaluated for truthiness | ||
* @param message - Message in Error if expression is false, may be a function that returns a string | ||
* @throws AssertExError | ||
* @returns Value of expression | ||
*/ | ||
declare function assertEx<T>(expr: T | null | undefined): T; | ||
/** @deprecated - replace string with () => string */ | ||
declare function assertEx<T>(expr: T | null | undefined, message?: string): T; | ||
@@ -15,0 +5,0 @@ declare function assertEx<T>(expr: T | null | undefined, messageFunc?: AssertExMessageFunc<T>): T; |
// src/index.ts | ||
function assertEx(expr, messageOrFunc) { | ||
if (expr) | ||
return expr; | ||
if (expr) return expr; | ||
if (typeof messageOrFunc === "function") { | ||
@@ -6,0 +5,0 @@ const errorOrMessage = messageOrFunc(expr); |
export type AssertExMessageFunc<T> = (value?: T | null) => string; | ||
export type AssertExErrorFunc<T, R extends Error> = (value?: T | null) => R; | ||
/** | ||
* | ||
* Intended for simple null/undefined checks for variables | ||
* | ||
* @param expr - Expression to be evaluated for truthiness | ||
* @param message - Message in Error if expression is false, may be a function that returns a string | ||
* @throws AssertExError | ||
* @returns Value of expression | ||
*/ | ||
declare function assertEx<T>(expr: T | null | undefined): T; | ||
/** @deprecated - replace string with () => string */ | ||
declare function assertEx<T>(expr: T | null | undefined, message?: string): T; | ||
@@ -15,0 +5,0 @@ declare function assertEx<T>(expr: T | null | undefined, messageFunc?: AssertExMessageFunc<T>): T; |
// src/index.ts | ||
function assertEx(expr, messageOrFunc) { | ||
if (expr) | ||
return expr; | ||
if (expr) return expr; | ||
if (typeof messageOrFunc === "function") { | ||
@@ -6,0 +5,0 @@ const errorOrMessage = messageOrFunc(expr); |
@@ -31,5 +31,5 @@ { | ||
"devDependencies": { | ||
"@xylabs/ts-scripts-yarn3": "^3.10.4", | ||
"@xylabs/tsconfig": "^3.10.4", | ||
"typescript": "^5.4.5" | ||
"@xylabs/ts-scripts-yarn3": "^3.11.10", | ||
"@xylabs/tsconfig": "^3.11.10", | ||
"typescript": "^5.5.2" | ||
}, | ||
@@ -54,4 +54,4 @@ "engines": { | ||
"sideEffects": false, | ||
"version": "3.5.1", | ||
"version": "3.5.2", | ||
"type": "module" | ||
} |
@@ -31,3 +31,2 @@ export type AssertExMessageFunc<T> = (value?: T | null) => string | ||
// eslint-disable-next-line deprecation/deprecation | ||
export { assertEx } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39466
186