swc/crates/swc_bundler/tests/.cache/deno/2848eaf794b78a575c19794382c82958390f8f78.ts
2021-11-09 20:42:49 +09:00

32 lines
761 B
TypeScript

// Loaded from https://deno.land/x/validasaur/src/rules/either.ts
import type { Validity, Rule } from "../types.ts";
import type { ValidationUtils } from "../interfaces.ts";
import { invalid } from "../utils.ts";
import { validateValue } from "../validate.ts";
export function either(
ruleSets: (Rule | Rule[])[],
errorCode: string = "either",
): Rule {
return async function eitherRule(
value: any,
utils: ValidationUtils,
): Promise<Validity> {
for (const ruleSet of ruleSets) {
const errs = await validateValue(
value,
ruleSet instanceof Array ? ruleSet : [ruleSet],
utils,
);
if (errs.length === 0) {
return undefined;
}
}
return invalid(errorCode, { value });
};
}