jaywalk
Version:
Runtime type validation
36 lines • 1.27 kB
JavaScript
;
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var rule_1 = require('./rule');
var Blacklist = (function (_super) {
__extends(Blacklist, _super);
function Blacklist(options) {
_super.call(this, options);
this.type = 'Blacklist';
if (options.blacklist != null) {
this.blacklist = options.blacklist;
}
this._tests.push(toBlacklistTest(this.blacklist));
}
Blacklist.prototype._extend = function (options) {
var res = _super.prototype._extend.call(this, options);
if (options.blacklist) {
res.blacklist = this.blacklist.concat(options.blacklist);
}
return res;
};
return Blacklist;
}(rule_1.Rule));
exports.Blacklist = Blacklist;
function toBlacklistTest(blacklist) {
return function (value, path, context, next) {
if (blacklist.indexOf(value) > -1) {
throw context.error(path, 'Blacklist', 'blacklist', blacklist, value);
}
return next(value);
};
}
//# sourceMappingURL=blacklist.js.map