You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.9 KiB
51 lines
1.9 KiB
import { __extends } from "tslib"; |
|
var genericMessage = "Invariant Violation"; |
|
var _a = Object.setPrototypeOf, setPrototypeOf = _a === void 0 ? function (obj, proto) { |
|
obj.__proto__ = proto; |
|
return obj; |
|
} : _a; |
|
var InvariantError = /** @class */ (function (_super) { |
|
__extends(InvariantError, _super); |
|
function InvariantError(message) { |
|
if (message === void 0) { message = genericMessage; } |
|
var _this = _super.call(this, typeof message === "number" |
|
? genericMessage + ": " + message + " (see https://github.com/apollographql/invariant-packages)" |
|
: message) || this; |
|
_this.framesToPop = 1; |
|
_this.name = genericMessage; |
|
setPrototypeOf(_this, InvariantError.prototype); |
|
return _this; |
|
} |
|
return InvariantError; |
|
}(Error)); |
|
export { InvariantError }; |
|
export function invariant(condition, message) { |
|
if (!condition) { |
|
throw new InvariantError(message); |
|
} |
|
} |
|
var verbosityLevels = ["debug", "log", "warn", "error", "silent"]; |
|
var verbosityLevel = verbosityLevels.indexOf("log"); |
|
function wrapConsoleMethod(name) { |
|
return function () { |
|
if (verbosityLevels.indexOf(name) >= verbosityLevel) { |
|
// Default to console.log if this host environment happens not to provide |
|
// all the console.* methods we need. |
|
var method = console[name] || console.log; |
|
return method.apply(console, arguments); |
|
} |
|
}; |
|
} |
|
(function (invariant) { |
|
invariant.debug = wrapConsoleMethod("debug"); |
|
invariant.log = wrapConsoleMethod("log"); |
|
invariant.warn = wrapConsoleMethod("warn"); |
|
invariant.error = wrapConsoleMethod("error"); |
|
})(invariant || (invariant = {})); |
|
export function setVerbosity(level) { |
|
var old = verbosityLevels[verbosityLevel]; |
|
verbosityLevel = Math.max(0, verbosityLevels.indexOf(level)); |
|
return old; |
|
} |
|
export default invariant; |
|
//# sourceMappingURL=invariant.js.map
|