react-router-typesafe-routes
Version:
Enhanced type safety via validation for all route params in React Router v7.
22 lines (21 loc) • 867 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.schema = exports.configure = void 0;
const index_js_1 = require("../lib/index.js");
function configure({ parserFactory }) {
function schema(schema, parser) {
return (0, index_js_1.type)((value) => {
const result = schema["~standard"].validate(value);
if (result instanceof Promise)
throw new Error("Async validation is not supported");
if (result.issues) {
throw new Error(JSON.stringify(result.issues, null, 2));
}
return result.value;
}, parser !== null && parser !== void 0 ? parser : parserFactory("unknown"));
}
return { schema };
}
exports.configure = configure;
const { schema } = configure({ parserFactory: index_js_1.parser });
exports.schema = schema;
;