Comparing version 0.9.4 to 0.9.5
/** Lazy error message provider. */ | ||
export type AssertionErrorProvider = (() => string) | string; | ||
export type AssertionErrorProvider = (() => string | Error) | string; | ||
/** Asserts that the *param* value is truthy using '!' operator or throws an Error. */ | ||
@@ -4,0 +4,0 @@ export declare function assertTruthy(value: unknown, error?: AssertionErrorProvider): asserts value; |
@@ -31,3 +31,10 @@ "use strict"; | ||
} | ||
return typeof errorProvider === 'string' ? errorProvider : errorProvider(); | ||
if (typeof errorProvider === 'string') { | ||
return errorProvider; | ||
} | ||
const error = errorProvider(); | ||
if (typeof error === 'string') { | ||
return error; | ||
} | ||
return error.message; | ||
} | ||
@@ -34,0 +41,0 @@ exports.getErrorMessage = getErrorMessage; |
@@ -10,1 +10,2 @@ import { AssertionErrorProvider, ValueAssertion } from './Assertion'; | ||
export declare const assertEmail: ValueAssertion<string>; | ||
export declare function assertNonNullable<T = unknown>(value: T, context?: undefined): asserts value; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.assertEmail = exports.assertHexString = exports.assertUuid = exports.assertBoolean = exports.assertNumber = exports.assertString = exports.formatError = void 0; | ||
exports.assertNonNullable = exports.assertEmail = exports.assertHexString = exports.assertUuid = exports.assertBoolean = exports.assertNumber = exports.assertString = exports.formatError = void 0; | ||
const Assertion_1 = require("./Assertion"); | ||
@@ -41,2 +41,6 @@ const ChecksLib_1 = require("./ChecksLib"); | ||
exports.assertEmail = assertEmail; | ||
function assertNonNullable(value, context = undefined) { | ||
(0, Assertion_1.assertTruthy)((0, ChecksLib_1.isNonNullable)(value), () => formatError(context, `Value is ${value === undefined ? 'undefined' : 'null'}`, value)); | ||
} | ||
exports.assertNonNullable = assertNonNullable; | ||
//# sourceMappingURL=AssertionsLib.js.map |
@@ -21,1 +21,3 @@ /** Returns *true* if the value is *boolean*. */ | ||
export declare function isHexString(value: unknown): value is string; | ||
/** Returns true if value is not 'null' and not 'undefined'. */ | ||
export declare function isNonNullable<T = unknown>(value: T | undefined | null): value is NonNullable<T>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isHexString = exports.isUuid = exports.isEmail = exports.checkArrayHasUniqueElements = exports.isNumber = exports.isString = exports.isBoolean = void 0; | ||
exports.isNonNullable = exports.isHexString = exports.isUuid = exports.isEmail = exports.checkArrayHasUniqueElements = exports.isNumber = exports.isString = exports.isBoolean = void 0; | ||
/** Returns *true* if the value is *boolean*. */ | ||
@@ -71,2 +71,7 @@ function isBoolean(value) { | ||
exports.isHexString = isHexString; | ||
/** Returns true if value is not 'null' and not 'undefined'. */ | ||
function isNonNullable(value) { | ||
return value !== null && value !== undefined; | ||
} | ||
exports.isNonNullable = isNonNullable; | ||
//# sourceMappingURL=ChecksLib.js.map |
{ | ||
"name": "assertic", | ||
"description": "Assertions and Validations for TypeScript", | ||
"version": "0.9.4", | ||
"version": "0.9.5", | ||
"license": "Apache-2.0", | ||
@@ -16,8 +16,8 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@typescript-eslint/eslint-plugin": "^6.2.1", | ||
"@typescript-eslint/parser": "^6.2.1", | ||
"eslint": "^8.46.0", | ||
"rimraf": "^5.0.1", | ||
"@typescript-eslint/eslint-plugin": "^6.7.4", | ||
"@typescript-eslint/parser": "^6.7.4", | ||
"eslint": "^8.51.0", | ||
"rimraf": "^5.0.5", | ||
"ts-jest": "^29.1.1", | ||
"typescript": "^5.1.6" | ||
"typescript": "^5.2.2" | ||
}, | ||
@@ -24,0 +24,0 @@ "engines": { |
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
54891
505