-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathenv-var.js
55 lines (46 loc) · 1.82 KB
/
env-var.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict'
const variable = require('./lib/variable')
const EnvVarError = require('./lib/env-error')
/**
* Returns an "env-var" instance that reads from the given container of values.
* By default, we export an instance that reads from process.env
* @param {Object} container target container to read values from
* @param {Object} extraAccessors additional accessors to attach to the
* resulting object
* @return {Object} a new module instance
*/
const from = (container, extraAccessors, logger) => {
return {
from: from,
/**
* This is the Error class used to generate exceptions. Can be used to identify
* exceptions and handle them appropriately.
*/
EnvVarError: require('./lib/env-error'),
/**
* Returns a variable instance with helper functions, or process.env
* @param {String} variableName Name of the environment variable requested
* @return {Object}
*/
get: function (variableName) {
if (!variableName) {
return container
}
if (arguments.length > 1) {
throw new EnvVarError('It looks like you passed more than one argument to env.get(). Since env-var@6.0.0 this is no longer supported. To set a default value use env.get(TARGET).default(DEFAULT)')
}
return variable(container, variableName, extraAccessors || {}, logger || function noopLogger () {})
},
/**
* Provides access to the functions that env-var uses to parse
* process.env strings into valid types requested by the API
*/
accessors: require('./lib/accessors/index'),
/**
* Provides a default logger that can be used to print logs.
* This will not print logs in a production environment (checks process.env.NODE_ENV)
*/
logger: require('./lib/logger')(console.log, container.NODE_ENV)
}
}
module.exports = from(process.env)