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

nenv

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nenv - npm Package Compare versions

Comparing version 0.2.5 to 0.3.0

9

lib/index.js

@@ -34,2 +34,7 @@ var defaults = ['test', 'devel', 'stage', 'production'];

function nenv(available, get, set) {
if(nenv.cache && !arguments.length) {
return nenv.cache;
}
if(typeof available === 'function') {

@@ -163,2 +168,6 @@ get = available;

if(!nenv.cache) {
nenv.cache = query;
}
return query;

@@ -165,0 +174,0 @@ }

6

package.json
{
"name": "nenv",
"description": "Utility for managing node development environments",
"version": "0.2.5",
"version": "0.3.0",
"author": "muji <noop@xpm.io>",

@@ -44,3 +44,4 @@ "main": "lib/index.js",

"install.md",
"usage.md"
"usage.md",
"api.md"
]

@@ -50,2 +51,3 @@ },

"title": "Example",
"text": "See [defaults.js](/defaults.js).",
"inc": "../../defaults.js",

@@ -52,0 +54,0 @@ "type": "code",

@@ -7,2 +7,3 @@ Table of Contents

* [Usage](#usage)
* [API](#api)
* [env([value])](#envvalue)

@@ -14,4 +15,11 @@ * [env.value](#envvalue)

* [env.set(val)](#envsetval)
* [env.defaults](#envdefaults)
* [Environments](#environments)
* [env.keys](#envkeys)
* [env.map](#envmap)
* [env.jsonify()](#envjsonify)
* [nenv.defaults](#nenvdefaults)
* [nenv.cache](#nenvcache)
* [nenv.get](#nenvget)
* [nenv.set](#nenvset)
* [Environments](#environments)
* [Getter](#getter)
* [Example](#example)

@@ -39,6 +47,2 @@ * [Developer](#developer)

```javascript
function nenv([environments, get, set])
```
```javascript
var env = require('nenv')();

@@ -48,3 +52,3 @@ if(!env.defined) {

// maybe: env.set(env.DEVEL) or whichever default you want
}else if(!env()) {
}else if(!env.valid) {
// do something when the specified environment is invalid

@@ -56,2 +60,8 @@ }else if(env.test) {

## API
```javascript
function nenv([environments, get, set])
```
* `environments`: Array or object of custom environments, if not specified the `defaults` are used.

@@ -63,3 +73,3 @@ * `get`: A custom function for getting the environment value (optional).

Determines if an environment value is valid. Returns `false` is the supplied value is invalid or the string key for the environment if valid.
Determines if an environment value is valid. Returns `false` if the supplied value is invalid or the string key for the environment if the value is a known environment alias.

@@ -88,4 +98,16 @@ If no value is supplied then `env.value` is used which allows testing whether the default value is valid by calling with no arguments.

### env.defaults
### env.keys
Array of environment keys.
### env.map
Map of environment keys to arrays of string aliases for the environment.
### env.jsonify()
Return an object suitable for passing to `JSON.stringify`.
### nenv.defaults
Default values to use.

@@ -97,14 +119,64 @@

### Environments
### nenv.cache
Pass an object or array to define your available environments:
A cache created the first time `nenv()` was invoked. Typically you would always want to share the same environment query:
```javascript
var nenv = require('nenv')
, env = nenv({production: ['production', 'pro'], dev: 'dev', test: 'test'});
console.log(env.keys);
, env = nenv()
, newenv = nenv()
// bypass cache and get a new query function using defaults
, altenv = nenv(true);
console.log(env === newenv);
console.log(env === altenv);
```
You can bypass the cached instance by passing arguments to `nenv()` or alternatively you could delete `nenv.cache` to force a new query to be created.
### nenv.get
Default `get` function.
### nenv.set
Default `set` function.
## Environments
Pass an object or array to define your available environments. Passing an object allows specifying multiple keys as aliases for the environment, useful to alias shortcuts for longer environment identifiers.
```javascript
var nenv = require('nenv');
console.dir(nenv(['test', 'dev', 'stage']));
console.dir(nenv({production: ['production', 'pro'], dev: 'dev', test: 'test'}));
```
## Getter
Use a fallback value by supplying a `get` function:
```javascript
var nenv = require('nenv');
function fallback() {
return process.env.NODE_ENV || this.PRODUCTION;
}
var env = nenv(fallback);
console.dir(env);
```
Or apply override logic to prefer another variable:
```javascript
var nenv = require('nenv');
function override() {
return process.env.ENV || process.env.NODE_ENV;
}
var env = nenv(override);
console.dir(env);
```
## Example
See [defaults.js](https://github.com/socialally/nenv/blob/master/defaults.js).
```javascript

@@ -111,0 +183,0 @@ var env = require('./')()

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