2016-06-23 09:47:54 -07:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2016-06-08 15:36:24 -07:00
|
|
|
import {AbstractControl} from '../model';
|
2017-02-21 03:26:51 +03:00
|
|
|
import {AsyncValidator, AsyncValidatorFn, Validator, ValidatorFn} from './validators';
|
2016-06-08 15:36:24 -07:00
|
|
|
|
|
|
|
export function normalizeValidator(validator: ValidatorFn | Validator): ValidatorFn {
|
2016-11-11 10:47:34 -08:00
|
|
|
if ((<Validator>validator).validate) {
|
2016-06-08 15:36:24 -07:00
|
|
|
return (c: AbstractControl) => (<Validator>validator).validate(c);
|
|
|
|
} else {
|
|
|
|
return <ValidatorFn>validator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-21 03:26:51 +03:00
|
|
|
export function normalizeAsyncValidator(validator: AsyncValidatorFn | AsyncValidator):
|
|
|
|
AsyncValidatorFn {
|
|
|
|
if ((<AsyncValidator>validator).validate) {
|
|
|
|
return (c: AbstractControl) => (<AsyncValidator>validator).validate(c);
|
2016-06-08 15:36:24 -07:00
|
|
|
} else {
|
|
|
|
return <AsyncValidatorFn>validator;
|
|
|
|
}
|
|
|
|
}
|