npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@d6v/zconf

v0.0.4

Published

Zod Validated Configuration files

Downloads

2

Readme

ZCONF

ZCONF is a TypeScript library for validating and parsing configuration files. It is based on the popular Zod library, which provides a simple and intuitive API for defining and validating data schemas.

Installation

To install ZCONF, use npm:

npm install @d6v/zconf

Usage

To use ZCONF, first define a schema for your configuration file using the Zod API. Then, use the parse function provided by ZCONF to parse and validate your configuration file.

Here's an example:

import { z } from "zod";
import { zconf } from "@d6v/zconf";

const schema = z.object({
  port: z.number().min(0).max(65535),
  host: z.string().optional(),
  debug: z.boolean().optional(),
});

const validatedEnv = zconf(schema, "./config.json");

In this example, we define a schema for a configuration file that has three properties: port, host, and debug. The port property is required and must be a number between 0 and 65535. The host and debug properties are optional and can be either a string or a boolean, respectively.

API

ZCONF provides the following API:

zconf(schema: z.ZodSchema, path: string): Promise<z.infer<z.ZodSchema>>

Detects, parses and validates a configuration file using the given Zod schema. Returns an object with the parsed values if the object is valid, or throws an error with a detailed error message if the object is invalid.

zjson(schema: z.ZodSchema, path: string): Promise<z.infer<z.ZodSchema>>

Parses and validates a JSON file using the given Zod schema. Returns an object with the parsed values if the object is valid, or throws an error with a detailed error message if the object is invalid.

zyaml(schema: z.ZodSchema, path: string): Promise<z.infer<z.ZodSchema>>

Parses and validates a YAML file using the given Zod schema. Returns an object with the parsed values if the object is valid, or throws an error with a detailed error message if the object is invalid.

ztoml(schema: z.ZodSchema, path: string): Promise<z.infer<z.ZodSchema>>

Parses and validates a TOML file using the given Zod schema. Returns an object with the parsed values if the object is valid, or throws an error with a detailed error message if the object is invalid.

zjsonc(schema: z.ZodSchema, path: string): Promise<z.infer<z.ZodSchema>>

Parses and validates a JSONC file using the given Zod schema. Returns an object with the parsed values if the object is valid, or throws an error with a detailed error message if the object is invalid.

zxml(schema: z.ZodSchema, path: string): Promise<z.infer<z.ZodSchema>>

Parses and validates an XML file using the given Zod schema. Returns an object with the parsed values if the object is valid, or throws an error with a detailed error message if the object is invalid.

zini(schema: z.ZodSchema, path: string): Promise<z.infer<z.ZodSchema>>

Parses and validates an INI file using the given Zod schema. Returns an object with the parsed values if the object is valid, or throws an error with a detailed error message if the object is invalid.

zconfFromString(schema: z.ZodSchema, data: string): z.infer<z.ZodSchema>

Detects, parses and validates a string using the given Zod schema. Returns an object with the parsed values if the object is valid, or throws an error with a detailed error message if the object is invalid.

zjsonFromString(schema: z.ZodSchema, data: string): z.infer<z.ZodSchema>

Parses and validates a JSON string using the given Zod schema. Returns an object with the parsed values if the object is valid, or throws an error with a detailed error message if the object is invalid.

zyamlFromString(schema: z.ZodSchema, data: string): z.infer<z.ZodSchema>

Parses and validates a YAML string using the given Zod schema. Returns an object with the parsed values if the object is valid, or throws an error with a detailed error message if the object is invalid.

ztomlFromString(schema: z.ZodSchema, data: string): z.infer<z.ZodSchema>

Parses and validates a TOML string using the given Zod schema. Returns an object with the parsed values if the object is valid, or throws an error with a detailed error message if the object is invalid.

zjsoncFromString(schema: z.ZodSchema, data: string): z.infer<z.ZodSchema>

Parses and validates a JSONC string using the given Zod schema. Returns an object with the parsed values if the object is valid, or throws an error with a detailed error message if the object is invalid.

zxmlFromString(schema: z.ZodSchema, data: string): z.infer<z.ZodSchema>

Parses and validates an XML string using the given Zod schema. Returns an object with the parsed values if the object is valid, or throws an error with a detailed error message if the object is invalid.

ziniFromString(schema: z.ZodSchema, data: string): z.infer<z.ZodSchema>

Parses and validates an INI string using the given Zod schema. Returns an object with the parsed values if the object is valid, or throws an error with a detailed error message if the object is invalid.

zconfSync(schema: z.ZodSchema, path: string): z.infer<z.ZodSchema>

Detects, parses and validates a configuration file using the given Zod schema. Returns an object with the parsed values if the object is valid, or throws an error with a detailed error message if the object is invalid.

zjsonSync(schema: z.ZodSchema, path: string): z.infer<z.ZodSchema>

Parses and validates a JSON file using the given Zod schema. Returns an object with the parsed values if the object is valid, or throws an error with a detailed error message if the object is invalid.

zyamlSync(schema: z.ZodSchema, path: string): z.infer<z.ZodSchema>

Parses and validates a YAML file using the given Zod schema. Returns an object with the parsed values if the object is valid, or throws an error with a detailed error message if the object is invalid.

ztomlSync(schema: z.ZodSchema, path: string): z.infer<z.ZodSchema>

Parses and validates a TOML file using the given Zod schema. Returns an object with the parsed values if the object is valid, or throws an error with a detailed error message if the object is invalid.

zjsoncSync(schema: z.ZodSchema, path: string): z.infer<z.ZodSchema>

Parses and validates a JSONC file using the given Zod schema. Returns an object with the parsed values if the object is valid, or throws an error with a detailed error message if the object is invalid.

zxmlSync(schema: z.ZodSchema, path: string): z.infer<z.ZodSchema>

Parses and validates an XML file using the given Zod schema. Returns an object with the parsed values if the object is valid, or throws an error with a detailed error message if the object is invalid.

ziniSync(schema: z.ZodSchema, path: string): z.infer<z.ZodSchema>

License

ZENV is licensed under the MIT License. See the LICENSE file for more information.