UNPKG

react-router-typesafe-routes

Version:

Enhanced type safety via validation for all route params in React Router v7.

29 lines (28 loc) 1.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.zod = exports.configure = void 0; const index_js_1 = require("../lib/index.js"); const zod_1 = require("zod"); function configure({ parserFactory }) { function zod(zodType, parser) { const unwrappedZodType = zodType instanceof zod_1.ZodOptional ? zodType.unwrap() : zodType; let typeHint = "unknown"; if (unwrappedZodType instanceof zod_1.ZodString) { typeHint = "string"; } else if (unwrappedZodType instanceof zod_1.ZodNumber) { typeHint = "number"; } else if (unwrappedZodType instanceof zod_1.ZodBoolean) { typeHint = "boolean"; } else if (unwrappedZodType instanceof zod_1.ZodDate) { typeHint = "date"; } return (0, index_js_1.type)((value) => zodType.parse(value), parser !== null && parser !== void 0 ? parser : parserFactory(typeHint)); } return { zod }; } exports.configure = configure; const { zod } = configure({ parserFactory: index_js_1.parser }); exports.zod = zod;