0.1.0 • Published 3 months ago

env-stub v0.1.0

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

✨ Env Stub

A simple library to ensure your environment variables are set and types are in sync.


❄️ Installation

First install the package using a package manager of your choice.

# using npm
npm install env-stub
# or pnpm
pnpm install env-stub
# or bun
bun add env-stub

🚀 Usage

// env.ts

import { InferStub, stubEnv } from "env-stub";
import { z } from "zod";

const env = stubEnv({
  URL: z.string().url(),
  PORT: z
    .string()
    .optional()
    .transform((val) => val ?? "3000"),
});

declare global {
  namespace NodeJS {
    interface ProcessEnv extends InferStub<typeof env> {}
  }
}

Now you need to import the env file in your application entry point to allow the stub to do its magic.

For example, in a Next.js application, you can import the env.ts file in the root layout.tsx file.

import "env.ts";

Just make sure to import the env.ts file before you use any environment variables.

then you can use the environment variables like you normally would.

console.log(process.env.URL);

No need to import env everywhere, just import it once and use process.env as you normally would.

You also need to include the env.ts file in your tsconfig.json file to allow TypeScript to pick up the types.

🐛 Reporting Bugs

If you encounter any bugs, please report them in the Issues.

🎋 Adding new features

You need to first fork this repository and then clone it to your local machine.

git clone https://github.com/[your-username]/env-stub
cd env-stub

Now you need to create a new branch for your changes. For features, you may want to use feat/[feature-name] as the branch name.

git checkout -b feat/[feature-name]

Now you can make your changes. After you are done, you need to commit your changes.

git add .
git commit -m "feat: ✨ My Awesome feature"

Now you need to push the changes to your forked repository.

git push origin feat/[feature-name]

Now you need to create a Pull Request to the original repository. And you are done!

We will review your changes and merge them if everything looks good.

💸 Sponsorship

If you find this plugin useful, please consider sponsoring me. This will help me spend more time on these projects.

📜 License

This project is licensed under the MIT License.

0.1.0

3 months ago

0.0.0

3 months ago