All Projects → simonepri → env-dot-prop

simonepri / env-dot-prop

Licence: MIT license
♻️ Get, set, or delete nested properties of process.env using a dot path

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to env-dot-prop

envman
Manage your .env configuration easily
Stars: ✭ 20 (-35.48%)
Mutual labels:  environment-variables, env, environment-vars
envyable
The simplest yaml to ENV config loader.
Stars: ✭ 78 (+151.61%)
Mutual labels:  environment-variables, env, environment-vars
angular-environment
AngularJS Environment Plugin
Stars: ✭ 78 (+151.61%)
Mutual labels:  environment-variables, environment-vars
envfile
Parse and write environment files with Node.js
Stars: ✭ 42 (+35.48%)
Mutual labels:  environment-variables, env
dotenvy
Speed up your production sites by ditching .env for key/value variable pairs as Apache, Nginx, and shell equivalents
Stars: ✭ 31 (+0%)
Mutual labels:  environment-variables, env
gatsby-plugin-dynamic-routes
Creating dynamic routes based on your environment and/or renaming existing routes
Stars: ✭ 14 (-54.84%)
Mutual labels:  environment-variables, env
envmnt
Environment variables utility functions.
Stars: ✭ 16 (-48.39%)
Mutual labels:  environment-variables, environment-vars
checkdotenv
Verify environment variables presence for Node JS.
Stars: ✭ 12 (-61.29%)
Mutual labels:  environment-variables, env
ts-dotenv
Strongly-typed environment variables for Node.js
Stars: ✭ 18 (-41.94%)
Mutual labels:  environment-variables, env
tfenv
Transform environment variables for use with Terraform (e.g. `HOSTNAME` ⇨ `TF_VAR_hostname`)
Stars: ✭ 120 (+287.1%)
Mutual labels:  environment-variables, env
envsafe
🔒 Makes sure you don't accidentally deploy apps with missing or invalid environment variables.
Stars: ✭ 705 (+2174.19%)
Mutual labels:  environment-variables, env
envclasses
envclasses is a library to map fields on dataclass object to environment variables.
Stars: ✭ 26 (-16.13%)
Mutual labels:  environment-variables, env
env
A lightweight package for loading OS environment variables into structs for Go projects
Stars: ✭ 24 (-22.58%)
Mutual labels:  environment-variables, env
aws-export-profile
Export AWS profiles to your shell environment
Stars: ✭ 45 (+45.16%)
Mutual labels:  environment-variables, environment-vars
sicher
Sicher is a go module that allows secure storage of encrypted credentials in a version control system.
Stars: ✭ 27 (-12.9%)
Mutual labels:  environment-variables, env
Node Convict
Featureful configuration management library for Node.js
Stars: ✭ 1,855 (+5883.87%)
Mutual labels:  environment-variables, env
fuck-env
Fuck environment variables everywhere
Stars: ✭ 14 (-54.84%)
Mutual labels:  environment-variables, env
goodconf
Transparently load variables from environment or JSON/YAML file.
Stars: ✭ 80 (+158.06%)
Mutual labels:  environment-variables, env
ini
📝 Go INI config management. support multi file load, data override merge. parse ENV variable, parse variable reference. Dotenv file parse and loader. INI配置读取管理,支持多文件加载,数据覆盖合并, 解析ENV变量, 解析变量引用。DotEnv 解析加载
Stars: ✭ 72 (+132.26%)
Mutual labels:  environment-variables, env
webpack-dotenv-plugin
Use dotenv with webpack.
Stars: ✭ 53 (+70.97%)
Mutual labels:  environment-variables, env

env-dot-prop

Latest version on npm Downloads on npm Project license Awesome project
Lint status Test macOS status Test Ubuntu status Test Windows status
Codecov Coverage report Known Vulnerabilities Dependency Status
XO Code Style used AVA Test Runner used Istanbul Test Coverage used NI Scaffolding System used NP Release System used

♻️ Get, set, or delete nested properties of process.env using a dot path
Coded with ❤️ by Simone Primarosa.

Background

This package aim to let you access to your environment variables as if they were JavaScript object. See this guide to understand how to use this package to create a 12 Factor compliant configuration system for you app.

Install

$ npm install --save env-dot-prop

Usage

const envDotProp = require('env-dot-prop');

// Let's assume process.env contains the following keys
process.env = {
  FOO_BAR: 'unicorn',
  'FOO_DOT.DOT': 'pony',
  'FOO_UND\\_UND': 'whale'
};

