macoolka-error
Version:
`macoolka-cache` Build a cache for function
69 lines • 2.54 kB
JavaScript
;
/**
* @file
*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.invariantWarn = exports.invariant = exports.InvariantError = void 0;
var genericMessage = "Invariant Violation";
var utils_1 = require("./utils");
var Error_1 = require("./Error");
/**
* @since 0.2.0
*/
var InvariantError = /** @class */ (function (_super) {
__extends(InvariantError, _super);
function InvariantError(message) {
if (message === void 0) { message = genericMessage; }
var _this = _super.call(this, message) || this;
_this.framesToPop = 1;
_this.name = genericMessage;
(0, utils_1.setPrototypeOf)(_this, InvariantError.prototype);
return _this;
}
return InvariantError;
}(Error));
exports.InvariantError = InvariantError;
/**
* Throw a InvariantError with message when value not is true
* @desczh
* 当value不为真时抛出InvariantError
* @since 0.2.1
*/
function invariant(_a) {
var value = _a.value, message = _a.message, title = _a.title;
if (!value) {
throw new InvariantError((0, Error_1.wrapErrorToString)({ title: title, message: message }));
}
}
exports.invariant = invariant;
/**
* Call warn and return a defualt value with message when value not is true
* @desczh
* 当value不为真时返回缺省值并调用warn
* @since 0.2.0
*/
function invariantWarn(_a) {
var title = _a.title, value = _a.value, _b = _a.message, message = _b === void 0 ? genericMessage : _b, defaultValue = _a.defaultValue, warn = _a.warn;
if (!value) {
warn && warn((0, Error_1.wrapErrorToString)({ title: title, message: message }));
return defaultValue;
}
return value;
}
exports.invariantWarn = invariantWarn;
//# sourceMappingURL=invariant.js.map