processenv
Advanced tools
Comparing version
{ | ||
"name": "processenv", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "processenv parses environment variables.", | ||
@@ -27,6 +27,7 @@ "contributors": [ | ||
"devDependencies": { | ||
"assertthat": "4.0.2", | ||
"assertthat": "5.1.0", | ||
"nodeenv": "3.0.0", | ||
"roboter": "9.1.0", | ||
"uuidv4": "5.0.1" | ||
"roboter": "10.0.1", | ||
"semantic-release-configuration": "1.0.6", | ||
"uuidv4": "6.0.0" | ||
}, | ||
@@ -33,0 +34,0 @@ "repository": { |
@@ -12,3 +12,3 @@ # processenv | ||
| Dev dependencies |  | | ||
| Build | [](https://circleci.com/gh/thenativeweb/processenv/tree/master) | | ||
| Build |  | | ||
| License |  | | ||
@@ -66,15 +66,12 @@ | ||
#### Using the `||` operator | ||
#### Using the `??` operator | ||
Instead of providing a second parameter, you may use the `||` operator to handle default values. However, this may lead to problems with boolean values, e.g. if you want to use a default value of `true`: | ||
Instead of providing a second parameter, you may use the `??` operator to handle default values: | ||
```javascript | ||
// This will always evaluate to true, no matter whether ROOT is false or true. | ||
const isRoot = processenv('ROOT') || true; | ||
const isRoot = processenv('ROOT') ?? true; | ||
``` | ||
The underlying problem here is that when a value of `false` is given for the environment variable, the `||` operator automatically falls back to the `true` keyword, hence the result will always be `true`. | ||
*Please note that this is only true if you are using the `??` operator. If you are using the old-style `||` operator instead, the previous line always returns `true`, no matter what the actual value of the `ROOT` environment variable is. To avoid this problem, either use the `??` operator or use the previously shown syntax using a second parameter to provide a default value.* | ||
To avoid this problem, always use the previously shown syntax using a second parameter to provide default values. | ||
### Getting all environment variables | ||
@@ -81,0 +78,0 @@ |
9403
2.78%13
18.18%99
3.13%5
25%90
-3.23%