@yobta/validator
Version:
Tree-shakable es6 validator
9 lines (8 loc) • 341 B
JavaScript
import { rule } from '../rule/rule.js';
export const identicalMessage = (field, path) => `"${field}" should be identical to "${path}"`;
export const identical = (path, message = identicalMessage) => rule((input, { data, field }) => {
if (input === data[path]) {
return input;
}
throw new Error(message(field, path));
});