Comparing version 1.2.2 to 1.3.0
@@ -18,5 +18,8 @@ 'use strict'; | ||
var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Assert failed'; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { | ||
debug: true | ||
}; | ||
if (!condition) { | ||
developmentDebugger(); | ||
developmentDebugger(options.debug); | ||
throw new TypeError(message); | ||
@@ -33,3 +36,6 @@ } | ||
function assertNever(condition) { | ||
developmentDebugger(); | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { | ||
debug: true | ||
}; | ||
developmentDebugger(options.debug); | ||
throw new Error("Unexpected call to assertNever: '".concat(condition, "'")); | ||
@@ -39,4 +45,4 @@ } | ||
function developmentDebugger() { | ||
if (process.env.NODE_ENV === 'production') { | ||
function developmentDebugger(enabled) { | ||
if (!enabled || process.env.NODE_ENV === 'production') { | ||
return; | ||
@@ -43,0 +49,0 @@ } // eslint-disable-next-line no-debugger |
@@ -18,4 +18,8 @@ 'use strict'; | ||
var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Assert failed'; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { | ||
debug: true | ||
}; | ||
if (!condition) { | ||
developmentDebugger(options.debug); | ||
throw new TypeError(message); | ||
@@ -32,6 +36,20 @@ } | ||
function assertNever(condition) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { | ||
debug: true | ||
}; | ||
developmentDebugger(options.debug); | ||
throw new Error("Unexpected call to assertNever: '".concat(condition, "'")); | ||
} | ||
/** Pause execution in development to aid debugging. */ | ||
function developmentDebugger(enabled) { | ||
if (!enabled || "production" === 'production') { | ||
return; | ||
} // eslint-disable-next-line no-debugger | ||
debugger; | ||
} | ||
exports.assert = assert; | ||
exports.assertNever = assertNever; |
@@ -14,5 +14,8 @@ /** | ||
var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Assert failed'; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : { | ||
debug: true | ||
}; | ||
if (!condition) { | ||
developmentDebugger(); | ||
developmentDebugger(options.debug); | ||
throw new TypeError(message); | ||
@@ -29,3 +32,6 @@ } | ||
function assertNever(condition) { | ||
developmentDebugger(); | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { | ||
debug: true | ||
}; | ||
developmentDebugger(options.debug); | ||
throw new Error("Unexpected call to assertNever: '".concat(condition, "'")); | ||
@@ -35,4 +41,4 @@ } | ||
function developmentDebugger() { | ||
if (process.env.NODE_ENV === 'production') { | ||
function developmentDebugger(enabled) { | ||
if (!enabled || process.env.NODE_ENV === 'production') { | ||
return; | ||
@@ -39,0 +45,0 @@ } // eslint-disable-next-line no-debugger |
@@ -8,3 +8,5 @@ /** | ||
*/ | ||
export declare function assert(condition: boolean, message?: string): asserts condition; | ||
export declare function assert(condition: boolean, message?: string, options?: { | ||
debug: boolean; | ||
}): asserts condition; | ||
/** | ||
@@ -16,3 +18,5 @@ * Asserts that allegedly unreachable code has been executed. | ||
*/ | ||
export declare function assertNever(condition: never): never; | ||
export declare function assertNever(condition: never, options?: { | ||
debug: boolean; | ||
}): never; | ||
//# sourceMappingURL=assertions.d.ts.map |
{ | ||
"name": "emery", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"description": "Utilities to help polish the rough parts of TypeScript.", | ||
@@ -5,0 +5,0 @@ "main": "dist/emery.cjs.js", |
@@ -12,5 +12,9 @@ /** | ||
// `''`, which can introduce "subtle" bugs. | ||
export function assert(condition: boolean, message = 'Assert failed'): asserts condition { | ||
export function assert( | ||
condition: boolean, | ||
message = 'Assert failed', | ||
options = { debug: true }, | ||
): asserts condition { | ||
if (!condition) { | ||
developmentDebugger(); | ||
developmentDebugger(options.debug); | ||
throw new TypeError(message); | ||
@@ -26,4 +30,4 @@ } | ||
*/ | ||
export function assertNever(condition: never): never { | ||
developmentDebugger(); | ||
export function assertNever(condition: never, options = { debug: true }): never { | ||
developmentDebugger(options.debug); | ||
throw new Error(`Unexpected call to assertNever: '${condition}'`); | ||
@@ -33,4 +37,4 @@ } | ||
/** Pause execution in development to aid debugging. */ | ||
function developmentDebugger() { | ||
if (process.env.NODE_ENV === 'production') { | ||
function developmentDebugger(enabled?: boolean): void { | ||
if (!enabled || process.env.NODE_ENV === 'production') { | ||
return; | ||
@@ -37,0 +41,0 @@ } |
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
76668
1746