Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexandre-fernandez/dotenvtypegen
Generate types for your .env files.
https://github.com/alexandre-fernandez/dotenvtypegen
Last synced: 8 days ago
JSON representation
Generate types for your .env files.
- Host: GitHub
- URL: https://github.com/alexandre-fernandez/dotenvtypegen
- Owner: Alexandre-Fernandez
- License: mit
- Created: 2022-09-23T13:18:22.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-09-23T15:42:45.000Z (about 2 years ago)
- Last Synced: 2024-10-15T03:57:52.293Z (23 days ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/dotenvtypegen
- Size: 10.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# dotenvtypegen
> Generate types for your .env files.
## Installation
```
// npm
npm install -D dotenvtypegen
// yarn
yarn add -D dotenvtypegen
// pnpm
pnpm add -D dotenvtypegen
```## Usage
- Star the [github repo](https://github.com/alexandre-fernandez/dotenvtypegen) 😎
### CLI
```css
npx dotenvtypegen [path_to_env] --save [path_to_output]
```### Module
```ts
import { Env } from "dotenvtypegen"new Env("path/to/.env").save("path/to/output.d.ts")
```## Reference
### CLI
| Option | Shortcut | Argument | Description |
| ----------- | -------- | -------- | ----------------------------------------------------------- |
| --namespace | -ns | string | Sets the namespace name for the generated type |
| --interface | -in | string | Sets the interface name for the generated type |
| --header | -hd | string | Adds the given string at the top of the generated type file |
| --save | -sv | string | Where to save the generated file |
| --optional | -op | bool | Will make all the type properties optional |If multiple `.env` file paths are given the `.env` files will be merged.
#### Example
```css
npx dotenvtypegen [path_to_first_env] [path_to_second_env] -ns MyNamespace -in MyInterface -hd "/* eslint-disable eslint/some-rule */" -op -sv type.d.ts
```### Module
```ts
class Env {
private env: Record/**
* @param path If multiple paths are given, the corresponding `.env` files will be merged.
*/
constructor(
path: string | string[],
private options: Config = {
namespace: "NodeJS",
interface: "ProcessEnv",
header: "",
optional: false,
}
) {}/**
* @returns The type file's content corresponding to the current instance.
*/
generate() {}/**
* Saves the types corresponding to the current instance to the given path.
*/
save(path) {}
}
```