zard 1.1.2
zard: ^1.1.2 copied to clipboard
Zard is a schema validation and transformation library for Dart, inspired by the popular Zod library for JavaScript.
1.1.2 #
Additive introspection — no breaking changes.
- Export the wrapper schema types
ZOptional,ZNullableandZUnionso theirinner/schemascan be introspected (e.g. for OpenAPI / JSON Schema generation).ZDefaultwas already exported.
1.1.1 #
Introspection getters and small fixes — no breaking changes.
Added #
ZList.element— the item schema of a list.ZEnum.values— the allowed values of an enum.
These enable schema introspection (e.g. generating OpenAPI / JSON Schema from
zard schemas). Object shape (ZMap.schemas), ZOptional.inner,
ZNullable.inner, ZDefault.inner/defaultValue and ZUnion.schemas were
already public.
Fixed #
isNullable/isOptionalnow look through wrapper schemas, so a schema that is both nullable and optional reportstruefor both — whether built withnullish()(ZNullable(ZOptional(x))) ornullable().optional()(ZOptional(ZNullable(x))).- Removed an unreachable, always-throwing
null as Stringcast inZString.parse(a bareZStringis never nullable; nullability is handled by theZNullablewrapper).
1.1.0 #
Major performance refactor — zero breaking changes, all existing tests pass.
Performance #
- Precompiled all built-in
RegExppatterns (email, uuid, cuid, ipv4/6, iso*, hex, base64, jwt, nanoid, ulid, mac, cidr, etc.) asstatic final— previously recompiled on everyparse()call. - New no-throw internal
parseIntopath: container schemas (ZMap,ZList,ZUnion,ZInterface,TransformedSchema) and primitives (ZInt,ZDouble,ZNum,ZBool,ZString,ZEnum) write errors directly into a caller-provided sink instead of throwing per field/item. Eliminates the dominant try/catch cost in nested validation. - Reused
ParseContextacross calls via in-placeissues.clear()(no allocation perparse()). - Replaced
List.unmodifiablewrappers in hot paths with directvalidatorsInternal/transformsInternalgetters. - Removed redundant
ZardIssuere-wrap whenpathis empty. ZMap.parseusesfor-inoverentries(no closure allocation per field) and a singlevalue[key]lookup instead ofcontainsKey+ index.ZUnion.parseskips the innersafeParseindirection.ZDefault.parseusesrethrow(one allocation instead of three).
Benchmarks #
- Added
benchmark_harnessas dev dependency. - New canonical benchmark suite at
test/src/benchmarks/zard_harness_benchmark.dart. - Expanded Stopwatch-based suite at
test/src/benchmarks/zard_benchmark.dart(5k warmup + 100k iterations, parity with Zod). - Expanded
yup_benchmark.jsto match Zod's full scenario list (Transform, Default, Nullable, Union, safeParse). - New
run-all.shorchestrator runs Dart (JIT + AOT) + Node (Zod + Yup) in one shot.
Results (µs/op, Dart 3.11 JIT vs Node 24 V8) #
| Scenario | Zard 1.0.0 | Zard 1.1.0 | Zod | Yup |
|---|---|---|---|---|
| String valid | 0.36 | 0.05 | 0.11 | 1.27 |
| String invalid | — | 0.55 | 19.67 | 29.28 |
| Small object | 1.11 | 0.36 | 0.37 | 3.82 |
| Complex nested | 6.69 | 2.93 | 0.89 | 40.62 |
| Transform | — | 0.06 | 0.24 | 0.81 |
| Default | 0.04 | 0.01 | 0.06 | 0.74 |
| Union (int) | 0.83 | 0.08 | 0.16 | 1.19 |
Zard now beats Zod on 8 of 11 scenarios and is 6–60× faster than Yup across the board.
Notes #
- All public API preserved:
getValidators(),getTransforms(),getErrors(),addError(),clearErrors(), theissuesgetter, etc. - New (additive) API:
Schema.parseInto(value, path, sink)— internal use, callable but intended for container schemas.
1.0.0 #
- Add more validation rules, refine, parseAsync, safeParseAsync, coerce, strict.
0.0.26 #
- Fix optional schema from ZMap.
0.0.25 #
- Chore ZString and ZMap, add Iso, Regexes and ZStringBool.
0.0.24 #
- Add ZDefault to define a default value.
0.0.23 #
- Chore interfaces schemas to improve usability.
0.0.22 #
- Improve to add type result from safeParse.
0.0.21 #
- Update transform method.
0.0.20 #
- Fix path error from ZInt.
0.0.19 #
- Fix inferType refine validation and improve type safety.
0.0.18 #
- Chore nullable return from ZMap parse async, add file method and fix $enum type.
0.0.17 #
- Chore nullable return from ZMap parse.
0.0.16 #
- Add path key to ZardIssue.
0.0.15 #
- Add generic type to ZardResult.
0.0.14 #
- Export ZardResult type.
0.0.13 #
- Add z.interface, z.lazy, z.interType and transformTyped.
0.0.12 #
- Add ZardResult type and update custom message.
0.0.11 #
- Update ZMap Validation.
0.0.10 #
- Update ZardError type to Exception.
0.0.9 #
- Update validation .optional and .nullable.
0.0.7 #
- Export ZardError type.
0.0.6 #
- Export schema types.
0.0.5 #
- Add more validation rules, refine, parseAsync, safeParseAsync, coerce, strict.
0.0.5 #
- Update .parse validation rules.
0.0.4 #
- ZMap updated.
0.0.3 #
- Update README.md
0.0.2 #
- Add more validation rules.
0.0.1 #
- Initial version of the package.