-
-
Notifications
You must be signed in to change notification settings - Fork 929
Closed
Description
Hi, i want use dotenv for parse and merge objects manually, as it is done under the hood of this library.
I want to extract mechanism of modifying process.env by parsing result.
Can we figure out how to decompose config() function into for example config() and merge() or apply().
In this case config() will be looks like:
function config (options) {
// ...
try {
const parsed = parse(fs.readFileSync(dotenvPath, { encoding }));
apply({
target: process.env,
source: parsed,
options: { debug, override },
});
return { parsed }
} catch (err) {
// ...
}The apply() function may be looks like:
function apply ({ target, source, options }) {
const { override, debug, log } = options;
for (const key of Object.keys(source)) {
if (!Object.prototype.hasOwnProperty.call(target, key)) {
target[key] = source[key];
} else {
if (override === true) {
target[key] = source[key];
debug && log(`"${key}" is already defined and WAS overwritten`);
} else {
debug && log(`"${key}" is already defined and was NOT overwritten`);
}
}
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels