react-router-typesafe-routes
Version:
Enhanced type safety via validation for all route params in React Router v7.
18 lines (17 loc) • 694 B
JavaScript
import { type, parser } from "../lib/index.mjs";
function configure({ parserFactory }) {
function schema(schema, parser) {
return 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 };
}
const { schema } = configure({ parserFactory: parser });
export { configure, schema };