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.
 
 

31 lines
687 B

import {ArgumentError} from '../argument-error';
import {BasePredicate, testSymbol} from './base-predicate';
import {Ow} from '../..';
/**
* @hidden
*/
export class AnyPredicate<T = any> implements BasePredicate<T> {
constructor(
private readonly predicates: BasePredicate[]
) {}
// tslint:disable completed-docs
[testSymbol](value: T, main: Ow, label?: string) {
const errors = [
'Any predicate failed with the following errors:'
];
for (const predicate of this.predicates) {
try {
main(value, label as string, predicate);
return;
} catch (err) {
errors.push(`- ${err.message}`);
}
}
throw new ArgumentError(errors.join('\n'), main);
}
}