UNPKG

env-file-rw

Version:
57 lines (56 loc) 1.36 kB
declare enum NodeType { VARIABLE = 0, COMMENT = 1, UNKNOWN = 2 } interface TreeNode { key: string; value: string; type: NodeType; line: number | undefined; } interface DotenvFileTree { [key: string]: TreeNode; } export default class EnvFileWriter<Structure = never> { private tree; private treePendingChanges; private fileName; private parseSingleValue; /** * Categorize each line and it's type */ private constructTreeFromString; private applyPendingChangesOnString; /** * read the file and parse the content, synchronously */ parseSync(): DotenvFileTree; /** * read the file and parse the content */ parse(): Promise<DotenvFileTree>; /** * if immediateParse, content is parsed synchronously */ constructor(fileName: string, immediateParse?: boolean); exists(key: keyof Structure | string): boolean; /** * Get the value of a key */ get(key: keyof Structure, defaultValue?: unknown): string | undefined; /** * Set the value of a key * call .save() to persist changes */ set(key: string, value: string): void; /** * Persists the pending changes, synchronously */ saveSync(): void; /** * Persists the pending changes */ save(): Promise<void>; } export {};