Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to load validator specs from .example.env file #187

Closed
jpolvora opened this issue Mar 30, 2022 · 1 comment
Closed

Add option to load validator specs from .example.env file #187

jpolvora opened this issue Mar 30, 2022 · 1 comment

Comments

@jpolvora
Copy link

jpolvora commented Mar 30, 2022

It would be great if we could leverage our .env.example file to set and configure validators, since it's a common practive in developer teams to have this kind of file in projects.

The idea is to pass a config to cleanEnv function to load specs from the file path we pass to it or defaulting to .env.example and parse it as JSON, like this:

PORT={"validator": "port",  "options":  { default: 8000}}
API_KEY={"validator": "str", "options": { }}
const specs = {}
const env = envalid.cleanEnv(process.env, specs, { useExampleFile: '.env.example'})

The cleanEnv function must handle if we pass specs and useExampleFile, merging it or just use one or another.

I've already forked this project and I'm working on this feature. When ready and well tested, I will make a pull request to review.

@af
Copy link
Owner

af commented Apr 2, 2022

Hi, thanks for the idea! Since v7 though the goal is really to keep this a small and focused library, as much as possible. Envalid can be used in the browser so we need to keep it lean. You should definitely consider starting a separate wrapper library that parses that JSON format and turns it into a cleanEnv call– I just think that scope doesn't fit the core envalid project

@af af closed this as completed Apr 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants