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

17 lines
492 B
TypeScript

// Loaded from https://deno.land/x/validasaur/src/rules/required_if.ts
import type { Validity, Rule } from "../types.ts";
import { required } from "./required.ts";
import { optionallyValid } from "../utils.ts";
export function requiredIf(field: string, fieldValue: any): Rule {
return function requiredIfRule(value: any, { getValue }): Validity {
const val = getValue(field);
if (val === fieldValue) {
return required(value);
}
return optionallyValid(true);
};
}