UNPKG

@traversets/code-extractor

Version:

The TypeScript Code Extractor and Analyzer can be handy for RAG (Retrieval-Augmented Generation) systems for codebases. It provides a detailed and structured representation of the codebase that can be converted into embeddings, enabling more effective adv

51 lines (50 loc) 2.29 kB
type ValueType = string | number | boolean; export declare class EnvManager { private envFilePath; private envVariables; private logger; constructor(envPath: string); /** * Initializes the environment variables by creating a new env file if it doesn't exist * and loading the variables from the file. * @throws {Error} If an error occurs while initializing the env file */ private initializeEnv; /** * Loads environment variables from a file. * Reads the file contents, splits them into key-value pairs, and stores them in the envVariables object. * @throws {Error} If there's an error reading the file, it will be logged and re-thrown. */ private loadEnvVariables; /** * Retrieves an environment variable value by its key. * Falls back to a default value if the variable is not set. * @param key - The key of the environment variable to retrieve * @param defaultValue - The default value to return if the variable is not set (optional) * @returns The parsed value of the environment variable, or the default value if it's not set */ get<T extends ValueType>(key: string, defaultValue?: T): T | undefined; /** * Sets an environment variable with the given key and value. * This method updates both the process.env object and the internal envVariables map. * It also updates the environment file to persist the changes. * @param key - The key of the environment variable to set * @param value - The value of the environment variable to set * */ set(key: string, value: string | number | boolean): void; /** * Removes an environment variable from the system and updates the env file. * This method is used to delete sensitive configuration variables after use. * @param key - The key of the environment variable to remove */ remove(key: string): void; private updateEnvFile; /** * Updates the environment file with the current environment variables. * This method iterates over the envVariables object, constructs the env file content, * and writes it to the file. If any error occurs during the process, it logs the error * and re-throws it. * */ private parseValue; } export {};