mirror of https://github.com/lukechilds/ow.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
683 B
32 lines
683 B
import {ArgumentError} from '../argument-error';
|
|
import {Predicate} from './predicate';
|
|
import {BasePredicate, testSymbol} from './base-predicate';
|
|
import {Ow} from '../..';
|
|
|
|
/**
|
|
* @hidden
|
|
*/
|
|
export class AnyPredicate<T> implements BasePredicate<T> {
|
|
constructor(
|
|
private readonly predicates: Predicate[]
|
|
) {}
|
|
|
|
// tslint:disable completed-docs
|
|
[testSymbol](value: T, main: Ow) {
|
|
const errors = [
|
|
'Any predicate failed with the following errors:'
|
|
];
|
|
|
|
for (const predicate of this.predicates) {
|
|
try {
|
|
main(value, predicate);
|
|
|
|
return;
|
|
} catch (err) {
|
|
errors.push(`- ${err.message}`);
|
|
}
|
|
}
|
|
|
|
throw new ArgumentError(errors.join('\n'), main);
|
|
}
|
|
}
|
|
|