Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@juriadams/env

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@juriadams/env

A simple and type-safe way to validate environment variables.

latest
npmnpm
Version
0.0.1
Version published
Weekly downloads
100
12.36%
Maintainers
1
Weekly downloads
 
Created
Source

@juriadams/env

A simple and type-safe way to validate environment variables.

Install

bun add @juriadams/env
import { vars, optional } from '@juriadams/env';

const env = vars([
  'OPENAI_API_KEY',
  optional('PORT'),
] as const);

//    ^? const env: { OPENAI_API_KEY: string, PORT: string | null }

In case one or more of the configured environment variables is missing, an InvalidEnvironmentError is thrown. This error cann be matched via instanceof :

import { vars, InvalidEnvironmentError } from '@juriadams/env';

try {
  const env = vars(['OPENAI_API_KEY'] as const);
} catch (err
  if (err instanceof InvalidEnvironmentError)
    console.debug({ missing: err.missing });

  throw err;
)

Lifecycle

Develop

bun run dev

Build

bun run build

Types

bun run typecheck

Test

bun run test

FAQs

Package last updated on 20 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts