GithubHelp home page GithubHelp logo

get-env-var's Introduction

get-env-var

A little function that reads an environment variable from process.env with support for default values and a optional mapping function applied to the data read from the environment.

It will throw an exception if key can't be found and no default value is supplied.

build status modules status

npm badge

Example

var getEnvVar = require('get-env-var');

getEnvVar('SOME_VAL', 'defaultValue');
getEnvVar('SOME_INT_VAL', Number.parseInt);
getEnvVar('SOME_INT_VAL', 20, Number.parseInt);

Shorthands

The following shorthand methods currently exists. They have the same API as the generic method. The mapping function is applied to the transformed value.

Boolean

getEnvVar.boolean is a shorthand method that returns true if the value equals 'true' and false in all other cases.

Integer

getEnvVar.integer is a shorthand method that calls parseInt(value, 10).

License

MIT

get-env-var's People

Contributors

hnrc avatar kagrela avatar voldern avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

hnrc

get-env-var's Issues

Ability to apply mapping function over env var

Idea is to be able to apply mapping function on retrieved values. My idea is to have something like this:

const intEnv = getEnvVar("SOME_INT_ENV").map(Number.parseInt).required();

and for optional values with default

const intEnv = getEnvVar("SOME_INT_ENV").map(Number.parseInt).orDefaultValue(42);

but that breaks backwards compability. The other way could be to introduce third argument, but then you can't stack applied functions, and it looks a bit of awkward (esp. when you want to have a mapping function over a value that is required).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.