react-router-typesafe-routes
Version:
Enhanced type safety via validation for all route params in React Router v7.
30 lines (29 loc) • 1.08 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.yup = exports.configure = void 0;
const index_js_1 = require("../lib/index.js");
const yup_1 = require("yup");
function configure({ parserFactory }) {
function yup(schema, parser) {
let typeHint = "unknown";
if (!schema.spec.nullable) {
if (schema instanceof yup_1.StringSchema) {
typeHint = "string";
}
else if (schema instanceof yup_1.NumberSchema) {
typeHint = "number";
}
else if (schema instanceof yup_1.BooleanSchema) {
typeHint = "boolean";
}
else if (schema instanceof yup_1.DateSchema) {
typeHint = "date";
}
}
return (0, index_js_1.type)((value) => schema.validateSync(value), parser !== null && parser !== void 0 ? parser : parserFactory(typeHint));
}
return { yup };
}
exports.configure = configure;
const { yup } = configure({ parserFactory: index_js_1.parser });
exports.yup = yup;
;