@zcorky/schema
Version:
Object schema validation written with TypeScript, inspired by dayjs and schema
26 lines • 831 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("./../core/constants");
const format_1 = require("@zodash/format");
const error_1 = require("./error");
exports.assert = (fn, message) => {
return (path, value, options) => {
if (!fn(value)) {
const name = options && options.name || constants_1.DEFAULT_OPTIONS.name;
const msg = format_1.format(message, {
...options,
name,
path,
value,
});
const detail = {
name: 'ValidationError',
message: msg,
path,
value,
};
throw new error_1.ValidationError(msg, detail);
}
};
};
//# sourceMappingURL=index.js.map