jaywalk
Version:
Runtime type validation
42 lines • 1.24 kB
JavaScript
;
var extend = require('xtend');
var utils_1 = require('../utils');
var Rule = (function () {
function Rule(options) {
if (options === void 0) { options = {}; }
this.type = 'Any';
this.meta = {};
this._tests = [];
if (options.description != null) {
this.description = options.description;
}
if (options.meta != null) {
this.meta = options.meta;
}
if (options.example != null) {
this.example = options.example;
}
}
Rule.prototype._isType = function (value, path, context) {
throw context.error(path, 'Rule', 'type', 'Rule', value);
};
Rule.prototype._typeOf = function (other) {
return other instanceof this.constructor;
};
Rule.prototype._compile = function () {
return utils_1.compose(this._tests);
};
Rule.prototype._extend = function (options) {
var res = extend(this, options);
delete res._tests;
return res;
};
Rule.prototype.toJSON = function () {
var json = extend(this);
delete json._tests;
return json;
};
return Rule;
}());
exports.Rule = Rule;
//# sourceMappingURL=rule.js.map