Zod Utilz (zod_utilz) is a TypeScript library providing framework-agnostic utilities that extend the functionality of Zod. Currently at version 0.8.4, it aims to simplify common Zod tasks, fill feature gaps, and offer implementations for potential new Zod features. Key utilities include `SPR` for enhanced `SafeParseResult` handling, `makeErrorMap` for custom error maps, `coerce` for type coercion, and dedicated schemas like `json()` and `stringToJSON()` for JSON validation. The library maintains a steady release cadence, typically with minor versions introducing new utilities. It differentiates itself by focusing on practical, often-requested Zod extensions, while also striving for reduced bundle size by replacing internal dependencies like Lodash. It requires `zod` (`^3.22.4`) and `typescript` (`^5.0.0`) as peer dependencies.
npm install zod_utilzVerified import paths — ran on the pinned version, not inferred.
Demonstrates importing `zu` and using `zu.json()` and `zu.stringToJSON()` to validate JSON data from strings against a Zod schema, including success and error handling.
Ensure your project's `tsconfig.json` (if applicable) and bundler configuration (`moduleResolution`, `target`, `module`) are set for modern ES Modules (e.g., `"module": "nodenext"` or `"es2020"`). You may need to update your bundler or Node.js version.
Always import the `zu` object as a named export: `import { zu } from 'zod_utilz';`. Then access utilities as properties of `zu`, e.g., `zu.json()`, `zu.SPR()`, `zu.makeErrorMap()`.Ensure that `zod` and `typescript` are installed in your project at versions compatible with the specified peer dependency ranges. Update your `package.json` to reflect the required versions and reinstall dependencies (`npm install` or `yarn install`).
For most projects, importing `zu` and letting bundlers handle tree-shaking is sufficient. If extreme bundle size optimization for specific utilities is critical, evaluate your bundler's tree-shaking effectiveness, or consider the project's suggestion of direct code inclusion for the absolute minimum footprint.
Ensure you are using ES Module import syntax: `import { zu } from 'zod_utilz';`. If your project is CommonJS-only, you may need to configure your bundler (e.g., Webpack, Rollup) or Node.js environment to correctly resolve and transpile ESM imports.Verify `zod_utilz` is installed (`npm install zod_utilz`). Check the import path. For TypeScript, ensure `tsconfig.json` has `"moduleResolution": "Bundler"` or `"NodeNext"` to correctly resolve module types, especially if `zod_utilz` uses modern `exports` maps in its `package.json`.
Update `zod` to `^3.22.4` and `typescript` to `^5.0.0` or newer compatible versions in your `package.json`. Run `npm install` or `yarn install` to ensure the correct versions are used.