UNPKG

698 BJavaScriptView Raw
1/* global process */
2/** @module io */
3
4const { 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 */
13const envOr = (key, defaultValue, postProcessor = x => x, { env } = process) => postProcessor(typeof key === 'string' && env && env[key.toUpperCase()]) || fnOrValue(defaultValue, key);
14
15module.exports = { envOr };