Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

get-env

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-env - npm Package Compare versions

Comparing version 0.3.2 to 0.4.0

19

lib/index.js

@@ -5,3 +5,4 @@ var assert = require('assert');

var PROD_RULES = ['PROD', 'PRODUCTION'];
var DEV_RULES = ['dev', 'development'];
var PROD_RULES = ['prod', 'production'];

@@ -26,3 +27,3 @@ function _buildExtras(args) {

env: env,
rules: [env.toUpperCase()]
rules: [env.toLowerCase()]
});

@@ -45,3 +46,3 @@ });

env: env,
rules: [env.toUpperCase()]
rules: [env.toLowerCase()]
});

@@ -65,3 +66,3 @@ });

env: env,
rules: [rules.toUpperCase()]
rules: [rules.toLowerCase()]
});

@@ -72,3 +73,3 @@ } else {

rules: rules.map(function (rule) {
return rule.toUpperCase()
return rule.toLowerCase()
})

@@ -87,3 +88,3 @@ });

var extras = _buildExtras(args);
var nodeEnv = (process.env.NODE_ENV || '').toUpperCase();
var nodeEnv = (process.env.NODE_ENV || '').toLowerCase();
var extra;

@@ -102,5 +103,9 @@

return 'dev';
if (_.contains(DEV_RULES, nodeEnv) || nodeEnv === '') {
return 'dev';
}
throw new Error('Unknown environment name: NODE_ENV=' + nodeEnv);
}
module.exports = getEnv;
{
"name": "get-env",
"version": "0.3.2",
"version": "0.4.0",
"description": "Return `dev`, `prod`, or optional extra environements based on `process.env.NODE_ENV`",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -8,3 +8,5 @@ [![NPM](https://nodei.co/npm/get-env.png?downloads=false&stars=false)](https://npmjs.org/package/get-env) [![NPM](https://nodei.co/npm-dl/get-env.png?months=6)](https://npmjs.org/package/get-env)

* [get-config](https://github.com/pilwon/node-get-config) uses this library to parse `process.env.NODE_ENV`.
## Why use this library?

@@ -18,3 +20,3 @@

2. If you supply an unexpected value for `NODE_ENV` (for example, `productoin` instead of `production` -- that is a typo), the `env` variable is now set to this wrong value and the rest of code that tests against this variable would have an unexpected behavior. This library fixes this problem by matching the exact string values with `dev` acting as a catch-all, default environment.
2. If you supply an unregistered value for `NODE_ENV` (for example, `productoin` instead of `production` -- that is a typo), the `env` variable is now set to this wrong value and the rest of code that tests against this variable would have an unexpected behavior. This library fixes this problem by throwing an error on unregistered and non-empty value set to `NODE_ENV`. An empty value is resolved to `dev` environment.

@@ -37,8 +39,10 @@ 3. If you start adding more extra environments (ex: staging, test, etc.) then it won't be a simple one line of code anymore. This library provides consistent, straightforward, and flexible extra environment addition methods therefore you can freely add or remove environments with minimal overhead in your code while keeping all the above mentioned benefits.

```js
var nodeEnv = (process.env.NODE_ENV || 'development').toLowerCase();
var nodeEnv = (process.env.NODE_ENV || '').toLowerCase();
var env;
if (nodeEnv === 'prod' || nodeEnv === 'production') {
env = 'prod';
} else if (nodeEnv === 'dev' || nodeEnv === 'development' || nodeEnv === '') {
env = 'dev';
} else {
env = 'dev';
throw new Error('Unknown environment name: NODE_ENV=' + nodeEnv);
}

@@ -57,4 +61,6 @@ ```

env = 'test';
} else if (process.env.NODE_ENV === 'dev' || process.env.NODE_ENV === 'development' || !process.env.NODE_ENV) {
env = 'dev';
} else {
env = 'dev';
throw new Error('Unknown environment name: NODE_ENV=' + nodeEnv);
}

@@ -75,6 +81,7 @@ ```

* There are 2 default environments: `dev` and `prod`.
* `prod` is returned when any of the following values are set: `PROD`, `PRODUCTION`
* `dev` is returned when the value is empty or it has an unexpected value. (default environment)
* It always expects a case-insensitive value. (i.e. `NODE_ENV=prod` is equivalent to `NODE_ENV=PROD`)
* There are 2 pre-registered environments: `dev` and `prod`.
* `prod` is returned when any of the following values are set: `prod`, `production`
* `dev` is returned when the value is empty (default environment) or any of the following values are set: `dev`, `development`
* It throws an **error** when the value is unregistered and non-empty. (catches typos)
* It always expects a case-insensitive value. (i.e. `NODE_ENV=PROD` is equivalent to `NODE_ENV=prod`)
* Extra environments can be optionally added in various methods. (see the usage section below)

@@ -94,5 +101,5 @@

This returns either `dev` or `prod`. (default environments)
This returns either `dev` or `prod`. (pre-registered environments)
Extra environments can be optionally added in addition to the default environments (`dev` and `prod`) with any of the following methods:
Extra environments can be optionally added in addition to the pre-registered environments (`dev` and `prod`) with any of the following methods:

@@ -124,11 +131,11 @@ ### 1. Pass a string

var env = require('get-env')({
docker: 'DOCKER', // or 'docker'
test: ['TEST', 'TESTING'], // or ['test', 'testing']
prod: ['PR', 'PROD', 'PRODUCTION'] // or ['pr', 'prod', 'production']
docker: 'docker', // or 'DOCKER'
test: ['test', 'testing'], // or ['TEST', 'TESTING']
prod: ['pr', 'prod', 'production'] // or ['PR', 'PROD', 'PRODUCTION']
});
```
* Return `docker` when the value is `DOCKER`.
* Return `test` when the value is `TEST` or `TESTING`.
* Return `prod` when the value is `PR`, `PROD`, or `PRODUCTION`. (default `prod` rules are overriden)
* Return `docker` when the value is `docker`.
* Return `test` when the value is `test` or `testing`.
* Return `prod` when the value is `pr`, `prod`, or `production`. (pre-reigstered rules for `prod` are overriden)
* Otherwise, return `dev`.

@@ -135,0 +142,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc