@jsbailey/reactive-form-validators
Version:
[](https://badge.fury.io/js/%40rxweb%2Freactive-form-validators) [](https://gitter.im/rxweb-project/rxweb?utm_source=badge
1,366 lines (1,326 loc) • 323 kB
JavaScript
import { __values, __read } from 'tslib';
import { isNumeric } from 'rxjs/internal-compatibility';
import { Injectable, NgModule } from '@angular/core';
import { FormBuilder, FormsModule, ReactiveFormsModule } from '@angular/forms';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
var CreditCardRegex = /** @class */ (function () {
function CreditCardRegex() {
this.Visa = new RegExp('^(?:4[0-9]{12})(?:[0-9]{3})?$');
this.AmericanExpress = new RegExp('^(?:3[47][0-9]{13})$');
this.Maestro = new RegExp('^(?:(?:5[0678]\\d\\d|6304|6390|67\\d\\d)\\d{8,15})$');
this.JCB = new RegExp('^(?:(?:2131|1800|35\\d{3})\\d{11})$');
this.Discover = new RegExp('^(?:6(?:011|5[0-9]{2})(?:[0-9]{12}))$');
this.DinersClub = new RegExp('^(?:3(?:0[0-5]|[68][0-9])[0-9]{11})$');
this.MasterCard = new RegExp('^(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}$');
}
return CreditCardRegex;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/** @type {?} */
var RegExRule = {
alpha: /^[a-zA-Z]+$/,
alphaWithSpace: /^[a-zA-Z\s]+$/,
onlyDigit: /^[0-9]+$/,
isDigitExits: /\d/g,
lowerCase: /[a-z]/g,
upperCase: /[A-Z]/g,
specialCharacter: /[!@#$%^&*(),.?":{}|<>]/g,
advancedEmail: /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,
basicEmail: /^(([^<>()\[\]\\.,,:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
alphaNumeric: /^[0-9a-zA-Z]+$/,
alphaNumericWithSpace: /^[0-9a-zA-Z\s]+$/,
hexColor: /#([a-f0-9]{3}|[a-f0-9]{4}(?:[a-f0-9]{2}){0,2})\b/gi,
strictHexColor: /^#([a-f0-9]{3,4}|[a-f0-9]{4}(?:[a-f0-9]{2}){1,2})\b$/i,
float: /^(?:[-+]?(?:[0-9]+))?(?:\.[0-9]*)?(?:[eE][\+\-]?(?:[0-9]+))?$/,
decimal: /^[-+]?([0-9]+|\.[0-9]+|[0-9]+\.[0-9]+)$/,
hexaDecimal: /^[0-9A-F]+$/i,
date: /^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,
time: /(00|[0-9]|1[0-9]|2[0-3]):([0-9]|[0-5][0-9])$/,
url: /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/,
creditCard: new CreditCardRegex(),
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/** @type {?} */
var ALPHABET = "alphabet";
/** @type {?} */
var DIGIT = "digit";
/** @type {?} */
var CONTAINS = "contains";
/** @type {?} */
var LOWERCASE = "lowerCase";
/** @type {?} */
var UPPERCASE = "upperCase";
/** @type {?} */
var SPECIAL_CHARACTER = "specialCharacter";
/** @type {?} */
var MIN_LENGTH = "minLength";
/** @type {?} */
var MAX_LENGTH = "maxLength";
var RegexValidator = /** @class */ (function () {
function RegexValidator() {
}
/**
* @param {?} value
* @param {?} regex
* @return {?}
*/
RegexValidator.isExits = /**
* @param {?} value
* @param {?} regex
* @return {?}
*/
function (value, regex) {
return value.match(regex) != null;
};
/**
* @param {?} value
* @param {?} regex
* @return {?}
*/
RegexValidator.isValid = /**
* @param {?} value
* @param {?} regex
* @return {?}
*/
function (value, regex) {
return regex.test(value);
};
/**
* @param {?} value
* @return {?}
*/
RegexValidator.isNotBlank = /**
* @param {?} value
* @return {?}
*/
function (value) {
return value != undefined && value != "" && value != null;
};
/**
* @param {?} passwordValidation
* @param {?} value
* @return {?}
*/
RegexValidator.isValidPassword = /**
* @param {?} passwordValidation
* @param {?} value
* @return {?}
*/
function (passwordValidation, value) {
/** @type {?} */
var isValid = false;
/** @type {?} */
var keyName = "status";
/** @type {?} */
var objectProperties = Object.getOwnPropertyNames(passwordValidation);
try {
for (var objectProperties_1 = __values(objectProperties), objectProperties_1_1 = objectProperties_1.next(); !objectProperties_1_1.done; objectProperties_1_1 = objectProperties_1.next()) {
var propertyName = objectProperties_1_1.value;
switch (propertyName) {
case ALPHABET:
isValid = RegexValidator.isExits(value, RegExRule["alpha"]);
keyName = ALPHABET;
break;
case DIGIT:
isValid = RegexValidator.isValid(value, RegExRule["isDigitExits"]);
keyName = DIGIT;
break;
case CONTAINS:
isValid = value.indexOf(passwordValidation[CONTAINS]) != -1;
keyName = CONTAINS;
break;
case LOWERCASE:
isValid = RegexValidator.isValid(value, RegExRule["lowerCase"]);
keyName = LOWERCASE;
break;
case UPPERCASE:
isValid = RegexValidator.isValid(value, RegExRule["upperCase"]);
keyName = UPPERCASE;
break;
case SPECIAL_CHARACTER:
isValid = RegexValidator.isExits(value, RegExRule["specialCharacter"]);
keyName = SPECIAL_CHARACTER;
break;
case MIN_LENGTH:
isValid = value.length >= passwordValidation[propertyName];
keyName = MIN_LENGTH;
break;
case MAX_LENGTH:
isValid = value.length <= passwordValidation[propertyName];
keyName = MAX_LENGTH;
break;
}
if (!isValid)
break;
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (objectProperties_1_1 && !objectProperties_1_1.done && (_a = objectProperties_1.return)) _a.call(objectProperties_1);
}
finally { if (e_1) throw e_1.error; }
}
return { isValid: isValid, keyName: keyName };
var e_1, _a;
};
return RegexValidator;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
var ReactiveFormConfig = /** @class */ (function () {
function ReactiveFormConfig() {
}
/**
* @param {?} jObject
* @return {?}
*/
ReactiveFormConfig.set = /**
* @param {?} jObject
* @return {?}
*/
function (jObject) {
if (jObject)
ReactiveFormConfig.json = jObject;
};
ReactiveFormConfig.json = {};
return ReactiveFormConfig;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
var ObjectMaker = /** @class */ (function () {
function ObjectMaker() {
}
/**
* @param {?} key
* @param {?} message
* @param {?} values
* @return {?}
*/
ObjectMaker.toJson = /**
* @param {?} key
* @param {?} message
* @param {?} values
* @return {?}
*/
function (key, message, values) {
/** @type {?} */
var messageText = (message) ? message : (ReactiveFormConfig && ReactiveFormConfig.json && ReactiveFormConfig.json["validationMessage"] && ReactiveFormConfig.json["validationMessage"][key]) ? ReactiveFormConfig.json["validationMessage"][key] : '';
values.forEach(function (t, index) {
messageText = messageText.replace("{{" + index + "}}", t);
});
/** @type {?} */
var jObject = {};
jObject[key] = {
message: messageText, refValues: values
};
return jObject;
};
/**
* @return {?}
*/
ObjectMaker.null = /**
* @return {?}
*/
function () {
return null;
};
return ObjectMaker;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
var Linq = /** @class */ (function () {
function Linq() {
}
/**
* @param {?} expression
* @return {?}
*/
Linq.functionCreator = /**
* @param {?} expression
* @return {?}
*/
function (expression) {
/** @type {?} */
var functionSetter = [];
/** @type {?} */
var match = expression.match(/^\s*\(?\s*([^)]*)\s*\)?\s*=>(.*)/);
/** @type {?} */
var splitSelect = match[2].split(",");
for (var i = 0; i < splitSelect.length; i++) {
/** @type {?} */
var equalToOperator = splitSelect[i].match(/^\s*\(?\s*([^)]*)\s*\)?\s*==(.*)/);
if (equalToOperator !== null) {
functionSetter = new Function(match[1], "return " + equalToOperator[0]);
}
else {
equalToOperator = splitSelect[i].match(/^\s*\(?\s*([^)]*)\s*\)?\s*=(.*)/);
if (equalToOperator === null) {
functionSetter = new Function(match[1], "return " + splitSelect[i]);
}
else {
functionSetter = new Function(match[1], "return " + equalToOperator[2]);
}
}
}
if (splitSelect.length == 0)
functionSetter = { accessFunction: new Function(match[1], "return " + match[2]) };
return functionSetter;
};
/**
* @param {?} jObject
* @param {?} expression
* @param {?} parentObject
* @return {?}
*/
Linq.IsPassed = /**
* @param {?} jObject
* @param {?} expression
* @param {?} parentObject
* @return {?}
*/
function (jObject, expression, parentObject) {
/** @type {?} */
var expressionFunction = expression;
if (parentObject && typeof expression == "string")
expressionFunction = Linq.functionCreator(expression);
if (parentObject && expressionFunction)
return expressionFunction(parentObject, jObject);
return true;
};
/**
* @param {?} expression
* @return {?}
*/
Linq.expressionColumns = /**
* @param {?} expression
* @return {?}
*/
function (expression) {
/** @type {?} */
var columns = [];
/** @type {?} */
var splitExpressions = [];
if (typeof expression == "string")
expression.split("=>")[1].split(" && ").forEach(function (t) {
t.split(" || ").forEach(function (x) {
splitExpressions.push(x.trim().split(' ')[0]);
});
});
else
String(expression).split(" return ")[1].split(" && ").forEach(function (t) {
t.split(" || ").forEach(function (x) {
splitExpressions.push(x.trim().split(' ')[0]);
});
});
splitExpressions.forEach(function (t) {
/** @type {?} */
var splitText = t.split('.');
if (splitText.length == 2)
columns.push({ propName: splitText[1].trim() });
else {
/** @type {?} */
var arrayProp = splitText[1].split('[');
/** @type {?} */
var jObject = {
propName: splitText[splitText.length - 1].trim(),
objectPropName: arrayProp[0],
arrayIndex: arrayProp.length > 1 ? arrayProp[1].replace("]", "") : undefined
};
columns.push(jObject);
}
});
return columns;
};
return Linq;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
var ApplicationUtil = /** @class */ (function () {
function ApplicationUtil() {
}
/**
* @param {?} control
* @return {?}
*/
ApplicationUtil.getParentObjectValue = /**
* @param {?} control
* @return {?}
*/
function (control) {
if (control.parent) {
/** @type {?} */
var parent_1 = this.parentObjectValue(control.parent);
return parent_1.value;
}
return {};
};
/**
* @param {?} control
* @return {?}
*/
ApplicationUtil.parentObjectValue = /**
* @param {?} control
* @return {?}
*/
function (control) {
if (!control.parent)
return control;
else
control = this.parentObjectValue(control.parent);
return control;
};
/**
* @param {?} config
* @return {?}
*/
ApplicationUtil.getConfigObject = /**
* @param {?} config
* @return {?}
*/
function (config) {
return (config != undefined && config != true) ? config : {};
};
return ApplicationUtil;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/** @type {?} */
var AnnotationTypes = {
numeric: 'numeric',
required: 'required',
minLength: 'minLength',
maxLength: 'maxLength',
minNumber: 'minNumber',
maxNumber: 'maxNumber',
pattern: 'pattern',
password: 'password',
compare: 'compare',
minDate: 'minDate',
maxDate: 'maxDate',
alpha: 'alpha',
alphaNumeric: 'alphaNumeric',
email: 'email',
hexColor: 'hexColor',
lowerCase: 'lowerCase',
url: 'url',
upperCase: 'upperCase',
nested: 'nested',
propArray: 'propArray',
propObject: 'propObject',
contains: 'contains',
range: 'range',
custom: 'custom',
digit: "digit",
creditCard: "creditCard",
time: "time",
json: "json",
greaterThan: "greaterThan",
greaterThanEqualTo: "greaterThanEqualTo",
lessThan: "lessThan",
lessThanEqualTo: "lessThanEqualTo"
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @param {?} conditionalValidationProps
* @return {?}
*/
function alphaValidator(config, conditionalValidationProps) {
return function (control) {
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
config = ApplicationUtil.getConfigObject(config);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if (RegexValidator.isNotBlank(controlValue)) {
/** @type {?} */
var testResult = false;
if (!config.allowWhiteSpace)
testResult = RegexValidator.isValid(controlValue, RegExRule["alpha"]);
else
testResult = RegexValidator.isValid(controlValue, RegExRule["alphaWithSpace"]);
if (!testResult)
return ObjectMaker.toJson(AnnotationTypes["alpha"], config.message || null, [controlValue]);
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @return {?}
*/
function alphaNumericValidator(config) {
return function (control) {
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
config = ApplicationUtil.getConfigObject(config);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if (RegexValidator.isNotBlank(controlValue)) {
/** @type {?} */
var testResult = true;
if (!config.allowWhiteSpace)
testResult = RegexValidator.isValid(controlValue, RegExRule["alphaNumeric"]);
else
testResult = RegexValidator.isValid(controlValue, RegExRule["alphaNumericWithSpace"]);
if (!testResult)
return ObjectMaker.toJson(AnnotationTypes["alphaNumeric"], config.message || null, [controlValue]);
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @return {?}
*/
function compareValidator(config) {
return function (control) {
/** @type {?} */
var compareControl = control.root.get([config.fieldName]);
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var compareControlValue = (compareControl) ? compareControl.value : '';
if (RegexValidator.isNotBlank(controlValue)) {
if (!(compareControl && compareControl.value === controlValue))
return ObjectMaker.toJson(AnnotationTypes["compare"], config.message || null, [controlValue, compareControlValue]);
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @return {?}
*/
function containsValidator(config) {
return function (control) {
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
config = ApplicationUtil.getConfigObject(config);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if (RegexValidator.isNotBlank(controlValue)) {
if (controlValue.indexOf(config.value) == -1)
return ObjectMaker.toJson(AnnotationTypes["contains"], config.message || null, [config.value, controlValue]);
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/** @enum {number} */
var CreditCardType = {
Visa: 1,
AmericanExpress: 2,
Maestro: 3,
JCB: 4,
Discover: 5,
DinersClub: 6,
MasterCard: 7,
};
CreditCardType[CreditCardType.Visa] = 'Visa';
CreditCardType[CreditCardType.AmericanExpress] = 'AmericanExpress';
CreditCardType[CreditCardType.Maestro] = 'Maestro';
CreditCardType[CreditCardType.JCB] = 'JCB';
CreditCardType[CreditCardType.Discover] = 'Discover';
CreditCardType[CreditCardType.DinersClub] = 'DinersClub';
CreditCardType[CreditCardType.MasterCard] = 'MasterCard';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @return {?}
*/
function creditCardValidator(config) {
return function (control) {
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
config = ApplicationUtil.getConfigObject(config);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if (RegexValidator.isNotBlank(controlValue)) {
/** @type {?} */
var isValid = false;
try {
for (var _a = __values(config.creditCardTypes), _b = _a.next(); !_b.done; _b = _a.next()) {
var creditCardType = _b.value;
switch (creditCardType) {
case CreditCardType.AmericanExpress:
isValid = RegexValidator.isValid(controlValue, RegExRule["creditCard"].AmericanExpress);
break;
case CreditCardType.DinersClub:
isValid = RegexValidator.isValid(controlValue, RegExRule["creditCard"].DinersClub);
break;
case CreditCardType.Discover:
isValid = RegexValidator.isValid(controlValue, RegExRule["creditCard"].Discover);
break;
case CreditCardType.JCB:
isValid = RegexValidator.isValid(controlValue, RegExRule["creditCard"].JCB);
break;
case CreditCardType.Maestro:
isValid = RegexValidator.isValid(controlValue, RegExRule["creditCard"].Maestro);
break;
case CreditCardType.MasterCard:
isValid = RegexValidator.isValid(controlValue, RegExRule["creditCard"].MasterCard);
break;
case CreditCardType.Visa:
isValid = RegexValidator.isValid(controlValue, RegExRule["creditCard"].Visa);
break;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
}
finally { if (e_1) throw e_1.error; }
}
if (!isValid)
return ObjectMaker.toJson(AnnotationTypes["creditCard"], config.message || null, [controlValue]);
}
}
return ObjectMaker.null();
var e_1, _c;
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @return {?}
*/
function digitValidator(config) {
return function (control) {
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
config = ApplicationUtil.getConfigObject(config);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if (RegexValidator.isNotBlank(controlValue)) {
if (!RegexValidator.isValid(controlValue, RegExRule["onlyDigit"]))
return ObjectMaker.toJson(AnnotationTypes["digit"], config.message || null, [controlValue]);
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
var DateProvider = /** @class */ (function () {
function DateProvider() {
}
/**
* @return {?}
*/
DateProvider.prototype.regex = /**
* @return {?}
*/
function () {
/** @type {?} */
var regExp;
if (ReactiveFormConfig && ReactiveFormConfig.json && ReactiveFormConfig.json["internationalization"] && ReactiveFormConfig.json["internationalization"].dateFormat && ReactiveFormConfig.json["internationalization"].seperator) {
/** @type {?} */
var seperator = ReactiveFormConfig.json["internationalization"].seperator;
switch (ReactiveFormConfig.json["internationalization"].dateFormat) {
case 'ymd':
regExp = /^(\d{4}-\d{1,2}-\d{1,2})$/;
break;
case 'dmy':
case 'mdy':
regExp = /^(\d{1,2}-\d{1,2}-\d{4})$/;
break;
}
}
return regExp;
};
/**
* @param {?} value
* @return {?}
*/
DateProvider.prototype.getDate = /**
* @param {?} value
* @return {?}
*/
function (value) {
/** @type {?} */
var year;
if (ReactiveFormConfig && ReactiveFormConfig.json && ReactiveFormConfig.json["internationalization"] && ReactiveFormConfig.json["internationalization"].dateFormat && ReactiveFormConfig.json["internationalization"].seperator) {
/** @type {?} */
var seperator = ReactiveFormConfig.json["internationalization"].seperator;
switch (ReactiveFormConfig.json["internationalization"].dateFormat) {
case 'ymd':
_a = __read(value.split(seperator).map(function (val) { return +val; }), 3), year = _a[0], month = _a[1], day = _a[2];
break;
case 'dmy':
_b = __read(value.split(seperator).map(function (val) { return +val; }), 3), day = _b[0], month = _b[1], year = _b[2];
break;
case 'mdy':
_c = __read(value.split(seperator).map(function (val) { return +val; }), 3), month = _c[0], day = _c[1], year = _c[2];
break;
}
}
return new Date(year, month - 1, day);
var _a, _b, _c;
};
/**
* @param {?} value
* @return {?}
*/
DateProvider.prototype.isValid = /**
* @param {?} value
* @return {?}
*/
function (value) {
value = value.replace(ReactiveFormConfig.json["internationalization"].seperator, '-').replace(ReactiveFormConfig.json["internationalization"].seperator, '-');
return this.regex().test(value);
};
return DateProvider;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @return {?}
*/
function emailValidator(config) {
return function (control) {
/** @type {?} */
var controlValue = control.value;
config = ApplicationUtil.getConfigObject(config);
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if (RegexValidator.isNotBlank(controlValue)) {
if (!RegexValidator.isValid(controlValue, RegExRule["basicEmail"]))
return ObjectMaker.toJson(AnnotationTypes["email"], config.message || null, [controlValue]);
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @return {?}
*/
function hexColorValidator(config) {
return function (control) {
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
config = ApplicationUtil.getConfigObject(config);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if (RegexValidator.isNotBlank(controlValue)) {
/** @type {?} */
var hexRegex = config.isStrict ? RegExRule["strictHexColor"] : RegExRule["hexColor"];
if (!RegexValidator.isValid(controlValue, hexRegex))
return ObjectMaker.toJson(AnnotationTypes["hexColor"], config.message || null, [controlValue]);
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @return {?}
*/
function lowercaseValidator(config) {
return function (control) {
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
config = ApplicationUtil.getConfigObject(config);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if (RegexValidator.isNotBlank(controlValue)) {
if (!(controlValue === controlValue.toLowerCase()))
return ObjectMaker.toJson(AnnotationTypes["lowerCase"], config.message || null, [controlValue]);
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @return {?}
*/
function maxDateValidator(config) {
return function (control) {
/** @type {?} */
var dateProvider = new DateProvider();
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
config = ApplicationUtil.getConfigObject(config);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if (RegexValidator.isNotBlank(controlValue)) {
if (dateProvider.isValid(controlValue)) {
/** @type {?} */
var maxDate = config.value;
/** @type {?} */
var currentValueDate = dateProvider.getDate(controlValue);
if (!(maxDate >= currentValueDate))
return ObjectMaker.toJson(AnnotationTypes["maxDate"], config.message || null, [control.value]);
}
else
return ObjectMaker.toJson(AnnotationTypes["maxDate"], config.message || null, [control.value]);
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @return {?}
*/
function maxLengthValidator(config) {
return function (control) {
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
config = ApplicationUtil.getConfigObject(config);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if (RegexValidator.isNotBlank(controlValue)) {
if (!(controlValue.length <= config.value))
return ObjectMaker.toJson(AnnotationTypes["maxLength"], config.message || null, [controlValue]);
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @return {?}
*/
function maxNumberValidator(config) {
return function (control) {
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
config = ApplicationUtil.getConfigObject(config);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if (RegexValidator.isNotBlank(controlValue)) {
if (!(parseFloat(controlValue) <= config.value))
return ObjectMaker.toJson(AnnotationTypes["maxNumber"], config.message || null, [controlValue]);
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @return {?}
*/
function minDateValidator(config) {
return function (control) {
/** @type {?} */
var dateProvider = new DateProvider();
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
config = ApplicationUtil.getConfigObject(config);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if (RegexValidator.isNotBlank(controlValue)) {
if (dateProvider.isValid(controlValue)) {
/** @type {?} */
var minDate = config.value;
/** @type {?} */
var currentControlValue = dateProvider.getDate(controlValue);
if (!(currentControlValue >= minDate))
return ObjectMaker.toJson(AnnotationTypes["minDate"], config.message || null, [control.value]);
}
else
return ObjectMaker.toJson(AnnotationTypes["minDate"], config.message || null, [control.value]);
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @return {?}
*/
function minLengthValidator(config) {
return function (control) {
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
config = ApplicationUtil.getConfigObject(config);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if (RegexValidator.isNotBlank(controlValue)) {
if (!(String(controlValue).length >= config.value))
return ObjectMaker.toJson(AnnotationTypes["minLength"], config.message || null, [controlValue]);
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @return {?}
*/
function minNumberValidator(config) {
return function (control) {
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
config = ApplicationUtil.getConfigObject(config);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if (RegexValidator.isNotBlank(controlValue)) {
if (!(parseFloat(controlValue) >= config.value))
return ObjectMaker.toJson(AnnotationTypes["minNumber"], config.message || null, [controlValue]);
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @return {?}
*/
function passwordValidator(config) {
return function (control) {
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
if (RegexValidator.isNotBlank(controlValue)) {
/** @type {?} */
var validation = RegexValidator.isValidPassword(config.validation, controlValue);
if (!validation["isValid"])
return ObjectMaker.toJson(AnnotationTypes["password"], config.message || null, [controlValue]);
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @return {?}
*/
function rangeValidator(config) {
return function (control) {
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
config = ApplicationUtil.getConfigObject(config);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if (RegexValidator.isNotBlank(controlValue)) {
if (!(String(controlValue).indexOf(".") == -1 && parseInt(controlValue) >= config.minimumNumber && parseInt(controlValue) <= config.maximumNumber))
return ObjectMaker.toJson(AnnotationTypes["range"], config.message || null, [config.minimumNumber, config.maximumNumber, controlValue]);
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @return {?}
*/
function uppercaseValidator(config) {
return function (control) {
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
config = ApplicationUtil.getConfigObject(config);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if (RegexValidator.isNotBlank(controlValue)) {
if (!(controlValue === controlValue.toUpperCase()))
return ObjectMaker.toJson(AnnotationTypes["upperCase"], config.message || null, [controlValue]);
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @return {?}
*/
function requiredValidator(config) {
return function (control) {
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
config = ApplicationUtil.getConfigObject(config);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if (!RegexValidator.isNotBlank(controlValue)) {
return ObjectMaker.toJson(AnnotationTypes["required"], config.message || null, [controlValue]);
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @return {?}
*/
function patternValidator(config) {
return function (control) {
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
config = ApplicationUtil.getConfigObject(config);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if (RegexValidator.isNotBlank(controlValue)) {
for (var pattern in config.pattern)
if (!(RegexValidator.isValid(controlValue, config.pattern[pattern])))
return ObjectMaker.toJson(pattern, config.message || null, [controlValue]);
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @param {?} conditionalValidationProps
* @return {?}
*/
function timeValidator(config, conditionalValidationProps) {
return function (control) {
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
config = ApplicationUtil.getConfigObject(config);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if (RegexValidator.isNotBlank(controlValue)) {
/** @type {?} */
var testResult = false;
/** @type {?} */
var valueLength = 5;
if (config.allowSeconds)
valueLength = 8;
testResult = RegexValidator.isValid(controlValue, RegExRule["time"]) && controlValue.length == valueLength;
if (!testResult)
return ObjectMaker.toJson(AnnotationTypes["time"], config.message || null, [controlValue]);
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @param {?} conditionalValidationProps
* @return {?}
*/
function urlValidator(config, conditionalValidationProps) {
return function (control) {
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
config = ApplicationUtil.getConfigObject(config);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if (RegexValidator.isNotBlank(controlValue)) {
if (!RegexValidator.isValid(controlValue, RegExRule["url"]))
return ObjectMaker.toJson(AnnotationTypes["url"], config.message || null, [controlValue]);
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @param {?} conditionalValidationProps
* @return {?}
*/
function jsonValidator(config, conditionalValidationProps) {
return function (control) {
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
config = ApplicationUtil.getConfigObject(config);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if (RegexValidator.isNotBlank(controlValue)) {
try {
/** @type {?} */
var parseValue = isNumeric(controlValue);
if (parseValue || controlValue == "true" || controlValue == "false") {
throw "invalid value";
}
/** @type {?} */
var json = JSON.parse(controlValue);
}
catch (ex) {
return ObjectMaker.toJson(AnnotationTypes["json"], config.message || null, [controlValue]);
}
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @return {?}
*/
function greaterThanValidator(config) {
return function (control) {
/** @type {?} */
var matchControl = control.root.get([config.fieldName]);
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var matchControlValue = (matchControl) ? matchControl.value : '';
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if (RegexValidator.isNotBlank(controlValue) && RegexValidator.isNotBlank(matchControlValue)) {
if (!(matchControl && parseFloat(controlValue) > parseFloat(matchControlValue)))
return ObjectMaker.toJson(AnnotationTypes["greaterThan"], config.message || null, [controlValue, matchControlValue]);
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @return {?}
*/
function greaterThanEqualToValidator(config) {
return function (control) {
/** @type {?} */
var matchControl = control.root.get([config.fieldName]);
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var matchControlValue = (matchControl) ? matchControl.value : '';
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if ((RegexValidator.isNotBlank(controlValue) && RegexValidator.isNotBlank(matchControlValue))) {
if (!(matchControl && parseFloat(controlValue) >= parseFloat(matchControlValue)))
return ObjectMaker.toJson(AnnotationTypes["greaterThanEqualTo"], config.message || null, [controlValue, matchControlValue]);
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {?} config
* @return {?}
*/
function lessThanEqualToValidator(config) {
return function (control) {
/** @type {?} */
var matchControl = control.root.get([config.fieldName]);
/** @type {?} */
var controlValue = control.value;
/** @type {?} */
var matchControlValue = (matchControl) ? matchControl.value : '';
/** @type {?} */
var formGroupValue = ApplicationUtil.getParentObjectValue(control);
/** @type {?} */
var parentObject = (control.parent) ? control.parent.value : undefined;
if (Linq.IsPassed(formGroupValue, config.conditionalExpression, parentObject)) {
if ((RegexValidator.isNotBlank(controlValue) && RegexValidator.isNotBlank(matchControlValue))) {
if (!(matchControl && parseFloat(controlValue) <= parseFloat(matchControlValue)))
return ObjectMaker.toJson(AnnotationTypes["lessThanEqualTo"], config.message || null, [controlValue, matchControlValue]);
}
}
return ObjectMaker.null();
};
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
/**
* @param {