Socket
Socket
Sign inDemoInstall

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.4.0 to 0.5.0

src/index.js

10

package.json
{
"name": "get-env",
"version": "0.4.0",
"version": "0.5.0",
"description": "Return `dev`, `prod`, or optional extra environements based on `process.env.NODE_ENV`",

@@ -26,8 +26,14 @@ "license": "MIT",

],
"main": "src",
"dependencies": {
"lodash": "^2.4.1"
"lodash.isempty": "^4.4.0",
"lodash.isplainobject": "^4.0.6",
"lodash.isstring": "^4.0.1"
},
"scripts": {
"prepublish": "npm prune"
},
"engines": {
"node": ">=6"
}
}

15

README.md

@@ -17,3 +17,3 @@ [![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)

1. If your code tests against, `development` and `production` (for example), then you must only use those values for `NODE_ENV`. `get-env` library accepts multiple alternative values as rules for an environment, therefore you can make unlimited number aliases to the same environment same. This lets you forget about the exact string value you used in your code, which means you can use whatever value that comes naturally to your mind whenever you switch environments. All environment names matched by this library are case-insensitive as well.
1. If your code tests against, `development` and `production` (for example), then you must only use those values for `NODE_ENV`. `get-env` library accepts multiple alternative values as rules for an environment, therefore you can make unlimited number of aliases to the same environment same. This lets you forget about the exact string value you used in your code, which means you can use whatever value that comes naturally to your mind whenever you switch environments. All environment names matched by this library are case-insensitive as well.

@@ -52,10 +52,11 @@ 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.

```js
var nodeEnv = process.env.NODE_ENV;
var env;
if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'prod') {
if (nodeEnv === 'production' || nodeEnv === 'prod') {
env = 'prod';
} else if (process.env.NODE_ENV === 'staging') {
} else if (nodeEnv === 'staging') {
env = 'staging';
} else if (process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'testing') {
} else if (nodeEnv === 'test' || nodeEnv === 'testing') {
env = 'test';
} else if (process.env.NODE_ENV === 'dev' || process.env.NODE_ENV === 'development' || !process.env.NODE_ENV) {
} else if (nodeEnv === 'dev' || nodeEnv === 'development' || !nodeEnv) {
env = 'dev';

@@ -82,3 +83,3 @@ } else {

* `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 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`)

@@ -150,3 +151,3 @@ * Extra environments can be optionally added in various methods. (see the usage section below)

Copyright (c) 2014 Pilwon Huh
Copyright (c) 2014-2016 Pilwon Huh

@@ -153,0 +154,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy

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