/** * The error thrown when a required key is not found. */ export class EnvKeyNotFoundError extends Error { /** * Creates a new instance. * @param {string} key The key that wasn't found. */ constructor(key: string); /** * The key that wasn't found. * @type {string} */ key: string; } /** * The error thrown when a required key is present but is an empty string. */ export class EnvEmptyStringError extends Error { /** * Creates a new instance. * @param {string} key The key that wasn't found. */ constructor(key: string); /** * The key that wasn't found. * @type {string} */ key: string; } /** * A utility for interacting with environment variables * * @template {object} [T=Record] */ export class Env> { /** * Creates a new instance of Env. * @param {T} [source] The environment variable object to read from. */ constructor(source?: T); /** * The object from which to read environment information. * @type {T} */ source: T; /** * Retrieves an environment variable without checking for its presence. * * Returns a default value if the environment variable doesn't * exist. * * @overload * @param {string} key The environment variable name to retrieve. * @param {string|number|boolean} defaultValue The default value to return if the * environment variable is not found. * @returns {string} The environment variable value if found or undefined if not. */ get(key: string, defaultValue: string | number | boolean): string; /** * Retrieves an environment variable without checking for its presence. * * @overload * @param {string} key * @returns {string|undefined} */ get(key: string): string | undefined; /** * Determines if a given environment variable exists. * @param {string} key The environment variable name to check. * @returns {boolean} True if the environment variable exists, * false if not. */ has(key: string): boolean; /** * Retrieves the first environment variable found in a list of environment * variable names. * * Returns a default value if the environment variable doesn't * exist. * * @overload * @param {string[]} keys The environment variable name to retrieve. * @param {string|number|boolean} defaultValue The default value to return if the * environment variable is not found. Will be coerced to a string. * @returns {string} The environment variable value if found or undefined if not. * @throws {TypeError} If keys is not an array with at least one item. */ first(keys: string[], defaultValue: string | number | boolean): string; /** * Retrieves the first environment variable found in a list of environment * variable names. * * @overload * @param {string[]} keys * @returns {string|undefined} * @throws {TypeError} If keys is not an array with at least one item. */ first(keys: string[]): string | undefined; /** * Retrieves an environment variable. If the environment variable does * not exist or is an empty string, then it throws an error. * @param {string} key The environment variable name to retrieve. * @returns {string} The environment variable value. * @throws {Error} When the environment variable doesn't exist or is an * empty string. */ require(key: string): string; /** * Retrieves the first environment variable found in a list of environment * variable names and throws an error if none of the variables are found. * @param {string[]} keys An array of environment variable names. * @returns {string} The environment variable value. * @throws {TypeError} If keys is not an array with at least one item. * @throws {Error} When the environment variable doesn't exist or is an * empty string. */ requireFirst(keys: string[]): string; /** * Lazy-loading property containing a proxy that can be used to * automatically throw errors when an undefined environment variable * is accessed. * @returns {T} A proxy object. */ get exists(): T; /** * Lazy-loading property containing a proxy that can be used to * automatically throw errors when an undefined or empty string * environment variable is accessed. * @returns {T} A proxy object. */ get required(): T; } export namespace Env { export { EnvKeyNotFoundError as KeyNotFoundError }; export { EnvEmptyStringError as EmptyStringError }; }