nowjs-core
Version:
NowCanDo Javascript Core [nowjs-core] is a library written by TypeScript code maintains under Apache 2.0 licence
528 lines (527 loc) • 18.8 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("./index");
class ValidationDefinition {
constructor() {
this.definitions = new Map();
this.currentName = '';
}
get Definitions() {
return this.definitions;
}
on(propertyName) {
if (!propertyName)
return this;
this.currentName = propertyName;
this.definitions.set(propertyName, []);
return this;
}
add(...validator) {
this.definitions.get(this.currentName).push(...validator);
return this;
}
get() {
return this.definitions.get(this.currentName);
}
clear() {
const list = this.definitions.get(this.currentName);
list.splice(0, list.length);
return this;
}
isStrict(errorMessage) {
this.definitions.get(this.currentName).push(new index_1.StrictValidator(errorMessage));
return this;
}
isRequired(arg0) {
let message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
}
else {
message = arg0;
}
this.definitions.get(this.currentName).push(new index_1.RequiredValidator(message));
return this;
}
isJsonSchema(arg0, errorMessage) {
let schema, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
schema = arg0.schema;
}
else {
message = errorMessage;
schema = arg0;
}
this.definitions.get(this.currentName).push(new index_1.JsonSchemaValidator(schema, message));
return this;
}
isMax(arg0, errorMessage) {
let max, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
max = arg0.max;
}
else {
message = errorMessage;
max = arg0;
}
this.definitions.get(this.currentName).push(new index_1.MaxValidator(max, message));
return this;
}
isMin(arg0, errorMessage) {
let min, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
min = arg0.min;
}
else {
message = errorMessage;
min = arg0;
}
this.definitions.get(this.currentName).push(new index_1.MinValidator(min, message));
return this;
}
isInRange(arg0, arg1, errorMessage) {
let min, max, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
min = arg0.min;
max = arg0.max;
}
else {
message = errorMessage;
min = arg0;
max = arg1;
}
this.definitions.get(this.currentName).push(new index_1.InRangeValidator(min, max, message));
return this;
}
isInLength(arg0, arg1, errorMessage) {
let min, max, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
min = arg0.min;
max = arg0.max;
}
else {
message = errorMessage;
min = arg0;
max = arg1;
}
this.definitions.get(this.currentName).push(new index_1.InLengthValidator(min, max, errorMessage));
return this;
}
isPattern(arg0, errorMessage) {
let pattern, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
pattern = arg0.pattern;
}
else {
message = errorMessage;
pattern = arg0;
}
this.definitions.get(this.currentName).push(new index_1.PatternValidator(pattern, errorMessage));
return this;
}
isIP(arg0, errorMessage) {
let options, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
options = arg0.options;
}
else {
message = errorMessage;
options = arg0;
}
this.definitions.get(this.currentName).push(new index_1.IPValidator(options, message));
return this;
}
isEmail(arg0) {
let message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
}
else {
message = arg0;
}
this.definitions.get(this.currentName).push(new index_1.EmailValidator(message));
return this;
}
isMobile(arg0, errorMessage) {
let style, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
style = arg0.style;
}
else {
message = errorMessage;
style = arg0;
}
this.definitions.get(this.currentName).push(new index_1.MobileValidator(style, message));
return this;
}
isPhone(arg0, errorMessage) {
let style, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
style = arg0.style;
}
else {
message = errorMessage;
style = arg0;
}
this.definitions.get(this.currentName).push(new index_1.PhoneValidator(style, message));
return this;
}
isNumeric(arg0, errorMessage) {
let style, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
style = arg0.style;
}
else {
message = errorMessage;
style = arg0;
}
this.definitions.get(this.currentName).push(new index_1.NumericValidator(style, message));
return this;
}
isUrl(arg0, errorMessage) {
let options, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
options = arg0.options;
}
else {
message = errorMessage;
options = arg0;
}
this.definitions.get(this.currentName).push(new index_1.UrlValidator(options, message));
return this;
}
isNegative(arg0) {
let message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
}
else {
message = arg0;
}
this.definitions.get(this.currentName).push(new index_1.NegativeValidator(message));
return this;
}
isPositive(arg0) {
let message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
}
else {
message = arg0;
}
this.definitions.get(this.currentName).push(new index_1.PositiveValidator(message));
return this;
}
isAlphabet(arg0, errorMessage) {
let styles, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
styles = arg0.style;
}
else {
message = errorMessage;
styles = arg0;
}
this.definitions.get(this.currentName).push(new index_1.AlphabetValidator(styles, message));
return this;
}
isAlphaNumeric(arg0, errorMessage) {
let styles, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
styles = arg0.style;
}
else {
message = errorMessage;
styles = arg0;
}
this.definitions.get(this.currentName).push(new index_1.AlphaNumericValidator(styles, message));
return this;
}
isValueType(arg0, errorMessage) {
let valueType, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
valueType = arg0.valueType;
}
else {
message = errorMessage;
valueType = arg0;
}
this.definitions.get(this.currentName).push(new index_1.ValueTypeValidator(valueType, message));
return this;
}
compareTo(arg0, arg1, arg2, errorMessage) {
let style, anotherTarget, anotherPropertyName, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
style = arg0.style;
anotherTarget = arg0.target;
anotherPropertyName = arg0.propertyName;
}
else {
message = errorMessage;
style = arg0;
anotherTarget = arg1;
anotherPropertyName = arg2;
}
this.definitions
.get(this.currentName)
.push(new index_1.CompareToValidator(style, anotherTarget, anotherPropertyName, message));
return this;
}
isEqualTo(arg0, arg1, errorMessage) {
let anotherTarget, anotherPropertyName, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
anotherTarget = arg0.target;
anotherPropertyName = arg0.propertyName;
}
else {
message = errorMessage;
anotherTarget = arg0;
anotherPropertyName = arg1;
}
this.definitions.get(this.currentName).push(new index_1.EqualToValidator(anotherTarget, anotherPropertyName, message));
return this;
}
isNotEqualTo(arg0, arg1, errorMessage) {
let anotherTarget, anotherPropertyName, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
anotherTarget = arg0.target;
anotherPropertyName = arg0.propertyName;
}
else {
message = errorMessage;
anotherTarget = arg0;
anotherPropertyName = arg1;
}
this.definitions
.get(this.currentName)
.push(new index_1.NotEqualToValidator(anotherTarget, anotherPropertyName, message));
return this;
}
isGreaterTo(arg0, arg1, errorMessage) {
let anotherTarget, anotherPropertyName, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
anotherTarget = arg0.target;
anotherPropertyName = arg0.propertyName;
}
else {
message = errorMessage;
anotherTarget = arg0;
anotherPropertyName = arg1;
}
this.definitions
.get(this.currentName)
.push(new index_1.GreaterToValidator(anotherTarget, anotherPropertyName, message));
return this;
}
isGreatOrEqualTo(arg0, arg1, errorMessage) {
let anotherTarget, anotherPropertyName, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
anotherTarget = arg0.target;
anotherPropertyName = arg0.propertyName;
}
else {
message = errorMessage;
anotherTarget = arg0;
anotherPropertyName = arg1;
}
this.definitions
.get(this.currentName)
.push(new index_1.GreatOrEqualToValidator(anotherTarget, anotherPropertyName, message));
return this;
}
isLesserTo(arg0, arg1, errorMessage) {
let anotherTarget, anotherPropertyName, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
anotherTarget = arg0.target;
anotherPropertyName = arg0.propertyName;
}
else {
message = errorMessage;
anotherTarget = arg0;
anotherPropertyName = arg1;
}
this.definitions.get(this.currentName).push(new index_1.LesserToValidator(anotherTarget, anotherPropertyName, message));
return this;
}
isLessOrEqualTo(arg0, arg1, errorMessage) {
let anotherTarget, anotherPropertyName, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
anotherTarget = arg0.target;
anotherPropertyName = arg0.propertyName;
}
else {
message = errorMessage;
anotherTarget = arg0;
anotherPropertyName = arg1;
}
this.definitions
.get(this.currentName)
.push(new index_1.LessOrEqualToValidator(anotherTarget, anotherPropertyName, message));
return this;
}
isIn(arg0, errorMessage) {
let values, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
values = arg0.values;
}
else {
message = errorMessage;
values = arg0;
}
this.definitions.get(this.currentName).push(new index_1.InValidator(values, message));
return this;
}
isNotIn(arg0, errorMessage) {
let values, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
values = arg0.values;
}
else {
message = errorMessage;
values = arg0;
}
this.definitions.get(this.currentName).push(new index_1.NotInValidator(values, message));
return this;
}
isContains(arg0, errorMessage) {
let value, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
value = arg0.values;
}
else {
message = errorMessage;
value = arg0;
}
this.definitions.get(this.currentName).push(new index_1.ContainsValidator(value, message));
return this;
}
isNotContains(arg0, errorMessage) {
let value, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
value = arg0.values;
}
else {
message = errorMessage;
value = arg0;
}
this.definitions.get(this.currentName).push(new index_1.NotContainsValidator(value, message));
return this;
}
isObject(arg0) {
let message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
}
else {
message = arg0;
}
this.definitions.get(this.currentName).push(new index_1.ObjectValidator(message));
return this;
}
isString(arg0) {
let message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
}
else {
message = arg0;
}
this.definitions.get(this.currentName).push(new index_1.StringValidator(message));
return this;
}
isFunction(arg0) {
let message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
}
else {
message = arg0;
}
this.definitions.get(this.currentName).push(new index_1.FunctionValidator(message));
return this;
}
isDate(arg0) {
let message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
}
else {
message = arg0;
}
this.definitions.get(this.currentName).push(new index_1.DateValidator(message));
return this;
}
isNumber(arg0) {
let message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
}
else {
message = arg0;
}
this.definitions.get(this.currentName).push(new index_1.NumberValidator(message));
return this;
}
isPostalCode(arg0, errorMessage) {
let style, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
style = arg0.style;
}
else {
message = errorMessage;
style = arg0;
}
this.definitions.get(this.currentName).push(new index_1.PostalCodeValidator(style, message));
return this;
}
isNSID(arg0, errorMessage) {
let style, message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
style = arg0.style;
}
else {
message = errorMessage;
style = arg0;
}
this.definitions.get(this.currentName).push(new index_1.NSIDValidator(style, message));
return this;
}
isJson(arg0) {
let message;
if (arg0 && arg0[index_1.VALIDATION_DEFINIIONITEM_KEY] === index_1.VALIDATION_DEFINIIONITEM_KEY) {
message = arg0.message;
}
else {
message = arg0;
}
this.definitions.get(this.currentName).push(new index_1.JsonValidator(message));
return this;
}
}
exports.ValidationDefinition = ValidationDefinition;