@xylabs/assert
Advanced tools
Comparing version 2.7.4 to 2.7.5
@@ -14,3 +14,3 @@ "use strict"; | ||
* @param expr - Expression to be evaluated for truthiness | ||
* @param message - Message in Error if expression is false | ||
* @param message - Message in Error if expression is false, may be a function that returns a string | ||
* @throws AssertExError | ||
@@ -22,3 +22,3 @@ * @returns Value of expression | ||
return expr; | ||
throw new AssertExError(message); | ||
throw new AssertExError(typeof message === 'string' ? message : message === null || message === void 0 ? void 0 : message(expr)); | ||
}; | ||
@@ -25,0 +25,0 @@ exports.assertEx = assertEx; |
@@ -10,3 +10,3 @@ { | ||
{ | ||
"id": 6, | ||
"id": 11, | ||
"name": "default", | ||
@@ -21,9 +21,78 @@ "kind": 8388608, | ||
"character": 0, | ||
"url": "https://github.com/xylabs/sdk-js/blob/77d5e7f/packages/assert/src/index.ts#L23" | ||
"url": "https://github.com/xylabs/sdk-js/blob/09e8e07/packages/assert/src/index.ts#L23" | ||
} | ||
], | ||
"target": 1 | ||
"target": 6 | ||
}, | ||
{ | ||
"id": 1, | ||
"name": "AssertExMessageFunc", | ||
"kind": 4194304, | ||
"kindString": "Type alias", | ||
"flags": {}, | ||
"sources": [ | ||
{ | ||
"fileName": "index.ts", | ||
"line": 6, | ||
"character": 12, | ||
"url": "https://github.com/xylabs/sdk-js/blob/09e8e07/packages/assert/src/index.ts#L6" | ||
} | ||
], | ||
"type": { | ||
"type": "reflection", | ||
"declaration": { | ||
"id": 2, | ||
"name": "__type", | ||
"kind": 65536, | ||
"kindString": "Type literal", | ||
"flags": {}, | ||
"sources": [ | ||
{ | ||
"fileName": "index.ts", | ||
"line": 6, | ||
"character": 34, | ||
"url": "https://github.com/xylabs/sdk-js/blob/09e8e07/packages/assert/src/index.ts#L6" | ||
} | ||
], | ||
"signatures": [ | ||
{ | ||
"id": 3, | ||
"name": "__type", | ||
"kind": 4096, | ||
"kindString": "Call signature", | ||
"flags": {}, | ||
"typeParameter": [ | ||
{ | ||
"id": 5, | ||
"name": "T", | ||
"kind": 131072, | ||
"kindString": "Type parameter", | ||
"flags": {} | ||
} | ||
], | ||
"parameters": [ | ||
{ | ||
"id": 4, | ||
"name": "value", | ||
"kind": 32768, | ||
"kindString": "Parameter", | ||
"flags": {}, | ||
"type": { | ||
"type": "reference", | ||
"id": 5, | ||
"name": "T" | ||
} | ||
} | ||
], | ||
"type": { | ||
"type": "intrinsic", | ||
"name": "string" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
{ | ||
"id": 6, | ||
"name": "assertEx", | ||
@@ -36,5 +105,5 @@ "kind": 64, | ||
"fileName": "index.ts", | ||
"line": 15, | ||
"line": 17, | ||
"character": 6, | ||
"url": "https://github.com/xylabs/sdk-js/blob/77d5e7f/packages/assert/src/index.ts#L15" | ||
"url": "https://github.com/xylabs/sdk-js/blob/09e8e07/packages/assert/src/index.ts#L17" | ||
} | ||
@@ -44,3 +113,3 @@ ], | ||
{ | ||
"id": 2, | ||
"id": 7, | ||
"name": "assertEx", | ||
@@ -80,3 +149,3 @@ "kind": 4096, | ||
{ | ||
"id": 3, | ||
"id": 8, | ||
"name": "T", | ||
@@ -90,3 +159,3 @@ "kind": 131072, | ||
{ | ||
"id": 4, | ||
"id": 9, | ||
"name": "expr", | ||
@@ -115,3 +184,3 @@ "kind": 32768, | ||
"type": "reference", | ||
"id": 3, | ||
"id": 8, | ||
"name": "T" | ||
@@ -123,3 +192,3 @@ } | ||
{ | ||
"id": 5, | ||
"id": 10, | ||
"name": "message", | ||
@@ -135,3 +204,3 @@ "kind": 32768, | ||
"kind": "text", | ||
"text": "Message in Error if expression is false" | ||
"text": "Message in Error if expression is false, may be a function that returns a string" | ||
} | ||
@@ -141,4 +210,14 @@ ] | ||
"type": { | ||
"type": "intrinsic", | ||
"name": "string" | ||
"type": "union", | ||
"types": [ | ||
{ | ||
"type": "intrinsic", | ||
"name": "string" | ||
}, | ||
{ | ||
"type": "reference", | ||
"id": 1, | ||
"name": "AssertExMessageFunc" | ||
} | ||
] | ||
} | ||
@@ -149,3 +228,3 @@ } | ||
"type": "reference", | ||
"id": 3, | ||
"id": 8, | ||
"name": "T" | ||
@@ -161,10 +240,16 @@ } | ||
"children": [ | ||
6 | ||
11 | ||
] | ||
}, | ||
{ | ||
"title": "Functions", | ||
"title": "Type Aliases", | ||
"children": [ | ||
1 | ||
] | ||
}, | ||
{ | ||
"title": "Functions", | ||
"children": [ | ||
6 | ||
] | ||
} | ||
@@ -177,5 +262,5 @@ ], | ||
"character": 0, | ||
"url": "https://github.com/xylabs/sdk-js/blob/77d5e7f/packages/assert/src/index.ts#L4" | ||
"url": "https://github.com/xylabs/sdk-js/blob/09e8e07/packages/assert/src/index.ts#L4" | ||
} | ||
] | ||
} |
@@ -11,3 +11,3 @@ /** | ||
* @param expr - Expression to be evaluated for truthiness | ||
* @param message - Message in Error if expression is false | ||
* @param message - Message in Error if expression is false, may be a function that returns a string | ||
* @throws AssertExError | ||
@@ -19,7 +19,7 @@ * @returns Value of expression | ||
return expr; | ||
throw new AssertExError(message); | ||
throw new AssertExError(typeof message === 'string' ? message : message?.(expr)); | ||
}; | ||
export { assertEx }; | ||
// eslint-disable-next-line import/no-default-export | ||
export default assertEx; | ||
export { assertEx }; | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,2 @@ | ||
export type AssertExMessageFunc = <T>(value: T) => string; | ||
/** | ||
@@ -6,9 +7,9 @@ * | ||
* @param expr - Expression to be evaluated for truthiness | ||
* @param message - Message in Error if expression is false | ||
* @param message - Message in Error if expression is false, may be a function that returns a string | ||
* @throws AssertExError | ||
* @returns Value of expression | ||
*/ | ||
declare const assertEx: <T>(expr?: T | null | undefined, message?: string) => T; | ||
declare const assertEx: <T>(expr?: T | null | undefined, message?: string | AssertExMessageFunc) => T; | ||
export default assertEx; | ||
export { assertEx }; | ||
export default assertEx; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -37,3 +37,3 @@ { | ||
"devDependencies": { | ||
"@xylabs/ts-scripts-yarn3": "^2.15.0" | ||
"@xylabs/ts-scripts-yarn3": "^2.16.1" | ||
}, | ||
@@ -55,3 +55,3 @@ "homepage": "https://xylabs.com", | ||
"sideEffects": false, | ||
"version": "2.7.4" | ||
"version": "2.7.5" | ||
} |
@@ -6,2 +6,4 @@ /** | ||
export type AssertExMessageFunc = <T>(value: T) => string | ||
/** | ||
@@ -12,14 +14,14 @@ * | ||
* @param expr - Expression to be evaluated for truthiness | ||
* @param message - Message in Error if expression is false | ||
* @param message - Message in Error if expression is false, may be a function that returns a string | ||
* @throws AssertExError | ||
* @returns Value of expression | ||
*/ | ||
const assertEx = <T>(expr?: T | null, message?: string): T => { | ||
const assertEx = <T>(expr?: T | null, message?: string | AssertExMessageFunc): T => { | ||
if (expr) return expr | ||
throw new AssertExError(message) | ||
throw new AssertExError(typeof message === 'string' ? message : message?.(expr)) | ||
} | ||
export { assertEx } | ||
// eslint-disable-next-line import/no-default-export | ||
export default assertEx | ||
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
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
19921
333