envdeep
v1.0.0
Published
Parse environment variables into a nested object: FOO_BAR=1 → { foo: { bar: '1' } }
Maintainers
Readme
envdeep
Parse environment variables into a nested object.
npm i envdeepimport env from 'envdeep'
// FERO_RETRIES_MAX=5 FERO_HOST=localhost
env()
// → { fero: { retries: { max: '5' }, host: 'localhost' } }
env({ FOO_BAR: '1' }) // any object works as the source
// → { foo: { bar: '1' } }Rules
- Keys are lowercased and split on
_:FOO_BAR_BAZ→foo.bar.baz. - Values are left as strings. Coercion (
'5'→5) is the caller's job. - A scalar and a nested object on the same path: the object wins, in either
order.
FOO=5next toFOO_BAZ=6→{ foo: { baz: '6' } }. - Empty segments are ignored:
_FOO,FOO__BAR,FOO_behave likeFOO,FOO_BAR,FOO. undefinedvalues are skipped.
Zero dependencies. ESM only. Ships TypeScript types.
License
MIT
