New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

habitat

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

habitat - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

21

index.js

@@ -126,3 +126,24 @@ function habitat(prefix, defaults) {

/**
* Get an object with all of the stuff in the environment
*
* @return {Object}
*/
habitat.prototype.all = function all() {
var prefix = this.prefix;
var keys = Object.keys(process.env);
if (!prefix) return process.env;
return keys.reduce(function (accum, key) {
if (key.indexOf(prefix) === 0)
accum.push(key)
return accum;
}, []).reduce(function (obj, key) {
var lowerKey = key.replace(prefix + '_', '').toLowerCase();
obj[lowerKey] = habitat.parse(process.env[key]);
return obj;
}, {});
};
/**

@@ -129,0 +150,0 @@ * Get a key from the environment without a prefix.

2

package.json
{
"name": "habitat",
"version": "0.2.0",
"version": "0.2.1",
"description": "Small library for managing environment variables",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -36,3 +36,3 @@ # habitat [![Build Status](https://secure.travis-ci.org/brianloveswords/habitat.png)](http://travis-ci.org/brianloveswords/habitat)

In this case, your prefix will `'airsupport'` -- prefixes will be
In this case, your prefix will be `'airsupport'` -- the prefix will be
auto-capitalized because only barbarians use lowercase letters in their

@@ -59,3 +59,3 @@ environment variables.

## habitat#get(key, default)
## habitat#get(key, [*default*])

@@ -88,2 +88,20 @@ Gets a key from the environment. Automatically prefixes with the

## habitat#all()
Get an object with all of the things in the environment.
Example:
```bash
export APP_HOST='localhost'
export APP_PORT=3000
export APP_PROTO=http
```
```js
var env = new habitat('app');
var obj = env.all();
console.log(obj.host); // 'localhost'
```
## habitat#temp(object, callback)

@@ -105,3 +123,2 @@

// sync
var tempEnv = {

@@ -112,2 +129,3 @@ host: 'lolcathost'

// sync
env.temp(tempEnv, function() {

@@ -121,3 +139,3 @@ console.log(env.get('host')) // "lolcathost"

// async
env.temp({tempEnv, function(done)
env.temp(tempEnv, function(done)
process.nextTick(function(){

@@ -124,0 +142,0 @@ console.log(env.get('port')) // 5000

@@ -119,1 +119,11 @@ var fs = require('fs');

});
test('habitat#all', function (t) {
process.env['HABITAT_YEP'] = 'yeah';
process.env['HABITAT_NOPE'] = 'naw';
var env = new habitat('habitat');
var obj = env.all();
t.same(obj.yep, 'yeah');
t.same(obj.nope, 'naw');
t.end();
});
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