Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ssssota/typedotenv
dotenv utility for TypeScript
https://github.com/ssssota/typedotenv
cli code-generation dotenv typescript unplugin vite webpack
Last synced: 3 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 (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-12T12:00:41.000Z (over 1 year ago)
- Last Synced: 2024-10-11T12:15:09.956Z (4 months ago)
- Topics: cli, code-generation, dotenv, typescript, unplugin, vite, webpack
- Language: TypeScript
- Homepage: https://ssssota.github.io/typedotenv/
- Size: 169 KB
- Stars: 14
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
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)