ngx-custom-validators
Version:
Angular custom directives for validation
1,378 lines (1,325 loc) • 68 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/forms')) :
typeof define === 'function' && define.amd ? define('ngx-custom-validators', ['exports', '@angular/core', '@angular/forms'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['ngx-custom-validators'] = {}, global.ng.core, global.ng.forms));
}(this, (function (exports, core, forms) { 'use strict';
function isPresent(obj) {
return obj !== undefined && obj !== null;
}
function isDate(obj) {
try {
var date = new Date(obj);
return !isNaN(date.getTime());
}
catch (e) {
return false;
}
}
function parseDate(obj) {
try {
// Moment.js
if (obj._d instanceof Date) {
var d = obj._d;
var month = +d.getMonth() + 1;
var day = +d.getDate();
return d.getFullYear() + "-" + formatDayOrMonth(month) + "-" + formatDayOrMonth(day);
}
// NgbDateStruct
if (typeof obj === 'object' && obj.year != null && obj.month != null && obj.day != null) {
var month = +obj.month;
var day = +obj.day;
return obj.year + "-" + formatDayOrMonth(month) + "-" + formatDayOrMonth(day);
}
}
catch (e) { }
return obj;
}
function formatDayOrMonth(month) {
return month < 10 ? "0" + month : month;
}
var arrayLength = function (value) {
return function (control) {
if (isPresent(forms.Validators.required(control))) {
return null;
}
var obj = control.value;
return Array.isArray(obj) && obj.length >= +value ? null : { arrayLength: { minLength: value } };
};
};
var ARRAY_LENGTH_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return ArrayLengthValidator; }),
multi: true
};
var ArrayLengthValidator = /** @class */ (function () {
function ArrayLengthValidator() {
}
ArrayLengthValidator.prototype.ngOnInit = function () {
this.validator = arrayLength(this.arrayLength);
};
ArrayLengthValidator.prototype.ngOnChanges = function (changes) {
for (var key in changes) {
if (key === 'arrayLength') {
this.validator = arrayLength(changes[key].currentValue);
if (this.onChange) {
this.onChange();
}
}
}
};
ArrayLengthValidator.prototype.validate = function (c) {
return this.validator(c);
};
ArrayLengthValidator.prototype.registerOnValidatorChange = function (fn) {
this.onChange = fn;
};
return ArrayLengthValidator;
}());
ArrayLengthValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[arrayLength][formControlName],[arrayLength][formControl],[arrayLength][ngModel]',
providers: [ARRAY_LENGTH_VALIDATOR]
},] }
];
ArrayLengthValidator.propDecorators = {
arrayLength: [{ type: core.Input }]
};
var base64 = function (control) {
if (isPresent(forms.Validators.required(control))) {
return null;
}
var v = control.value;
return /^(?:[A-Z0-9+\/]{4})*(?:[A-Z0-9+\/]{2}==|[A-Z0-9+\/]{3}=|[A-Z0-9+\/]{4})$/i.test(v) ? null : { base64: true };
};
var BASE64_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return Base64Validator; }),
multi: true
};
var Base64Validator = /** @class */ (function () {
function Base64Validator() {
}
Base64Validator.prototype.validate = function (c) {
return base64(c);
};
return Base64Validator;
}());
Base64Validator.decorators = [
{ type: core.Directive, args: [{
selector: '[base64][formControlName],[base64][formControl],[base64][ngModel]',
providers: [BASE64_VALIDATOR]
},] }
];
var creditCard = function (control) {
if (isPresent(forms.Validators.required(control))) {
return null;
}
var v = control.value;
var sanitized = v.replace(/[^0-9]+/g, '');
// problem with chrome
/* tslint:disable */
if (!(/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|(?:9792)\d{12})$/.test(sanitized))) {
return { creditCard: true };
}
/* tslint:enable */
var sum = 0;
var digit;
var tmpNum;
var shouldDouble;
for (var i = sanitized.length - 1; i >= 0; i--) {
digit = sanitized.substring(i, (i + 1));
tmpNum = parseInt(digit, 10);
if (shouldDouble) {
tmpNum *= 2;
if (tmpNum >= 10) {
sum += ((tmpNum % 10) + 1);
}
else {
sum += tmpNum;
}
}
else {
sum += tmpNum;
}
shouldDouble = !shouldDouble;
}
if (Boolean((sum % 10) === 0 ? sanitized : false)) {
return null;
}
return { creditCard: true };
};
var CREDIT_CARD_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return CreditCardValidator; }),
multi: true
};
var CreditCardValidator = /** @class */ (function () {
function CreditCardValidator() {
}
CreditCardValidator.prototype.validate = function (c) {
return creditCard(c);
};
return CreditCardValidator;
}());
CreditCardValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[creditCard][formControlName],[creditCard][formControl],[creditCard][ngModel]',
providers: [CREDIT_CARD_VALIDATOR]
},] }
];
var dateISO = function (control) {
if (isPresent(forms.Validators.required(control))) {
return null;
}
var v = control.value;
return /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/.test(v) ? null : { dateISO: true };
};
var DATE_ISO_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return DateISOValidator; }),
multi: true
};
var DateISOValidator = /** @class */ (function () {
function DateISOValidator() {
}
DateISOValidator.prototype.validate = function (c) {
return dateISO(c);
};
return DateISOValidator;
}());
DateISOValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[dateISO][formControlName],[dateISO][formControl],[dateISO][ngModel]',
providers: [DATE_ISO_VALIDATOR]
},] }
];
var date = function (control) {
if (isPresent(forms.Validators.required(control))) {
return null;
}
var v = control.value;
v = parseDate(v);
return isDate(v) ? null : { date: true };
};
var DATE_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return DateValidator; }),
multi: true
};
var DateValidator = /** @class */ (function () {
function DateValidator() {
}
DateValidator.prototype.validate = function (c) {
return date(c);
};
return DateValidator;
}());
DateValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[date][formControlName],[date][formControl],[date][ngModel]',
providers: [DATE_VALIDATOR]
},] }
];
var digits = function (control) {
if (isPresent(forms.Validators.required(control))) {
return null;
}
var v = control.value;
return /^\d+$/.test(v) ? null : { digits: true };
};
var DIGITS_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return DigitsValidator; }),
multi: true
};
var DigitsValidator = /** @class */ (function () {
function DigitsValidator() {
}
DigitsValidator.prototype.validate = function (c) {
return digits(c);
};
return DigitsValidator;
}());
DigitsValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[digits][formControlName],[digits][formControl],[digits][ngModel]',
providers: [DIGITS_VALIDATOR]
},] }
];
var email = function (control) {
if (isPresent(forms.Validators.required(control))) {
return null;
}
var v = control.value;
/* tslint:disable */
return /^(([^<>()\[\]\\.,;:\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,}))$/.test(v) ? null : { 'email': true };
/* tslint:enable */
};
var EMAIL_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return EmailValidator; }),
multi: true
};
var EmailValidator = /** @class */ (function () {
function EmailValidator() {
}
EmailValidator.prototype.validate = function (c) {
return email(c);
};
return EmailValidator;
}());
EmailValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[ngvemail][formControlName],[ngvemail][formControl],[ngvemail][ngModel]',
providers: [EMAIL_VALIDATOR]
},] }
];
var equalTo = function (equalControl) {
var subscribe = false;
return function (control) {
if (!subscribe) {
subscribe = true;
equalControl.valueChanges.subscribe(function () {
control.updateValueAndValidity();
});
}
var v = control.value;
return equalControl.value === v ? null : { equalTo: { control: equalControl, value: equalControl.value } };
};
};
var EQUAL_TO_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return EqualToValidator; }),
multi: true
};
var EqualToValidator = /** @class */ (function () {
function EqualToValidator() {
}
EqualToValidator.prototype.ngOnInit = function () {
this.validator = equalTo(this.equalTo);
};
EqualToValidator.prototype.validate = function (c) {
return this.validator(c);
};
return EqualToValidator;
}());
EqualToValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[equalTo][formControlName],[equalTo][formControl],[equalTo][ngModel]',
providers: [EQUAL_TO_VALIDATOR]
},] }
];
EqualToValidator.propDecorators = {
equalTo: [{ type: core.Input }]
};
var equal = function (val) {
return function (control) {
if (isPresent(forms.Validators.required(control))) {
return null;
}
var v = control.value;
return val === v ? null : { equal: { value: val } };
};
};
var EQUAL_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return EqualValidator; }),
multi: true
};
var EqualValidator = /** @class */ (function () {
function EqualValidator() {
}
EqualValidator.prototype.ngOnInit = function () {
this.validator = equal(this.equal);
};
EqualValidator.prototype.ngOnChanges = function (changes) {
for (var key in changes) {
if (key === 'equal') {
this.validator = equal(changes[key].currentValue);
if (this.onChange) {
this.onChange();
}
}
}
};
EqualValidator.prototype.validate = function (c) {
return this.validator(c);
};
EqualValidator.prototype.registerOnValidatorChange = function (fn) {
this.onChange = fn;
};
return EqualValidator;
}());
EqualValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[equal][formControlName],[equal][formControl],[equal][ngModel]',
providers: [EQUAL_VALIDATOR]
},] }
];
EqualValidator.propDecorators = {
equal: [{ type: core.Input }]
};
var gte = function (value) {
return function (control) {
if (!isPresent(value)) {
return null;
}
if (isPresent(forms.Validators.required(control))) {
return null;
}
var v = +control.value;
return v >= +value ? null : { gte: { value: value } };
};
};
var GREATER_THAN_EQUAL_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return GreaterThanEqualValidator; }),
multi: true
};
var GreaterThanEqualValidator = /** @class */ (function () {
function GreaterThanEqualValidator() {
}
GreaterThanEqualValidator.prototype.ngOnInit = function () {
this.validator = gte(this.gte);
};
GreaterThanEqualValidator.prototype.ngOnChanges = function (changes) {
for (var key in changes) {
if (key === 'gte') {
this.validator = gte(changes[key].currentValue);
if (this.onChange) {
this.onChange();
}
}
}
};
GreaterThanEqualValidator.prototype.validate = function (c) {
return this.validator(c);
};
GreaterThanEqualValidator.prototype.registerOnValidatorChange = function (fn) {
this.onChange = fn;
};
return GreaterThanEqualValidator;
}());
GreaterThanEqualValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[gte][formControlName],[gte][formControl],[gte][ngModel]',
providers: [GREATER_THAN_EQUAL_VALIDATOR]
},] }
];
GreaterThanEqualValidator.propDecorators = {
gte: [{ type: core.Input }]
};
var gt = function (value) {
return function (control) {
if (!isPresent(value)) {
return null;
}
if (isPresent(forms.Validators.required(control))) {
return null;
}
var v = +control.value;
return v > +value ? null : { gt: { value: value } };
};
};
var GREATER_THAN_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return GreaterThanValidator; }),
multi: true
};
var GreaterThanValidator = /** @class */ (function () {
function GreaterThanValidator() {
}
GreaterThanValidator.prototype.ngOnInit = function () {
this.validator = gt(this.gt);
};
GreaterThanValidator.prototype.ngOnChanges = function (changes) {
for (var key in changes) {
if (key === 'gt') {
this.validator = gt(changes[key].currentValue);
if (this.onChange) {
this.onChange();
}
}
}
};
GreaterThanValidator.prototype.validate = function (c) {
return this.validator(c);
};
GreaterThanValidator.prototype.registerOnValidatorChange = function (fn) {
this.onChange = fn;
};
return GreaterThanValidator;
}());
GreaterThanValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[gt][formControlName],[gt][formControl],[gt][ngModel]',
providers: [GREATER_THAN_VALIDATOR]
},] }
];
GreaterThanValidator.propDecorators = {
gt: [{ type: core.Input }]
};
var includedIn = function (includedInArr) {
return function (control) {
if (!isPresent(includedInArr)) {
return null;
}
if (isPresent(forms.Validators.required(control))) {
return null;
}
if (includedInArr.indexOf(control.value) < 0) {
return { includedIn: { value: control.value, reason: includedInArr } };
}
return null;
};
};
var INCLUDED_IN_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return IncludedInValidator; }),
multi: true
};
var IncludedInValidator = /** @class */ (function () {
function IncludedInValidator() {
}
IncludedInValidator.prototype.ngOnInit = function () {
this.validator = includedIn(this.includedIn);
};
IncludedInValidator.prototype.ngOnChanges = function (changes) {
for (var key in changes) {
if (key === 'includedIn') {
this.validator = includedIn(changes[key].currentValue);
if (this.onChange) {
this.onChange();
}
}
}
};
IncludedInValidator.prototype.validate = function (c) {
return this.validator(c);
};
IncludedInValidator.prototype.registerOnValidatorChange = function (fn) {
this.onChange = fn;
};
return IncludedInValidator;
}());
IncludedInValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[includedIn][formControlName],[includedIn][formControl],[includedIn][ngModel]',
providers: [INCLUDED_IN_VALIDATOR]
},] }
];
IncludedInValidator.propDecorators = {
includedIn: [{ type: core.Input }]
};
var json = function (control) {
if (isPresent(forms.Validators.required(control))) {
return null;
}
var v = control.value;
try {
var obj = JSON.parse(v);
if (Boolean(obj) && typeof obj === 'object') {
return null;
}
}
catch (e) { }
return { json: true };
};
var JSON_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return JSONValidator; }),
multi: true
};
var JSONValidator = /** @class */ (function () {
function JSONValidator() {
}
JSONValidator.prototype.validate = function (c) {
return json(c);
};
return JSONValidator;
}());
JSONValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[json][formControlName],[json][formControl],[json][ngModel]',
providers: [JSON_VALIDATOR]
},] }
];
var lte = function (value) {
return function (control) {
if (!isPresent(value)) {
return null;
}
if (isPresent(forms.Validators.required(control))) {
return null;
}
var v = +control.value;
return v <= +value ? null : { lte: { value: value } };
};
};
var LESS_THAN_EQUAL_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return LessThanEqualValidator; }),
multi: true
};
var LessThanEqualValidator = /** @class */ (function () {
function LessThanEqualValidator() {
}
LessThanEqualValidator.prototype.ngOnInit = function () {
this.validator = lte(this.lte);
};
LessThanEqualValidator.prototype.ngOnChanges = function (changes) {
for (var key in changes) {
if (key === 'lte') {
this.validator = lte(changes[key].currentValue);
if (this.onChange) {
this.onChange();
}
}
}
};
LessThanEqualValidator.prototype.validate = function (c) {
return this.validator(c);
};
LessThanEqualValidator.prototype.registerOnValidatorChange = function (fn) {
this.onChange = fn;
};
return LessThanEqualValidator;
}());
LessThanEqualValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[lte][formControlName],[lte][formControl],[lte][ngModel]',
providers: [LESS_THAN_EQUAL_VALIDATOR]
},] }
];
LessThanEqualValidator.propDecorators = {
lte: [{ type: core.Input }]
};
var lt = function (value) {
return function (control) {
if (!isPresent(value)) {
return null;
}
if (isPresent(forms.Validators.required(control))) {
return null;
}
var v = +control.value;
return v < +value ? null : { lt: { value: value } };
};
};
var LESS_THAN_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return LessThanValidator; }),
multi: true
};
var LessThanValidator = /** @class */ (function () {
function LessThanValidator() {
}
LessThanValidator.prototype.ngOnInit = function () {
this.validator = lt(this.lt);
};
LessThanValidator.prototype.ngOnChanges = function (changes) {
for (var key in changes) {
if (key === 'lt') {
this.validator = lt(changes[key].currentValue);
if (this.onChange) {
this.onChange();
}
}
}
};
LessThanValidator.prototype.validate = function (c) {
return this.validator(c);
};
LessThanValidator.prototype.registerOnValidatorChange = function (fn) {
this.onChange = fn;
};
return LessThanValidator;
}());
LessThanValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[lt][formControlName],[lt][formControl],[lt][ngModel]',
providers: [LESS_THAN_VALIDATOR]
},] }
];
LessThanValidator.propDecorators = {
lt: [{ type: core.Input }]
};
var maxDate = function (maxInput) {
var value;
var subscribe = false;
var maxValue = maxInput;
var isForm = maxInput instanceof forms.FormControl || maxInput instanceof forms.NgModel;
return function (control) {
if (!subscribe && isForm) {
subscribe = true;
maxInput.valueChanges.subscribe(function () {
control.updateValueAndValidity();
});
}
if (isForm) {
maxValue = maxInput.value;
}
value = parseDate(maxValue);
if (!isDate(value) && !(value instanceof Function)) {
if (value == null) {
return null;
}
else if (isForm) {
return { maxDate: { error: 'maxDate is invalid' } };
}
else {
throw Error('maxDate value must be or return a formatted date');
}
}
if (isPresent(forms.Validators.required(control))) {
return null;
}
var d = new Date(parseDate(control.value)).getTime();
if (!isDate(d)) {
return { value: true };
}
if (value instanceof Function) {
value = value();
}
return d <= new Date(value).getTime()
? null
: (isForm ? { maxDate: { control: maxInput, value: maxInput.value } } : { maxDate: { value: maxValue, control: undefined } });
};
};
var MAX_DATE_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return MaxDateValidator; }),
multi: true
};
var MaxDateValidator = /** @class */ (function () {
function MaxDateValidator() {
}
MaxDateValidator.prototype.ngOnInit = function () {
this.validator = maxDate(this.maxDate);
};
MaxDateValidator.prototype.ngOnChanges = function (changes) {
for (var key in changes) {
if (key === 'maxDate') {
this.validator = maxDate(changes[key].currentValue);
if (this.onChange) {
this.onChange();
}
}
}
};
MaxDateValidator.prototype.validate = function (c) {
return this.validator(c);
};
MaxDateValidator.prototype.registerOnValidatorChange = function (fn) {
this.onChange = fn;
};
return MaxDateValidator;
}());
MaxDateValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[maxDate][formControlName],[maxDate][formControl],[maxDate][ngModel]',
providers: [MAX_DATE_VALIDATOR]
},] }
];
MaxDateValidator.propDecorators = {
maxDate: [{ type: core.Input }]
};
var max = function (value) {
return function (control) {
if (!isPresent(value)) {
return null;
}
if (isPresent(forms.Validators.required(control))) {
return null;
}
var v = +control.value;
return v <= +value ? null : { max: { value: value } };
};
};
var MAX_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return MaxValidator; }),
multi: true
};
var MaxValidator = /** @class */ (function () {
function MaxValidator() {
}
MaxValidator.prototype.ngOnInit = function () {
this.validator = max(this.max);
};
MaxValidator.prototype.ngOnChanges = function (changes) {
for (var key in changes) {
if (key === 'max') {
this.validator = max(changes[key].currentValue);
if (this.onChange) {
this.onChange();
}
}
}
};
MaxValidator.prototype.validate = function (c) {
return this.validator(c);
};
MaxValidator.prototype.registerOnValidatorChange = function (fn) {
this.onChange = fn;
};
return MaxValidator;
}());
MaxValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[max][formControlName],[max][formControl],[max][ngModel]',
providers: [MAX_VALIDATOR]
},] }
];
MaxValidator.propDecorators = {
max: [{ type: core.Input }]
};
var minDate = function (minInput) {
var value;
var subscribe = false;
var minValue = minInput;
var isForm = minInput instanceof forms.FormControl || minInput instanceof forms.NgModel;
return function (control) {
if (!subscribe && isForm) {
subscribe = true;
minInput.valueChanges.subscribe(function () {
control.updateValueAndValidity();
});
}
if (isForm) {
minValue = minInput.value;
}
value = parseDate(minValue);
if (!isDate(value) && !(value instanceof Function)) {
if (value == null) {
return null;
}
else if (isForm) {
return { minDate: { error: 'minDate is invalid' } };
}
else {
throw Error('minDate value must be or return a formatted date');
}
}
if (isPresent(forms.Validators.required(control))) {
return null;
}
var d = new Date(parseDate(control.value)).getTime();
if (!isDate(d)) {
return { value: true };
}
if (value instanceof Function) {
value = value();
}
return d >= new Date(value).getTime()
? null
: (isForm ? { minDate: { control: minInput, value: minInput.value } } : { minDate: { value: minValue, control: undefined } });
};
};
var MIN_DATE_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return MinDateValidator; }),
multi: true
};
var MinDateValidator = /** @class */ (function () {
function MinDateValidator() {
}
MinDateValidator.prototype.ngOnInit = function () {
this.validator = minDate(this.minDate);
};
MinDateValidator.prototype.ngOnChanges = function (changes) {
for (var key in changes) {
if (key === 'minDate') {
this.validator = minDate(changes[key].currentValue);
if (this.onChange) {
this.onChange();
}
}
}
};
MinDateValidator.prototype.validate = function (c) {
return this.validator(c);
};
MinDateValidator.prototype.registerOnValidatorChange = function (fn) {
this.onChange = fn;
};
return MinDateValidator;
}());
MinDateValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[minDate][formControlName],[minDate][formControl],[minDate][ngModel]',
providers: [MIN_DATE_VALIDATOR]
},] }
];
MinDateValidator.propDecorators = {
minDate: [{ type: core.Input }]
};
var min = function (value) {
return function (control) {
if (!isPresent(value)) {
return null;
}
if (isPresent(forms.Validators.required(control))) {
return null;
}
var v = +control.value;
return v >= +value ? null : { min: { value: value } };
};
};
var MIN_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return MinValidator; }),
multi: true
};
var MinValidator = /** @class */ (function () {
function MinValidator() {
}
MinValidator.prototype.ngOnInit = function () {
this.validator = min(this.min);
};
MinValidator.prototype.ngOnChanges = function (changes) {
for (var key in changes) {
if (key === 'min') {
this.validator = min(changes[key].currentValue);
if (this.onChange) {
this.onChange();
}
}
}
};
MinValidator.prototype.validate = function (c) {
return this.validator(c);
};
MinValidator.prototype.registerOnValidatorChange = function (fn) {
this.onChange = fn;
};
return MinValidator;
}());
MinValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[min][formControlName],[min][formControl],[min][ngModel]',
providers: [MIN_VALIDATOR]
},] }
];
MinValidator.propDecorators = {
min: [{ type: core.Input }]
};
var notEqualTo = function (notEqualControl) {
var subscribe = false;
return function (control) {
if (!subscribe) {
subscribe = true;
notEqualControl.valueChanges.subscribe(function () {
control.updateValueAndValidity();
});
}
var v = control.value;
if (notEqualControl.value == null && v == null) {
return null;
}
return notEqualControl.value !== v ? null : { notEqualTo: { control: notEqualControl, value: notEqualControl.value } };
};
};
var NOT_EQUAL_TO_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return NotEqualToValidator; }),
multi: true
};
var NotEqualToValidator = /** @class */ (function () {
function NotEqualToValidator() {
}
NotEqualToValidator.prototype.ngOnInit = function () {
this.validator = notEqualTo(this.notEqualTo);
};
NotEqualToValidator.prototype.validate = function (c) {
return this.validator(c);
};
return NotEqualToValidator;
}());
NotEqualToValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[notEqualTo][formControlName],[notEqualTo][formControl],[notEqualTo][ngModel]',
providers: [NOT_EQUAL_TO_VALIDATOR]
},] }
];
NotEqualToValidator.propDecorators = {
notEqualTo: [{ type: core.Input }]
};
var notEqual = function (val) {
return function (control) {
if (isPresent(forms.Validators.required(control))) {
return null;
}
var v = control.value;
return val !== v ? null : { notEqual: { value: val } };
};
};
var NOT_EQUAL_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return NotEqualValidator; }),
multi: true
};
var NotEqualValidator = /** @class */ (function () {
function NotEqualValidator() {
}
NotEqualValidator.prototype.ngOnInit = function () {
this.validator = notEqual(this.notEqual);
};
NotEqualValidator.prototype.ngOnChanges = function (changes) {
for (var key in changes) {
if (key === 'notEqual') {
this.validator = notEqual(changes[key].currentValue);
if (this.onChange) {
this.onChange();
}
}
}
};
NotEqualValidator.prototype.validate = function (c) {
return this.validator(c);
};
NotEqualValidator.prototype.registerOnValidatorChange = function (fn) {
this.onChange = fn;
};
return NotEqualValidator;
}());
NotEqualValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[notEqual][formControlName],[notEqual][formControl],[notEqual][ngModel]',
providers: [NOT_EQUAL_VALIDATOR]
},] }
];
NotEqualValidator.propDecorators = {
notEqual: [{ type: core.Input }]
};
var notIncludedIn = function (includedInArr) {
return function (control) {
if (!isPresent(includedInArr)) {
return null;
}
if (isPresent(forms.Validators.required(control))) {
return null;
}
if (includedInArr.indexOf(control.value) >= 0) {
return { notIncludedIn: { value: control.value, reason: includedInArr } };
}
return null;
};
};
var NOT_INCLUDED_IN_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return NotIncludedInValidator; }),
multi: true
};
var NotIncludedInValidator = /** @class */ (function () {
function NotIncludedInValidator() {
}
NotIncludedInValidator.prototype.ngOnInit = function () {
this.validator = notIncludedIn(this.notIncludedIn);
};
NotIncludedInValidator.prototype.ngOnChanges = function (changes) {
for (var key in changes) {
if (key === 'notIncludedIn') {
this.validator = notIncludedIn(changes[key].currentValue);
if (this.onChange) {
this.onChange();
}
}
}
};
NotIncludedInValidator.prototype.validate = function (c) {
return this.validator(c);
};
NotIncludedInValidator.prototype.registerOnValidatorChange = function (fn) {
this.onChange = fn;
};
return NotIncludedInValidator;
}());
NotIncludedInValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[notIncludedIn][formControlName],[notIncludedIn][formControl],[notIncludedIn][ngModel]',
providers: [NOT_INCLUDED_IN_VALIDATOR]
},] }
];
NotIncludedInValidator.propDecorators = {
notIncludedIn: [{ type: core.Input }]
};
var notMatching = function (p) {
if (!isPresent(p)) {
return function (control) { return null; };
}
var patternValidator = forms.Validators.pattern(p);
return function (control) {
if (isPresent(forms.Validators.required(control))) {
return null;
}
if (!patternValidator(control)) {
return { notMatching: { value: control.value, reason: p } };
}
return null;
};
};
var NOT_MATCHING_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return NotMatchingValidator; }),
multi: true
};
var NotMatchingValidator = /** @class */ (function () {
function NotMatchingValidator() {
}
NotMatchingValidator.prototype.ngOnInit = function () {
this.validator = notMatching(this.notMatching);
};
NotMatchingValidator.prototype.ngOnChanges = function (changes) {
for (var key in changes) {
if (key === 'notMatching') {
this.validator = notMatching(changes[key].currentValue);
if (this.onChange) {
this.onChange();
}
}
}
};
NotMatchingValidator.prototype.validate = function (c) {
return this.validator(c);
};
NotMatchingValidator.prototype.registerOnValidatorChange = function (fn) {
this.onChange = fn;
};
return NotMatchingValidator;
}());
NotMatchingValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[notMatching][formControlName],[notMatching][formControl],[notMatching][ngModel]',
providers: [NOT_MATCHING_VALIDATOR]
},] }
];
NotMatchingValidator.propDecorators = {
notMatching: [{ type: core.Input }]
};
// tslint:disable-next-line:variable-name
var number = function (control) {
if (isPresent(forms.Validators.required(control))) {
return null;
}
var v = control.value;
return /^(?:-?\d+|-?\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(v) ? null : { number: true };
};
var NUMBER_VALIDATOR = {
provide: forms.NG_VALIDATORS,
useExisting: core.forwardRef(function () { return NumberValidator; }),
multi: true
};
var NumberValidator = /** @class */ (function () {
function NumberValidator() {
}
NumberValidator.prototype.validate = function (c) {
return number(c);
};
return NumberValidator;
}());
NumberValidator.decorators = [
{ type: core.Directive, args: [{
selector: '[number][formControlName],[number][formControl],[number][ngModel]',
providers: [NUMBER_VALIDATOR]
},] }
];
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (Object.prototype.hasOwnProperty.call(b, p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function () {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); };
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try {
step(generator.next(value));
}
catch (e) {
reject(e);
} }
function rejected(value) { try {
step(generator["throw"](value));
}
catch (e) {
reject(e);
} }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function () { if (t[0] & 1)
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f)
throw new TypeError("Generator is already executing.");
while (_)
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
return t;
if (y = 0, t)
op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return { value: op[1], done: false };
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2])
_.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
}
catch (e) {
op = [6, e];
y = 0;
}
finally {
f = t = 0;
}
if (op[0] & 5)
throw op[1];
return { value: op[0] ? op[1] : void 0, done: true };
}
}
var __createBinding = Object.create ? (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
}) : (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
o[k2] = m[k];
});
function __exportStar(m, o) {
for (var p in m)
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
__createBinding(o, m, p);
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m)
return m.call(o);
if (o && typeof o.length === "number")
return {
next: function () {
if (o && i >= o.length)
o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
}
catch (error) {
e = { error: error };
}
finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);