envimist
v0.0.4
Published
Applies minimist to process.env
Downloads
5
Readme
envimist
Applies minimist to process.env
Oh...
- cross-env — ok
- dotenv — ok
- Where's smth like arvg parser, env-utils?
- ...
- env
- xenv
- envx
- envar
- envars
- enve
- envex
- env-map
- env-util
- env-utils
Status
Working draft
Install
yarn add envimist
Usage
import envimist from 'envimist'
const envs = envimist()
envs.path // '/users/username/go/bin:/users/username/.kube:..'
envs.shell // '/bin/zsh'
envs.user // 'username'
// ...
You can provide some extra options to instruct the parser.
// Pass env records to parse. Defaults to process.env
const env = {
FOO: 'false'
}
// Regular minimist.Opts. Follow its docs for details
// https://github.com/minimistjs/minimist
const opts = {
boolean: ['foo']
}
const envs = envimist(env, opts)
envs.foo // === false
To resolve variables as arrays, set splitting params:
const env = {
FOO: 'bar,baz,qux',
ABC: 'a,b,c',
PATH: '/some/bin/path:/another/bin/dir'
}
const opts = {
split: ['foo']
}
// You can also specify a custom separator:
const opts1 = {
split: [['foo', ':']]
}
// Compbine diff vars with diff separators
const opts2 = {
split: [['path', ':'], ['foo', 'abc', ',']]
}
envimist(env, opts2)
// {
// foo: ['bar', 'baz', 'qux'],
// abc: ['a', 'b', 'c'],
// path: ['/some/bin/path', '/another/bin/dir'],
// _: []
// }