1.1.3 • Published 2 years ago

@bebrasmell/zod-env v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Zod Environment parser

❗️ This package is now a part of Zodyac. Please consider using @zodyac/env instead.

npm version Build Status Coverage Status

This package allows you to parse your .env file or process.env safely.

Installation

Install the package:

npm i @bebrasmell/zod-env

Usage

Define your environment schema:

import { z } from 'zod';

const env_schema = z.object({
  // ... your zod schema
});

Don't forget to use z.coerce on types other than String!

Parse your environment using parse():

import { parse } from '@bebrasmell/zod-env';
const env = parse(env_schema);

You can also use z.default() to provide a fallback.

Now your env infers types from Zod schema.

Configuration

By default, parse falls back to process.env, if no .env file was found.

You can ignore process.env fallback by adding:

const env = parse(env_schema, {
  ignoreProcessEnv: true,
});

Or you can provide it's path using path parameter:

const env = parse(env_schema, {
  path: 'path/to/env.file',
  ignoreProcessEnv: true,
});
1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago