nowjs-core
Version:
NowCanDo Javascript Core [nowjs-core] is a library written by TypeScript code maintains under Apache 2.0 licence
29 lines (28 loc) • 1.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("../index");
const index_2 = require("./index");
exports.VALIDATOR_URL_METADATA_KEY = Symbol('validation:validator:isUrl');
function isUrl(options, errorMessage) {
return (target, propertyKey, descriptor) => {
const original = descriptor.value;
Reflect.defineMetadata(exports.VALIDATOR_URL_METADATA_KEY, null, target, propertyKey);
Reflect.defineMetadata(index_1.VALIDATOR_METADATA_KEY, new UrlValidator(options, errorMessage), target, propertyKey);
};
}
exports.isUrl = isUrl;
exports.PATTERN_URL_UNIVERSAL = /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/gi;
class UrlValidator extends index_2.PatternValidatorBase {
constructor(options, errorMessage = 'The value of ${DisplayName} must have url pattern : ${Pattern} .') {
super('Url', exports.PATTERN_URL_UNIVERSAL, errorMessage);
options = options || {
Ports: [],
Protocols: ['http', 'https'],
ForcePort: false,
AllowQuery: false,
MaxSize: 1024,
ForceProtocol: true,
};
}
}
exports.UrlValidator = UrlValidator;