Skip to content

Add Support for Optional Environment Variables

Choose a tag to compare

@yasserfedsi yasserfedsi released this 26 Jun 20:36

envfy v0.4.0 Release Notes

New Features

Optional Environment Variables

Added support for optional environment variables using the new object schema.

Example:

validateEnv({
  API_KEY: {
    type: "string",
    optional: true,
  },
});

Behavior:

  • Missing optional variables are ignored.
  • Present optional variables are still validated.

Internal Improvements

New Type System

Moved all exported types into a dedicated src/types/ directory.

New exported types:

  • PrimitiveType
  • EnumType
  • EnvOption
  • SchemaValue
  • Schema

All types are now re-exported from the package entry point for cleaner imports.


Better Project Structure

Project structure is now organized as:

src/
├── errors/
├── types/
├── validators.ts
├── validateEnv.ts
└── index.ts

This separates:

  • validation logic
  • custom errors
  • exported types
  • public API

Test Improvements

Added tests for:

  • Missing optional variables
  • Optional variables with valid values
  • Optional variables with invalid values
  • Required variables still throwing when missing

Improved test isolation by cleaning all environment variables before each test.


Code Improvements

  • Introduced SchemaValue type alias.
  • Fixed optional object schema validation.
  • Normalized validation rules before processing.
  • Improved internal type safety.
  • Cleaned up validation logic for future extensibility.

Foundation for Future Versions

v0.4.0 prepares the library for upcoming features such as:

  • Default values (default)
  • Custom validators
  • Advanced schema options
  • Improved TypeScript inference