1 | /* global process */
|
2 | /** @module io */
|
3 |
|
4 | const { fnOrValue } = require('../logic');
|
5 | /** Returns and parses an environment var and if does not exists returns the default value
|
6 | * @argument {String} key key to get from our environment variables
|
7 | * @argument {*} defaultValue default value to be returned if key not found
|
8 | * @argument {Function} postProcessor process the value once getted.
|
9 | * @argument {Object} env io source to read environment vars from
|
10 | * @returns {*}
|
11 | * @method
|
12 | */
|
13 | const envOr = (key, defaultValue, postProcessor = x => x, { env } = process) => postProcessor(typeof key === 'string' && env && env[key.toUpperCase()]) || fnOrValue(defaultValue, key);
|
14 |
|
15 | module.exports = { envOr };
|