Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-invariant

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-invariant - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

4

lib/invariant.d.ts
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[][] = [];

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc