Giter VIP home page Giter VIP logo

zod-package-json's Introduction

zod-package-json

Build status Coverage jsDocs.io Language npm License

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

Install

Using npm:

npm add zod-package-json

Using yarn:

yarn add zod-package-json

Using pnpm:

pnpm add zod-package-json

Using bun:

bun add zod-package-json

Usage 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

MIT

Copyright (c) 2024 Edoardo Scibona

See LICENSE file.

zod-package-json's People

Contributors

velut avatar dependabot[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.