Comparing version 0.2.1 to 0.2.2
var defaults = ['test', 'devel', 'stage', 'production']; | ||
/** | ||
* Default function for extracting the current environment. | ||
* Default function for getting the current environment. | ||
*/ | ||
function extract() { | ||
function dget() { | ||
return process.env.NODE_ENV; | ||
@@ -11,26 +11,36 @@ } | ||
/** | ||
* Default function for setting the current environment. | ||
*/ | ||
function dset(val) { | ||
var value = this.value; | ||
process.env.NODE_ENV = val; | ||
return function revert() { | ||
process.env.NODE_ENV = value; | ||
} | ||
} | ||
/** | ||
* Get an environment object. | ||
* | ||
* @param available Array or map of available environments. | ||
* @param opts Options used to control the behaviour. | ||
* @param get A custom get function. | ||
* | ||
* @return An environment object. | ||
*/ | ||
function nenv(available) { | ||
var init | ||
, k | ||
, arr | ||
, l | ||
function nenv(available, get, set) { | ||
if(typeof available === 'function') { | ||
get = available; | ||
available = null; | ||
} | ||
var k, arr, l | ||
, args = [].slice.call(arguments); | ||
// last arg is extract function | ||
if(args.length | ||
&& typeof args[args.length - 1] === 'function') { | ||
init = args[args.length - 1]; | ||
// last arg is get function | ||
if(args.length && typeof args[0] !== 'function') { | ||
args.shift(); | ||
} | ||
// use default function | ||
if(typeof init !== 'function') { | ||
init = extract; | ||
} | ||
// use default function(s) | ||
get = get || dget; | ||
set = set || dset; | ||
@@ -107,3 +117,3 @@ // available list as map is preferred | ||
// initial value | ||
query.value = init(); | ||
query.value = get(); | ||
@@ -116,5 +126,5 @@ // object map | ||
// reference function used to get | ||
// the current value | ||
query.get = extract; | ||
// get and set functions | ||
query.get = get.bind(query); | ||
query.set = set.bind(query); | ||
@@ -125,4 +135,5 @@ return query; | ||
nenv.defaults = defaults; | ||
nenv.extract = extract; | ||
nenv.dget = dget; | ||
nenv.dset = dset; | ||
module.exports = nenv; |
{ | ||
"name": "nenv", | ||
"description": "Utility for managing node development environments", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"author": "muji <noop@xpm.io>", | ||
@@ -6,0 +6,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6537
6
117