1.0.5 • Published 2 years ago

dotenvtypegen v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

dotenvtypegen

Generate types for your .env files.

Installation

// npm
npm install -D dotenvtypegen
// yarn
yarn add -D dotenvtypegen
// pnpm
pnpm add -D dotenvtypegen

Usage

CLI

npx dotenvtypegen [path_to_env] --save [path_to_output]

Module

import { Env } from "dotenvtypegen"

new Env("path/to/.env").save("path/to/output.d.ts")

Reference

CLI

OptionShortcutArgumentDescription
--namespace-nsstringSets the namespace name for the generated type
--interface-instringSets the interface name for the generated type
--header-hdstringAdds the given string at the top of the generated type file
--save-svstringWhere to save the generated file
--optional-opboolWill make all the type properties optional

If multiple .env file paths are given the .env files will be merged.

Example

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

class Env {
	private env: Record<string, unknown>

	/**
	 * @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) {}
}
1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

0.0.1

2 years ago