jaywalk
Version:
Runtime type validation
38 lines • 1.34 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 validator = require('validator');
var string_1 = require('./string');
var utils_1 = require('../utils');
var Url = (function (_super) {
__extends(Url, _super);
function Url(options) {
if (options === void 0) { options = {}; }
_super.call(this, options);
this.type = 'Url';
this._tests.push(isUrl);
}
Url.prototype._isType = function (value, path, context) {
return utils_1.wrapIsType(this, value, path, context, _super.prototype._isType, function (value) {
if (validator.isURL(value)) {
return 1;
}
throw context.error(path, 'Url', 'type', 'Url', value);
});
};
Url.prototype._extend = function (options) {
return _super.prototype._extend.call(this, options);
};
return Url;
}(string_1.String));
exports.Url = Url;
function isUrl(value, path, context, next) {
if (!validator.isURL(value)) {
throw context.error(path, 'Url', 'type', 'Url', value);
}
return next(value);
}
//# sourceMappingURL=url.js.map