Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.customRule('format_ipv4', function (val) { return !!val ? ipv4.test(val) : true; }, this.configuration.messages.format_ipv4 || '${$displayName} is not a valid IPv4 address.');
// format ipv6
// tslint:disable-next-line:max-line-length
var ipv6 = /^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i;
aurelia_validation_1.ValidationRules
.customRule('format_ipv6', function (val) { return !!val ? ipv6.test(val) : true; }, this.configuration.messages.format_ipv6 || '${$displayName} is not a valid IPv6 address.');
// format hostname
var hostname = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*$/i;
aurelia_validation_1.ValidationRules
.customRule('format_hostname', function (val) { return !!val ? hostname.test(val) : true; }, this.configuration.messages.format_hostname || '${$displayName} is not a valid hostname.');
// format uri
var uri = /^(?:[a-z][a-z0-9+-.]*:)(?:\/?\/)?[^\s]*$/i;
aurelia_validation_1.ValidationRules
.customRule('format_uri', function (val) { return !!val ? uri.test(val) : true; }, this.configuration.messages.format_uri || '${$displayName} is not a valid URI.');
// pattern
aurelia_validation_1.ValidationRules
.customRule('pattern', function (val, _obj, pattern) { return !!val ? (new RegExp(pattern)).test(val) : true; }, this.configuration.messages.pattern || '${$displayName} is not correctly formatted.', function (pattern) { return ({ pattern: pattern }); });
};
StringRules.prototype.bind = function (ctrl, rule) {
StringRules.prototype.add = function () {
// format datetime
// tslint:disable-next-line:max-line-length
var iso8601Datetime = /^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d:\d\d)$/i;
aurelia_validation_1.ValidationRules
.customRule('format_datetime', function (val) { return !!val ? iso8601Datetime.test(val) : true; }, this.configuration.messages.format_datetime || '${$displayName} is not a valid date/time.');
// format date
var iso8601Date = /^\d\d\d\d-[0-1]\d-[0-3]\d$/;
aurelia_validation_1.ValidationRules
.customRule('format_date', function (val) { return !!val ? iso8601Date.test(val) : true; }, this.configuration.messages.format_date || '${$displayName} is not a valid date.');
// format time
var iso8601Time = /^(?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d:\d\d)?$/i;
aurelia_validation_1.ValidationRules
.customRule('format_time', function (val) { return !!val ? iso8601Time.test(val) : true; }, this.configuration.messages.format_time || '${$displayName} is not a valid time.');
// format ipv4
var ipv4 = /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/;
aurelia_validation_1.ValidationRules
.customRule('format_ipv4', function (val) { return !!val ? ipv4.test(val) : true; }, this.configuration.messages.format_ipv4 || '${$displayName} is not a valid IPv4 address.');
// format ipv6
// tslint:disable-next-line:max-line-length
var ipv6 = /^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i;
ArrayRules.prototype.bind = function (ctrl) {
var rule = aurelia_validation_1.ValidationRules
.ensureObject()
.displayName(ctrl.form.$schema.title)
.satisfies(function () { return true; });
if (ctrl.form.$required) {
rule = rule.required();
}
if (Number.isInteger(ctrl.form.$schema.maxItems)) {
rule = rule.maxItems(ctrl.form.$schema.maxItems);
}
if (Number.isInteger(ctrl.form.$schema.minItems)) {
rule = rule.minItems(ctrl.form.$schema.minItems);
}
if (ctrl.form.$schema.uniqueItems) {
// TODO: add unique items rule
}
rule.on(ctrl.model);
NumberRules.prototype.add = function () {
// minimum
aurelia_validation_1.ValidationRules
.customRule('minimum', function (val, _obj, min) { return val !== undefined ? val >= min : true; }, this.configuration.messages.minimum || '${$displayName} must be greater than or equal to ${$config.min}.', function (min) { return ({ min: min }); });
// exclusionMinimum
aurelia_validation_1.ValidationRules
.customRule('exclusiveMinimum', function (val, _obj, min) { return val !== undefined ? val > min : true; }, this.configuration.messages.exclusiveMinimum || '${$displayName} must be greater than ${$config.min}.', function (min) { return ({ min: min }); });
// maximum
aurelia_validation_1.ValidationRules
.customRule('maximum', function (val, _obj, max) { return val !== undefined ? val <= max : true; }, this.configuration.messages.maximum || '${$displayName} must be less than or equal to ${$config.max}.', function (max) { return ({ max: max }); });
// exclusiveMaximum
aurelia_validation_1.ValidationRules
.customRule('exclusiveMaximum', function (val, _obj, max) { return val !== undefined ? val < max : true; }, this.configuration.messages.exclusiveMaximum || '${$displayName} must be less than ${$config.max}.', function (max) { return ({ max: max }); });
// multipleOf
aurelia_validation_1.ValidationRules
.customRule('multipleOf', function (val, _obj, multiple) { return val !== undefined ? ((val % multiple) / 100) === 0 : true; }, this.configuration.messages.multipleOf || '${$displayName} must be a multiple of ${$config.multiple}.', function (multiple) { return ({ multiple: multiple }); });
};
NumberRules.prototype.bind = function (ctrl, rule) {
NumberRules.prototype.add = function () {
// minimum
aurelia_validation_1.ValidationRules
.customRule('minimum', function (val, _obj, min) { return val !== undefined ? val >= min : true; }, this.configuration.messages.minimum || '${$displayName} must be greater than or equal to ${$config.min}.', function (min) { return ({ min: min }); });
// exclusionMinimum
aurelia_validation_1.ValidationRules
.customRule('exclusiveMinimum', function (val, _obj, min) { return val !== undefined ? val > min : true; }, this.configuration.messages.exclusiveMinimum || '${$displayName} must be greater than ${$config.min}.', function (min) { return ({ min: min }); });
// maximum
aurelia_validation_1.ValidationRules
.customRule('maximum', function (val, _obj, max) { return val !== undefined ? val <= max : true; }, this.configuration.messages.maximum || '${$displayName} must be less than or equal to ${$config.max}.', function (max) { return ({ max: max }); });
// exclusiveMaximum
aurelia_validation_1.ValidationRules
.customRule('exclusiveMaximum', function (val, _obj, max) { return val !== undefined ? val < max : true; }, this.configuration.messages.exclusiveMaximum || '${$displayName} must be less than ${$config.max}.', function (max) { return ({ max: max }); });
// multipleOf
aurelia_validation_1.ValidationRules
.customRule('multipleOf', function (val, _obj, multiple) { return val !== undefined ? ((val % multiple) / 100) === 0 : true; }, this.configuration.messages.multipleOf || '${$displayName} must be a multiple of ${$config.multiple}.', function (multiple) { return ({ multiple: multiple }); });
};
NumberRules.prototype.bind = function (ctrl, rule) {
var registerValidators = function (container) {
container.get(aureliaValidation.ValidationController).validateTrigger = aureliaValidation.validateTrigger.changeOrBlur;
aureliaValidation.ValidationRules.customRule("url", function (value) {
return value === null ||
value === undefined ||
value === "" ||
/^((http[s]?|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-.]+[^#?\s]+)(.*)?(#[\w\-]+)?$/.test(value);
}, "\${$displayName} is not a valid url.");
aureliaValidation.ValidationRules.customRule("phone", function (value) {
return value === null || value === undefined || value === "" || libphonenumberJs.parsePhoneNumberFromString(value).isValid();
}, "\${$displayName} is not a valid phone number.");
aureliaValidation.ValidationRules.customRule("number", function (value, obj, min, max) {
return value === null ||
value === undefined ||
value === "" ||
(isNumber(value) &&
value >= (isEmpty(min) ? Number.MIN_VALUE : min) &&
value <= (isEmpty(max) ? Number.MAX_VALUE : max));
}, "\${$displayName} must be an number value between \${$config.min} and \${$config.max}.", function (min, max) { return ({ min: min, max: max }); });
var registerValidators = function (container) {
container.get(aureliaValidation.ValidationController).validateTrigger = aureliaValidation.validateTrigger.changeOrBlur;
aureliaValidation.ValidationRules.customRule("url", function (value) {
return value === null ||
value === undefined ||
value === "" ||
/^((http[s]?|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-.]+[^#?\s]+)(.*)?(#[\w\-]+)?$/.test(value);
}, "\${$displayName} is not a valid url.");
aureliaValidation.ValidationRules.customRule("phone", function (value) {
return value === null || value === undefined || value === "" || libphonenumberJs.parsePhoneNumberFromString(value).isValid();
}, "\${$displayName} is not a valid phone number.");
aureliaValidation.ValidationRules.customRule("number", function (value, obj, min, max) {
return value === null ||
value === undefined ||
value === "" ||
(isNumber(value) &&
value >= (isEmpty(min) ? Number.MIN_VALUE : min) &&
value <= (isEmpty(max) ? Number.MAX_VALUE : max));
}, "\${$displayName} must be an number value between \${$config.min} and \${$config.max}.", function (min, max) { return ({ min: min, max: max }); });
aureliaValidation.ValidationRules.customRule("decimal", function (value, obj, min, max) {
return value === null ||
value === undefined ||
value === "" ||
(isDecimal(value) &&
value >= (isEmpty(min) ? Number.MIN_VALUE : min) &&
value <= (isEmpty(max) ? Number.MAX_VALUE : max));
}, "\${$displayName} must be a decimal value between \${$config.min} and \${$config.max}.", function (min, max) { return ({ min: min, max: max }); });
};
function configure(frameworkConfig, configCallback) {
_aureliaValidation.ValidationRules.customRule('hasAssociation', function (value) {
return value instanceof Entity && typeof value.id === 'number' || typeof value === 'number';
}, '${$displayName} must be an association.');
var entityManagerInstance = frameworkConfig.container.get(EntityManager);
configCallback(entityManagerInstance);
frameworkConfig.container.get(_aureliaViewManager.Config).configureNamespace('spoonx/orm', {
location: './view/{{framework}}/{{view}}.html'
});
frameworkConfig.globalResources('./component/association-select');
frameworkConfig.globalResources('./component/paged');
}
CommonRules.prototype.bind = function (ctrl) {
var rule = aurelia_validation_1.ValidationRules
.ensure('model')
.displayName(ctrl.form.$schema.title)
.satisfies(function () { return true; });
if (ctrl.form.$schema.const) {
rule = rule.equals(ctrl.form.$schema.const);
}
if (ctrl.form.$schema.enum) {
rule = rule.satisfiesRule('enum', ctrl.form.$schema.enum);
}
if (ctrl.form.$required) {
rule = rule.required();
}
return rule;
};
CommonRules = __decorate([
function configure(frameworkConfig, configCallback) {
_aureliaValidation.ValidationRules.customRule('hasAssociation', function (value) {
return value instanceof Entity && typeof value.id === 'number' || typeof value === 'number';
}, '${$displayName} must be an association.');
var entityManagerInstance = frameworkConfig.container.get(EntityManager);
configCallback(entityManagerInstance);
frameworkConfig.container.get(_aureliaViewManager.Config).configureNamespace('spoonx/orm', {
location: './view/{{framework}}/{{view}}.html'
});
frameworkConfig.globalResources('./component/association-select');
frameworkConfig.globalResources('./component/paged');
}