zod-package-json
Version:
Zod schema for the package.json file format
38 lines (28 loc) • 1.18 kB
TypeScript
/**
This package exports a Zod mini schema (and the inferred TypeScript type) named `PackageJson`
that can parse most well-formed `package.json` files.
The schema includes all currently supported properties listed in the
{@link https://docs.npmjs.com/cli/v11/configuring-npm/package-json | 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 known properties against their 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 mini functions.
```typescript
import { PackageJson } from "zod-package-json/mini";
// 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"
```
*/
export { PackageJson } from "./package-json.js";