console.log(process.env);
// => { FOO_BAR: 'unicorn', 'FOO_DOT.DOT': 'pony', 'FOO_UND\_UND': 'whale' }
envDotProp.get('');
// => { foo: { bar: 'unicorn', 'dot.dot': 'pony', und_und: 'whale' } }

// getter
envDotProp.get('foo.bar');
// => 'unicorn'

envDotProp.get('foo.notDefined.deep');
// => undefined

envDotProp.get('foo.notDefined.deep', 'default value');
// => 'default value'

envDotProp.get('foo.dot\\.dot');
// => 'pony'

// setter
envDotProp.set('foo.bar', 'b');
envDotProp.get('foo.bar');
// => 'b'

envDotProp.get('');
// => { foo: { bar: 'b', 'dot.dot': 'pony', und_und: 'whale' } }

envDotProp.set('foo.baz.e', 'x');
envDotProp.get('foo.baz.e');
// => 'x'
envDotProp.get('foo.baz');
// => { e: 'x' }

envDotProp.get('');
// => { foo: { bar: 'b', baz: { e: 'x' }, 'dot.dot': 'pony', und_und: 'whale' } }

// has
envDotProp.has('foo.bar');
// => true

// deleter
envDotProp.delete('foo.bar');
envDotProp.get('foo');
// => { baz: { e: 'x' }, 'dot.dot': 'pony', und_und: 'whale' }

envDotProp.delete('foo.baz.e');
envDotProp.get('foo.baz');
// => undefined

envDotProp.set('n1', 42, {stringify: false});
envDotProp.get('n1', {parse: false});
// => 42
envDotProp.get('n1', {parse: true});
// => 42

envDotProp.set('n2', 42, {stringify: true});
envDotProp.get('n2', {parse: false});
// => '42'
envDotProp.get('n2', {parse: true});
// => 42

envDotProp.set('n3', 42);
envDotProp.get('n3');
// => 42

envDotProp.set('n4', '42');
envDotProp.get('n4');
// => '42'

envDotProp.get('');
// => { n1: '42', n1: 42, n3: 42, n4: '42', foo: { 'dot.dot': 'pony', und_und: 'whale' } }
console.log(process.env);
// => { 'FOO_DOT.DOT': 'pony', 'FOO_UND\_UND': 'whale', N1: '42', N2: 42, N3: 42, N4: '42' }

API

get(path, [defaultValue], [opts]) ⇒ any

Gets the values of environment variables at the path specified.

Kind: global function
Returns: any - The values of environment variables associated with the path specified.
Access: public

Param Type Default Description
path string Dot separated path.
[defaultValue] any Default value to return if there is not any environment variable that matches the path provided.
[opts] Object Additional options.
[opts.parse] boolean false If true the value retrieved is converted to the proper type.
[opts.caseSensitive] boolean false If true no case conversion will be performed from the dot path provided to the env key search. Eg: 'tesT.kEy' will look for tesT_kEy environment variable instead of TEST_KEY.

set(path, value, [opts])

Sets an env key at the path specified. If nested keys are present they will be deleted.

Kind: global function
Access: public

Param Type Default Description
path string Dot separated path.
value string Value to set.
[opts] object Additional options.
[opts.stringify] boolean false If true the value provided is converted to string.
[opts.caseSensitive] boolean false If true no case conversion is performed from the dot path provided to the env key search. Eg: 'tesT.kEy' will look for tesT_kEy environment variable instead of TEST_KEY.

del(path, [opts])

Deletes an env key at the path specified. If nested keys are present they will be deleted too.

Kind: global function
Access: public

Param Type Default Description
path string A dot separated path.
[opts] object Additional options.
[opts.caseSensitive] boolean false If true no case conversion is performed from the dot path provided to the env key search. Eg: 'tesT.kEy' will look for tesT_kEy environment variable instead of TEST_KEY.

has(path, [opts]) ⇒ boolean

Returns whether an env key exists at the path specified.

Kind: global function
Returns: boolean - true if exists at least one environment variables with that path prefix.
Access: public

Param Type Default Description
path string Dot separated path.
[opts] object Additional options.
[opts.caseSensitive] boolean false If true no case conversion is performed from the dot path provided to the env key search. Eg: 'tesT.kEy' will look for tesT_kEy environment variable instead of TEST_KEY.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the license file for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].