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 Whitelist = (function (_super) {
__extends(Whitelist, _super);
function Whitelist(options) {
_super.call(this, options);
this.type = 'Whitelist';
if (options.whitelist != null) {
this.whitelist = options.whitelist;
}
this._tests.push(toWhitelistTest(this.whitelist));
}
Whitelist.prototype._extend = function (options) {
var res = _super.prototype._extend.call(this, options);
if (options.whitelist) {
res.whitelist = this.whitelist.concat(options.whitelist);
}
return res;
};
return Whitelist;
}(rule_1.Rule));
exports.Whitelist = Whitelist;
function toWhitelistTest(whitelist) {
return function (value, path, context, next) {
if (whitelist.indexOf(value) === -1) {
throw context.error(path, 'Whitelist', 'whitelist', whitelist, value);
}
return next(value);
};
}
//# sourceMappingURL=whitelist.js.map