zod-search-params
Advanced tools
Comparing version 0.1.1 to 0.1.2
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.parseSearchParams = void 0; | ||
var schemaChanges = []; | ||
var modifySchema = function (zodType, key, object) { | ||
@@ -16,2 +17,3 @@ if (zodType._def.typeName === 'ZodBoolean') { | ||
zodType._def.coerce = true; | ||
schemaChanges.push(zodType._def); | ||
return; | ||
@@ -29,2 +31,3 @@ } | ||
zodType._def.coerce = true; | ||
schemaChanges.push(zodType._def); | ||
} | ||
@@ -38,2 +41,9 @@ return; | ||
}; | ||
var revertSchema = function () { | ||
schemaChanges.forEach(function (type) { | ||
if ('coerce' in type) { | ||
type.coerce = false; | ||
} | ||
}); | ||
}; | ||
var expectsArray = function (zodType) { | ||
@@ -101,5 +111,8 @@ if (!(zodType === null || zodType === void 0 ? void 0 : zodType._def)) | ||
try { | ||
return schema.parse(processedObject); | ||
var parsedQuery = schema.parse(processedObject); | ||
revertSchema(); | ||
return parsedQuery; | ||
} | ||
catch (_b) { | ||
revertSchema(); | ||
// @ts-expect-error Undefined is return only in specific case, not sure how to fix this on the types level | ||
@@ -106,0 +119,0 @@ return undefined; |
{ | ||
"name": "zod-search-params", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"private": false, | ||
"description": "Zod utility for parsing search params", | ||
"license": "MIT", | ||
"keywords": [ | ||
"zod", | ||
"search params", | ||
"query params", | ||
"url search params", | ||
"url query params", | ||
"next.js", | ||
@@ -11,0 +14,0 @@ "nextjs", |
@@ -16,3 +16,3 @@ # zod-search-params | ||
### Define Schema | ||
Do **NOT** use `coerce` in the schema, coerce is applied automatically (to prevent casting `undefined` to `"undefined"` etc.) for enabled types, when it's needed. | ||
```ts | ||
@@ -19,0 +19,0 @@ const schema = z.object({ |
11616
138