import { Parser } from "./index"; import { EnsureParser, IParser, OrParser } from "./interfaces"; import { any } from "./simple-parsers"; export type SomeParsers = T extends [] | readonly [] ? IParser : T extends [infer A] | readonly [infer A] ? EnsureParser : T extends [infer A, ...infer B] | readonly [infer A, ...infer B] ? OrParser> : T extends Array | ReadonlyArray ? A : never; /** * Union is a good tool to make sure that the validated value * is in the union of all the validators passed in. Basically an `or` * operator for validators. */ export function some[]>( ...parsers: RestParsers ): SomeParsers { if (parsers.length <= 0) { return any as any; } const first = parsers.splice(0, 1)[0]; return parsers.reduce((left, right) => left.orParser(right), first) as any; }