I'm trying to convert an environment variable into an object of values for configuration in JavaScript but I don't know the best way to achieve this.
The idea would be to output SAMPLE_ENV_VAR=value as:
{
sample: {
env: {
var: value
}
}
}
What I have so far:
const _ = require('lodash');
const process = require('process');
_.each(process.env, (value, key) => {
key = key.toLowerCase().split('_');
// Convert to object here
}
Here's a more complete solution based on yours:
To simply put:
from process.env)['HELLO', 'WORLD', 'HI']){ hello: {} }->{ hello: { world: {} } }->{ hello: world: { hi: ? } } }){ hello: { world: { hi: 5 } } })