Comparing version 0.2.1 to 0.3.0
'use strict'; | ||
/*eslint-disable no-process-env*/ | ||
var nodeenv = function (key, value, callback) { | ||
var backupValues, | ||
environmentVariables; | ||
/* eslint-disable no-process-env */ | ||
const nodeenv = function (key, value) { | ||
let environmentVariables; | ||
if (typeof key === 'string') { | ||
if (typeof value === 'function') { | ||
callback = value; | ||
if (arguments.length === 1) { | ||
value = key; | ||
key = 'NODE_ENV'; | ||
} else if (typeof callback === 'undefined') { | ||
throw new Error('Callback is missing.'); | ||
} | ||
@@ -20,20 +16,16 @@ | ||
return nodeenv(environmentVariables, callback); | ||
return nodeenv(environmentVariables); | ||
} | ||
if (typeof value === 'undefined') { | ||
throw new Error('Callback is missing.'); | ||
} | ||
environmentVariables = key; | ||
callback = value; | ||
backupValues = {}; | ||
Object.keys(environmentVariables).forEach(function (envKey) { | ||
var envValue = environmentVariables[envKey]; | ||
const backupValues = {}; | ||
Object.keys(environmentVariables).forEach(envKey => { | ||
const envValue = environmentVariables[envKey]; | ||
backupValues[envKey] = process.env[envKey]; | ||
if (envValue === undefined) { | ||
delete process.env[envKey]; | ||
Reflect.deleteProperty(process.env, envKey); | ||
} else { | ||
@@ -44,15 +36,17 @@ process.env[envKey] = envValue; | ||
callback(function () { | ||
Object.keys(backupValues).forEach(function (backupKey) { | ||
var backupValue = backupValues[backupKey]; | ||
const restore = function () { | ||
Object.keys(backupValues).forEach(backupKey => { | ||
const backupValue = backupValues[backupKey]; | ||
if (!backupValue) { | ||
return delete process.env[backupKey]; | ||
Reflect.deleteProperty(process.env, backupKey); | ||
} | ||
process.env[backupKey] = backupValue; | ||
}); | ||
}); | ||
}; | ||
return restore; | ||
}; | ||
/*eslint-enable no-process-env*/ | ||
/* eslint-enable no-process-env */ | ||
module.exports = nodeenv; |
{ | ||
"name": "nodeenv", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "nodeenv enables tests to control Node.js environment variables.", | ||
@@ -13,10 +13,14 @@ "contributors": [ | ||
"email": "matthias.wagler@thenativeweb.io" | ||
}, | ||
{ | ||
"name": "Jan-Hendrik Grundhöfer", | ||
"email": "jan-hendrik.grundhoefer@thenativeweb.io" | ||
} | ||
], | ||
"main": "lib/nodeenv.js", | ||
"main": "dist/nodeenv.js", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"assertthat": "0.4.2", | ||
"grunt": "0.4.5", | ||
"tourism": "0.13.2" | ||
"assertthat": "0.10.3", | ||
"roboter": "0.15.4", | ||
"roboter-server": "0.15.4" | ||
}, | ||
@@ -27,3 +31,7 @@ "repository": { | ||
}, | ||
"keywords": [ | ||
"environment", | ||
"nodeenv" | ||
], | ||
"license": "MIT" | ||
} |
@@ -7,3 +7,5 @@ # nodeenv | ||
$ npm install nodeenv | ||
```shell | ||
$ npm install nodeenv | ||
``` | ||
@@ -15,3 +17,3 @@ ## Quick start | ||
```javascript | ||
var nodeenv = require('nodeenv'); | ||
const nodeenv = require('nodeenv'); | ||
``` | ||
@@ -22,8 +24,9 @@ | ||
```javascript | ||
nodeenv({ | ||
const restore = nodeenv({ | ||
NODE_ENV: 'dev' | ||
}, function (restore) { | ||
// ... | ||
restore(); | ||
}); | ||
// ... | ||
restore(); | ||
``` | ||
@@ -38,6 +41,7 @@ | ||
```javascript | ||
nodeenv('NODE_ENV', 'dev', function (restore) { | ||
// ... | ||
restore(); | ||
}); | ||
const restore = nodeenv('NODE_ENV', 'dev'); | ||
// ... | ||
restore(); | ||
``` | ||
@@ -50,6 +54,7 @@ | ||
```javascript | ||
nodeenv('dev', function (restore) { | ||
// ... | ||
restore(); | ||
}); | ||
nodeenv('dev'); | ||
// ... | ||
restore(); | ||
``` | ||
@@ -59,5 +64,7 @@ | ||
This module can be built using [Grunt](http://gruntjs.com/). Besides running the tests, this also analyses the code. To run Grunt, go to the folder where you have installed nodeenv and run `grunt`. You need to have [grunt-cli](https://github.com/gruntjs/grunt-cli) installed. | ||
To build this module use [roboter](https://www.npmjs.com/package/roboter). | ||
$ grunt | ||
```shell | ||
$ bot | ||
``` | ||
@@ -67,3 +74,3 @@ ## License | ||
The MIT License (MIT) | ||
Copyright (c) 2013-2015 the native web. | ||
Copyright (c) 2013-2017 the native web. | ||
@@ -70,0 +77,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
7082
122
75
0
1