Skip to content

Commit be0f990

Browse files
committed
Add parsing rules
1 parent ebecd70 commit be0f990

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,34 @@ Parses URLSearchParams to JavaScript objects according to Zod schemas.
77

88
## Description
99

10-
TODO
10+
### Allowed Zod Schemas
11+
12+
- The top-level schema must be an `z.object()` or `z.union()` of `z.object()`.
13+
- Properties may be a `z.object()` or `z.union()` of objects.
14+
- All union object types must flatten to a parseable object schema with non-conflicting property types.
15+
- Primitive properties must be a `z.string()`, `z.number()`, `z.boolean()` or `z.date()`.
16+
- Properties must be a single-value type
17+
- The primitives `z.bigint()` and `z.symbol()` are not supported.
18+
- Strings with zero length are not allowed.
19+
If not specified, a `z.string()` is always assumed to be `z.string().min(1)`.
20+
- Using `z.enum()` is allowed and equivalent to `z.string()`.
21+
- Any property may be `z.optional()` or `z.never()`.
22+
- No property may `z.void()`, `z.undefined()`, `z.any()`, or `z.unknown()`.
23+
- Any property may be `z.nullable()` except `z.array()`.
24+
- Properties that are `z.literal()` are allowed and must still obey all of these rules.
25+
- A `z.array()` must be of a single value-type.
26+
- The value-types must obey all the same basic rules
27+
for primitive object, union, and property types.
28+
- Value-types may not be `z.nullable()` or `z.undefined()`.
29+
- The value-type cannot be an `z.array()` or contain a nested `z.array()` at any level.
30+
- A `z.record()` has less-strict schema constraints but weaker parsing guarantees:
31+
- They keys must be `z.string()`.
32+
- The value-type may be a single primitive type.
33+
- The value-type may be a union of primitives.
34+
This union must include `z.string()`
35+
and all values will be parsed as `z.string()`.
36+
- The value-type may be `z.nullable()`.
37+
- The value-type may not be a `z.record()`, `z.array()`, or `z.object()`.
1138

1239
## Installation
1340

0 commit comments

Comments
 (0)