0.0.4 • Published 12 months ago

@d6v/zconf v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

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.

0.0.4

12 months ago

0.0.3

12 months ago

0.0.2

12 months ago

0.0.1

12 months ago