https://github.com/ssssota/typedotenv
dotenv utility for TypeScript
https://github.com/ssssota/typedotenv
cli code-generation dotenv typescript unplugin vite webpack
Last synced: 12 months ago
JSON representation
dotenv utility for TypeScript
- Host: GitHub
- URL: https://github.com/ssssota/typedotenv
- Owner: ssssota
- License: apache-2.0
- Created: 2023-02-15T08:22:13.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-01-06T10:22:43.000Z (about 1 year ago)
- Last Synced: 2025-03-08T18:03:27.428Z (about 1 year ago)
- Topics: cli, code-generation, dotenv, typescript, unplugin, vite, webpack
- Language: TypeScript
- Homepage: https://ssssota.github.io/typedotenv/
- Size: 245 KB
- Stars: 14
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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)