0.0.2 • Published 1 year ago
avalon-env v0.0.2
Avalon-Env
Avalon-Env is a utility package that provides a simple way to parse and validate environment variables using Zod. This package allows you to define a Zod schema for your environment variables and ensures they are parsed and validated correctly at runtime.
Features
- Parse environment variables according to a defined Zod schema
- Validate the parsed values to ensure they meet specified constraints
- Support for common data types such as strings, numbers, and booleans
Installation
To use Avalon-Env, ensure you have Node.js and npm installed, then run the following command to install the package:
npm install avalon-env
Usage
To use Avalon-Env, define a Zod schema that represents your environment variables, and then call the createEnv
function with this schema.
Example
import { createEnv } from 'avalon-env';
import { z } from 'zod';
// Define a Zod schema for environment variables
const schema = {
PORT: z.number(), // Expected to be a number
DEBUG_MODE: z.boolean(), // Expected to be a boolean
APP_NAME: z.string(), // Expected to be a string
};
// Create the environment using the schema
const env = createEnv(schema);
console.log(`App: ${env.APP_NAME}, Port: ${env.PORT}, Debug mode: ${env.DEBUG_MODE}`);
Contribution
Contributions are welcome! If you'd like to contribute, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Open a pull request with a clear description of your changes.
License
Avalon-Env is licensed under the MIT License.