@adonisjs/env
Version:
Environment variable manager for Node.js
98 lines (97 loc) • 2.98 kB
TypeScript
/**
* Env parser parses the environment variables from a string formatted
* as a key-value pair seperated using an `=`. For example:
*
* ```
* PORT=3333
* HOST=127.0.0.1
* ```
*
* The variables can reference other environment variables as well using `$`.
* For example:
*
* ```
* PORT=3333
* REDIS_PORT=$PORT
* ```
*
* The variables using characters other than letters can wrap variable
* named inside a curly brace.
*
* ```
* APP-PORT=3333
* REDIS_PORT=${APP-PORT}
* ```
*
* You can escape the `$` sign with a backtick.
*
* ```
* REDIS_PASSWORD=foo\$123
* ```
*
* ## Usage
*
* ```ts
* const parser = new EnvParser(envContents)
* const output = parser.parse()
*
* // The output is a key-value pair
* ```
*/
export declare class EnvParser {
#private;
/**
* Creates a new EnvParser instance
*
* @param envContents - Raw environment file contents
* @param appRoot - Application root directory URL
* @param options - Parser options
*/
constructor(envContents: string, appRoot: URL, options?: {
ignoreProcessEnv: boolean;
});
/**
* Define an identifier for any environment value. The callback is invoked
* when the value match the identifier to modify its interpolation.
*
* @deprecated use `EnvParser.defineIdentifier` instead
*/
/**
* Define an identifier for any environment value. The callback is invoked
* when the value match the identifier to modify its interpolation.
*
* @deprecated use `EnvParser.defineIdentifier` instead
* @param name - The identifier name
* @param callback - Callback function to process the identifier value
*/
static identifier(name: string, callback: (value: string) => Promise<string> | string): void;
/**
* Define an identifier for any environment value. The callback is invoked
* when the value match the identifier to modify its interpolation.
*
* @param name - The identifier name
* @param callback - Callback function to process the identifier value
*/
static defineIdentifier(name: string, callback: (value: string) => Promise<string> | string): void;
/**
* Define an identifier for any environment value, if it's not already defined.
* The callback is invoked when the value match the identifier to modify its
* interpolation.
*
* @param name - The identifier name
* @param callback - Callback function to process the identifier value
*/
static defineIdentifierIfMissing(name: string, callback: (value: string) => Promise<string> | string): void;
/**
* Remove an identifier
*
* @param name - The identifier name to remove
*/
static removeIdentifier(name: string): void;
/**
* Parse the env string to an object of environment variables.
*
* @returns Promise resolving to parsed environment variables
*/
parse(): Promise<NodeJS.Dict<string>>;
}