Socket
Socket
Sign inDemoInstall

now-env

Package Overview
Dependencies
0
Maintainers
3
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 3.0.0

39

lib/get-value.js
/**
* Get the secret value
* @param {String} key The secret key
* @param {Object} [secrets={}] The secrets map
* @return {String} The secret value
*/
function getSecretValue(key, secrets = {}) {
// check if the value is in the secret map
const value = secrets[key]
// if is defined return the secret
if (value !== undefined) return value
// try get the secret value without @ from the map
return secrets[key.slice(1)]
}
/**
* Get the value of a environment variable or secret

@@ -24,22 +9,26 @@ * @param {Object} env Map of environment variables

*/
function getValue(key, env, secrets = {}, required = {}) {
module.exports = (key, env, secrets = {}, required = {}) => {
let value
if (required.hasOwnProperty(key)) {
// get required value
// Get required value
value = required[key]
} else if (env.hasOwnProperty(key)){
// get environment value
// Get environment value
value = env[key]
} else {
// if the value is not defined throw an error
// If the value is not defined throw an error
throw new ReferenceError(`The environment variable ${key} is required.`)
}
// if the value doesn't start with @ (it's not a secret) return it
if (`${value}`.indexOf('@') !== 0) return value
// try get the secret secret or return the value
return getSecretValue(value, secrets) || value
// If the value doesn't start with @ (it's not a secret) return it
if (`${value}`.indexOf('@') !== 0) {
return value
}
// Otherwise, hand back the secret. This will
// intentionally return `undefined` if the secret
// is not defined so that the
// developers knows it is not defined.
return secrets[key]
}
module.exports = getValue
{
"name": "now-env",
"version": "2.0.0",
"version": "3.0.0",
"description": "Use `now.json` environment variables while developing",

@@ -5,0 +5,0 @@ "keywords": [

@@ -23,3 +23,3 @@ # now-env

That's all, you can now check in `process.env` for you environment variables!
That's all, you can now check `process.env` for the environment variables!

@@ -26,0 +26,0 @@ > If your application is running inside [Now](https://zeit.co/now) cloud then this module is not going to do anything and let Now set your environment variables.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc