getenv
Advanced tools
Comparing version 0.6.0 to 0.7.0
@@ -5,2 +5,3 @@ var util = require("util"); | ||
var fallbacksDisabled = false; | ||
var throwError = true; | ||
@@ -10,2 +11,5 @@ function _value(varName, fallback) { | ||
if (value === undefined) { | ||
if (fallback === undefined && !throwError) { | ||
return value; | ||
} | ||
if (fallback === undefined) { | ||
@@ -132,2 +136,10 @@ throw new Error('GetEnv.Nonexistent: ' + varName + ' does not exist ' + | ||
getenv.disableErrors = function() { | ||
throwError = false; | ||
}; | ||
getenv.enableErrors = function() { | ||
throwError = true; | ||
}; | ||
module.exports = getenv; |
@@ -9,5 +9,6 @@ { | ||
"Jan Lehnardt", | ||
"Tim Ruffles <timruffles@gmail.com>" | ||
"Tim Ruffles <timruffles@gmail.com>", | ||
"Ashwani Agarwal <ashwani.a@outlook.com>" | ||
], | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"homepage": "https://github.com/ctavan/node-getenv", | ||
@@ -14,0 +15,0 @@ "repository": { |
@@ -100,3 +100,3 @@ # getenv | ||
baz: ["BAZ", "defaultval", "string"], // parse into type | ||
quux: ["QUUX", undefined, "integer"] // parse & throw | ||
quux: ["QUUX", undefined, "int"] // parse & throw | ||
}); | ||
@@ -126,2 +126,26 @@ | ||
### env.disableErrors() | ||
`getenv` won't throw any error. If a fallback value is provided, that will be returned, else `undefined` is returned. | ||
```javascript | ||
getenv.disableErrors(); | ||
console.log(getenv("RANDOM")); | ||
// undefined | ||
``` | ||
### env.enableErrors() | ||
Revert the effect of `disableErrors()`. | ||
```javascript | ||
getenv.disableErrors(); | ||
console.log(getenv("RANDOM")); | ||
// undefined | ||
getenv.enableErrors(); | ||
console.log(getenv("RANDOM")); | ||
// Error: GetEnv.Nonexistent: RANDOM does not exist and no fallback value provided. | ||
``` | ||
## Changelog | ||
@@ -154,2 +178,3 @@ | ||
- Tim Ruffles <timruffles@gmail.com>: `disableFallbacks()`, `url()` | ||
- Ashwani Agarwal <ashwani.a@outlook.com>: `disableErrors()`, `enableErrors()` | ||
@@ -156,0 +181,0 @@ ## License |
@@ -11,3 +11,3 @@ var assert = require('assert'); | ||
assert.throws(function() { | ||
getenv.string("url", "http://localhost"); | ||
getenv.string('url', 'http://localhost'); | ||
}); | ||
@@ -14,0 +14,0 @@ getenv.enableFallbacks(); |
@@ -38,5 +38,5 @@ var assert = require('assert'); | ||
process.env.TEST_GETENV_URL_1 = "tcp://localhost:80"; | ||
process.env.TEST_GETENV_URL_2 = "tcp://localhost:2993"; | ||
process.env.TEST_GETENV_URL_3 = "http://192.162.22.11:2993"; | ||
process.env.TEST_GETENV_URL_1 = 'tcp://localhost:80'; | ||
process.env.TEST_GETENV_URL_2 = 'tcp://localhost:2993'; | ||
process.env.TEST_GETENV_URL_3 = 'http://192.162.22.11:2993'; | ||
@@ -526,8 +526,8 @@ var tests = {}; | ||
var expected = [ | ||
{hostname: "localhost", port: "80", protocol: "tcp:"}, | ||
{hostname: "localhost", port: "2993", protocol: "tcp:"}, | ||
{hostname: "192.162.22.11", port: "2993", protocol: "http:"}, | ||
{hostname: 'localhost', port: '80', protocol: 'tcp:'}, | ||
{hostname: 'localhost', port: '2993', protocol: 'tcp:'}, | ||
{hostname: '192.162.22.11', port: '2993', protocol: 'http:'}, | ||
]; | ||
var prefix = "TEST_GETENV_URL_"; | ||
var prefix = 'TEST_GETENV_URL_'; | ||
@@ -534,0 +534,0 @@ expected.forEach(function(expectation, i) { |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 35 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
24155
9
614
181
40