zod-package-json v1.0.3
zod-package-json
Zod schema for the package.json file format.
This package exports a zod schema (and a TypeScript type) named PackageJson
that can parse most well-formed package.json files.
The schema includes all currently supported properties listed in the npm docs as well as additional well-known properties specific to TypeScript and Node.js.
The schema also preserves unknown properties, which can be accessed by indexing the parsed data with the desired string keys.
The schema only validates the listed properties against the expected type
but does not do any additional normalization such as merging similar properties.
If necessary, that can be done by extending the schema with zod methods such as
.transform() or .refine().
Useful resources
- Explore the API on jsDocs.io
- View package contents on unpkg
- View repository on GitHub
- Read the changelog on GitHub
Install
Using npm:
npm add zod-package-jsonUsing yarn:
yarn add zod-package-jsonUsing pnpm:
pnpm add zod-package-jsonUsing bun:
bun add zod-package-jsonUsage examples
import { PackageJson } from "zod-package-json";
// Parse data from a `package.json` file.
const packageJson = PackageJson.parse({
name: "foo",
version: "1.0.0",
unknownProp: "who knows",
});
// Access a known property.
packageJson.name; // "foo"
// Access an unknown property.
packageJson["unknownProp"]; // "who knows"License
MITCopyright (c) 2024 Edoardo Scibona
See LICENSE file.