typed-env is a TypeScript-first library designed for parsing environment variables with strong type safety. Its current stable version is 2.0.0, which notably incorporates features from `neon-env` following a recent merge, indicating active development. This library provides mechanisms to define schemas for environment variables, ensuring that values are correctly parsed into specified types like numbers or URLs. Key differentiators include support for custom parsers, allowing complex transformations; the ability to define `choices` to restrict variable values to a predefined set of strings; and the flexibility to supply a custom `env` object instead of relying solely on `process.env`. It's particularly useful in applications requiring robust configuration management and type validation at runtime, helping prevent common configuration-related errors.
npm install typed-envVerified import paths — ran on the pinned version, not inferred.
Demonstrates defining and accessing typed environment variables, including numbers, string choices, and custom URL parsers, using the `createEnv` function with `process.env` and custom environment objects.
Ensure your Node.js environment meets the new minimum requirement by upgrading to Node.js 14.18.0+ or 16.0.0+.
Update all calls from `config(...)` to `createEnv(...)` in your codebase, including import statements.
For non-Node.js environments, explicitly pass a custom `env` object to `createEnv` via the `options` parameter, e.g., `createEnv(schema, { env: yourCustomEnvObject });`Change your import and function call from `config` to `createEnv`. For example: `import { createEnv } from 'typed-env';` and `createEnv(...)`.Ensure the environment variable (e.g., `NODE_ENV`) is set to one of the explicitly allowed values ('development', 'production') or update your `createEnv` schema to include the desired value in the `choices` array.Provide an explicit `env` object as the second argument to `createEnv`: `createEnv(schema, { env: { NODE_ENV: 'production' } });`No dependency data recorded yet.