seniority/dotenv
Every export of seniority/dotenv, with its signature and doc comment: parse, populate, configDotenv, config, dotenv, plus 11 types.
import dotenv from 'seniority/dotenv';
import { parse, populate, configDotenv, … } from 'seniority/dotenv';Functions
config
dotenv's config: configDotenv, through the module object a stub can patch.
function config(options?: Partial<ConfigOptions>): ConfigResult;| Parameter | Type |
|---|---|
options (optional) | Partial<ConfigOptions> |
Returns ConfigResult
configDotenv
Read, parse and populate. Returns { parsed }, or { parsed, error } with the last error,
and never throws for a missing file — dotenv is loaded at import time, where a throw
takes the program down before it can say anything useful.
function configDotenv(given?: Partial<ConfigOptions>): ConfigResult;| Parameter | Type |
|---|---|
given (optional) | Partial<ConfigOptions> |
Returns ConfigResult
parse
Every KEY=value in a .env, as an object. Accepts the Buffer readFileSync hands back.
function parse(src: string | Buffer, options?: ParseOptions): Record<string, string>;| Parameter | Type |
|---|---|
src | string | Buffer |
options (optional) | ParseOptions |
Returns Record<string, string>
populate
Copy parsed into target and return what was actually set. Without override a key the
target already holds is left alone — the same rule seniority's own ORDER states as
env > config (R1), arrived at independently by dotenv and worth noticing. Either argument
that is not an object is OBJECT_REQUIRED, as dotenv 18 checks both before it reads either.
function populate(target: DotenvPopulateInput, parsed: DotenvPopulateInput, options?: PopulateOptions): DotenvPopulateOutput;| Parameter | Type |
|---|---|
target | DotenvPopulateInput |
parsed | DotenvPopulateInput |
options (optional) | PopulateOptions |
Returns DotenvPopulateOutput
Constants
default
The default export, declared as dotenv.
The default export, and why a drop-in subpath needs one.
const dotenv: {
config: typeof config;
configDotenv: typeof configDotenv;
parse: typeof parse;
populate: typeof populate;
};module.exports
What require() returns: the default export, dotenv, under the name Node's require(esm) reads.
Interfaces
ConfigOptions
interface ConfigOptions extends Omit<PopulateOptions, 'debug' | 'override'> {
/** Log what it does, through `console.log`; a string is read as dotenv reads it (`'false'`, `'0'`, … are false). */
debug?: boolean | string;
/** Replace keys the environment already has. */
override?: boolean | string;
/** Suppress the `injected env` line. Off by default, as in dotenv. */
quiet?: boolean | string | undefined;
/** Parse with the character scanner. */
fast?: boolean | string;
/** One file or several, highest priority first — an earlier file's key is not overwritten by a later one. `./.env` when omitted; a leading `~` is the home directory; a `URL` is read as one. */
path: string | URL | readonly (string | URL)[];
/** The object to populate; the process's own environment when omitted, as dotenv does (D-135). */
processEnv: Record<string, string | undefined>;
encoding?: BufferEncoding;
}ConfigResult
interface ConfigResult {
parsed?: Record<string, string>;
error?: Error;
}ParseOptions
interface ParseOptions {
/** Use the character scanner (dotenv's `{ fast: true }`) instead of the regular expression; read as dotenv reads a boolean. */
fast?: boolean | string | undefined;
}PopulateOptions
interface PopulateOptions {
/** Replace a key the target already has. Off by default: the real environment outranks a file. */
override?: boolean;
/** Report each key that was already defined, and whether it was overwritten. dotenv's own `_debug`. */
debug?: boolean;
}Types
DotenvConfigOptions
type DotenvConfigOptions = Partial<ConfigOptions>;DotenvConfigOutput
type DotenvConfigOutput = ConfigResult;DotenvParseOptions
type DotenvParseOptions = ParseOptions;DotenvParseOutput
type DotenvParseOutput = Record<string, string>;DotenvPopulateInput
type DotenvPopulateInput = Record<string, string | undefined>;DotenvPopulateOptions
type DotenvPopulateOptions = PopulateOptions;DotenvPopulateOutput
type DotenvPopulateOutput = Record<string, string | undefined>;