Socket
Socket
Sign inDemoInstall

umgebung

Package Overview
Dependencies
1
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    umgebung

hinoki source for environment variables


Version published
Weekly downloads
4
Maintainers
1
Install size
61.9 kB
Created
Weekly downloads
 

Readme

Source

umgebung

NPM Package Build Status Dependencies

hinoki source for environment variables

npm install umgebung

provided these envvars are set in your shell:

PORT=8080
ENABLE_ETAGS=true
DATABASE_URL="postgres://localhost:5432/my_database"
COMMISSION=0.1
API_CREDENTIALS='{"user": "foo", "password": "bar"}'

then with umgebung and the hinoki dependency injection system you can ask for envvars by their name in your code:

var hinoki = require('hinoki');
var umgebung = require('umgebung');

hinoki(umgebung, function(
  envIntPort,
  envBoolEnableEtags,
  envStringDatabaseUrl,
  envFloatCommision,
  maybeEnvStringApiKey,
  maybeEnvIntPoolSize,
  maybeEnvJsonApiCredentials
  env
) {
  assert(envIntPort === 8080);
  assert(envBoolEnableEtags === true);
  assert(envStringDatabaseUrl === 'postgres://localhost:5432/my_database');
  assert(envFloatCommission === 0.1);
  assert(maybeEnvStringApiKey === null);
  assert(maybeEnvIntPoolSize === null);

  assert(maybeEnvJsonApiCredentials.user === 'foo');
  assert(maybeEnvJsonApiCredentials.password === 'bar');

  assert(env.PORT === '8080');
  assert(env.ENABLE_ETAGS === 'true');
  assert(env.DATABASE_URL === 'postgres://localhost:5432/my_database');
  assert(env.COMMISSION === '0.1');
  assert(env.API_CREDENTIALS === '{"user": "foo", "password": "bar"}');
});

umgebung parses type and envvar name from dependency-names (function arguments), looks them up on process.env and converts them to the specified type.

unless names start with maybe an error is thrown if no such envvar is present or it is blank.

types Int, Bool, Float and Json throw if the envvar can't be converted into the type.

all that comes after the type is converted from camelcase to underscore-delimited-uppercase and looked up on process.env.


you can add your own types, change the env prefix and much more:

var myUmgebung = umgebung.configure({
  // you can provide the env to use (defaults to `process.env`)
  env: {
    PORT: '9090',
    COMMISSION: '0.1'
  },
  // you can change the prefixes
  prefix: 'umgebungsVariable',
  maybePrefix: 'vielleicht',
  // you can change the name of the dependency where the whole `env`
  // (see above) is provided (defaults to `'env'`)
  envDependencyName: 'umgebung'
  // you can add your own types
  typeHandlers: {
    zahl: function(parsed, value) {
      var result = parseInt(value, 10);
      if (isNaN(result)) {
        throw new Error('env var ' + parsed.envVarName + 'must be an integer');
      }
      return result;
    }
  }
});

hinoki(myUmgebung, function(
  umgebungsVariableZahlPort,
  vielleichtUmgebungsVariableZahlPoolSize,
  umgebungsVariableFloatCommission,
  umgebung
) {
  assert(umgebungsVariableZahlPort === 9090);
  assert(vielleichtUmgebungsVariableZahlPoolSize === null);
  assert(umgebungsVariableFloatCommission === 0.1);

  assert(umgebung.PORT === '9090');
  assert(umgebung.COMISSION === '0.1');
});

license: MIT

Keywords

FAQs

Last updated on 25 Jun 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc