ts-invariant
Advanced tools
Comparing version 0.2.1 to 0.3.0
export declare class InvariantError extends Error { | ||
framesToPop: number; | ||
name: string; | ||
constructor(message?: string); | ||
constructor(message?: string | number); | ||
} | ||
export declare function invariant(condition: any, message?: string): void; | ||
export declare function invariant(condition: any, message?: string | number): void; | ||
export declare namespace invariant { | ||
@@ -8,0 +8,0 @@ function warn(...args: any[]): void; |
@@ -12,3 +12,5 @@ import { __extends } from 'tslib'; | ||
if (message === void 0) { message = genericMessage; } | ||
var _this = _super.call(this, message) || this; | ||
var _this = _super.call(this, typeof message === "number" | ||
? genericMessage + ": " + message + " (see https://github.com/apollographql/invariant-packages)" | ||
: message) || this; | ||
_this.framesToPop = 1; | ||
@@ -15,0 +17,0 @@ _this.name = genericMessage; |
@@ -16,3 +16,5 @@ 'use strict'; | ||
if (message === void 0) { message = genericMessage; } | ||
var _this = _super.call(this, message) || this; | ||
var _this = _super.call(this, typeof message === "number" | ||
? genericMessage + ": " + message + " (see https://github.com/apollographql/invariant-packages)" | ||
: message) || this; | ||
_this.framesToPop = 1; | ||
@@ -19,0 +21,0 @@ _this.name = genericMessage; |
@@ -59,2 +59,14 @@ "use strict"; | ||
}); | ||
it("should annotate numeric error codes with URL", function () { | ||
try { | ||
invariant_1.invariant(false, 123); | ||
throw new Error("unexpected"); | ||
} | ||
catch (e) { | ||
assert_1.default(e instanceof invariant_1.InvariantError); | ||
assert_1.default.strictEqual(e.message, "Invariant Violation: 123 (see https://github.com/apollographql/invariant-packages)"); | ||
} | ||
var error = new invariant_1.InvariantError(456); | ||
assert_1.default.strictEqual(error.message, "Invariant Violation: 456 (see https://github.com/apollographql/invariant-packages)"); | ||
}); | ||
it("invariant.warn", function () { | ||
@@ -61,0 +73,0 @@ var argsReceived = []; |
{ | ||
"name": "ts-invariant", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"author": "Ben Newman <ben@apollographql.com>", | ||
@@ -40,3 +40,3 @@ "description": "TypeScript implementation of invariant(condition, message)", | ||
}, | ||
"gitHead": "9298ee0391e85354cfdf932bdb116c6dc9fe8445" | ||
"gitHead": "a8fc72bdcb9eeb9af0eabf7e9ba988277a0ac51b" | ||
} |
@@ -12,4 +12,8 @@ const genericMessage = "Invariant Violation"; | ||
name = genericMessage; | ||
constructor(message: string = genericMessage) { | ||
super(message); | ||
constructor(message: string | number = genericMessage) { | ||
super( | ||
typeof message === "number" | ||
? `${genericMessage}: ${message} (see https://github.com/apollographql/invariant-packages)` | ||
: message | ||
); | ||
setPrototypeOf(this, InvariantError.prototype); | ||
@@ -19,3 +23,3 @@ } | ||
export function invariant(condition: any, message?: string) { | ||
export function invariant(condition: any, message?: string | number) { | ||
if (!condition) { | ||
@@ -22,0 +26,0 @@ throw new InvariantError(message); |
@@ -57,2 +57,21 @@ import assert from "assert"; | ||
it("should annotate numeric error codes with URL", function () { | ||
try { | ||
invariant(false, 123); | ||
throw new Error("unexpected"); | ||
} catch (e) { | ||
assert(e instanceof InvariantError); | ||
assert.strictEqual( | ||
e.message, | ||
"Invariant Violation: 123 (see https://github.com/apollographql/invariant-packages)", | ||
); | ||
} | ||
const error = new InvariantError(456); | ||
assert.strictEqual( | ||
error.message, | ||
"Invariant Violation: 456 (see https://github.com/apollographql/invariant-packages)", | ||
); | ||
}); | ||
it("invariant.warn", function () { | ||
@@ -59,0 +78,0 @@ const argsReceived: any[][] = []; |
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
15565
420