Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ssssota/typedotenv

dotenv utility for TypeScript
https://github.com/ssssota/typedotenv

cli code-generation dotenv typescript unplugin vite webpack

Last synced: about 1 month ago
JSON representation

dotenv utility for TypeScript

Awesome Lists containing this project

README

        

# typedotenv

dotenv utility for TypeScript

## Example

_.env_

```ini
API_KEY=qwertyuiop
NEXT_PUBLIC_API_BASE_URL=http://example.com/
```

_env.ts_ (generated TypeScript code)

```ts
/* Auto generated by typedotenv */
if (typeof process.env.API_KEY !== 'string') throw new Error('API_KEY is not defined in .env');
export const API_KEY = process.env.API_KEY;
if (typeof process.env.NEXT_PUBLIC_API_BASE_URL !== 'string') throw new Error('NEXT_PUBLIC_API_BASE_URL is not defined in .env');
export const NEXT_PUBLIC_API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL;
```

`disableRuntimeTypeCheck:true` & `enableTypeAssetion:true` & `envObject:'import.meta.env'`

```ts
/* Auto generated by typedotenv */
export const API_KEY = import.meta.env.API_KEY as string;
export const NEXT_PUBLIC_API_BASE_URL = import.meta.env.NEXT_PUBLIC_API_BASE_URL as string;
```

## Usage

- [CLI](./packages/cli/README.md)
- [unplugin](./packages/unplugin/README.md) (e.g. Vite, Webpack, ...)
- [API](./packages/core/README.md)