3.0.1 • Published 2 months ago

@availity/env-var v3.0.1

Weekly downloads
136
License
MIT
Repository
github
Last release
2 months ago

env-var

Get run-time environment variables for immutable builds

Install

npm install @availity/env-var --save

Usage

envVar (default export)

Given an object of possible values and get back the value for the current environment.

import envVar from '@availity/env-var';
const myEnvVal = envVar(valuesObject[, windowOverride]);

Required params

  • valuesObject: An object with keys which match the name of the potential environments. The value of the give for the current environment will be returned

Optional params

  • windowOverride: String or Window Object which can be used to override the window which is used to determine the current hostname (which is used to determine the current environment)
    • When string, the string will be takes an a fully qualified URL and the hostname will be parsed from it.
    • When Window Object, the location hostname will be used.

Example

import envVar from '@availity/env-var';
const myEnvVal = envVar({prod: '123', qa: '234', local: '345'});
/*
depending on which environment this is ran in, myEnvVal would be something different
in prod: myEnvVal will be '123'
in qa: myEnvVal will be '234'
in test: myEnvVal will be '345' (defaults to local if env is not found)
*/

setEnvironments

Set the potential environments and the tests used to determine which environment the code is currently being executed in.

import { setEnvironments } from '@availity/env-var';
setEnvironments(possibleEnvironments[, replaceExisting])

Required params

  • possibleEnvironments: An object with keys which match the name of the potential environments and the values are the tests which are ran to determine if the environment is the current one.

These tests can be

  • String: A string will be used to check an exact match.
  • Regular Expression: A regex will be testd with the domain.
  • Function: The function will be called and the result should be a boolean indicating if the environment is the current environment.
  • Array: An array containing any of the above types.

Optional params

  • replaceExisting: Boolean, when true possibleEnvironments will replace the existing environments instead of merging.

Example

import { setEnvironments } from '@availity/env-var';
setEnvironments({
  local: ['127.0.0.1', 'localhost'],
  test: [/^t(?:(?:\d\d)|(?:est))-apps$/],
  qa: [/^q(?:(?:\d\d)|(?:ap?))-apps$/],
  prod: [/^apps$/],
  myEnv: ['custom-stuff-here']
});
3.0.1

2 months ago

1.0.0

8 months ago

2.0.4

8 months ago

3.0.0

8 months ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.11.4-alpha.0

2 years ago

1.11.3

2 years ago

1.11.2

3 years ago

1.11.1

3 years ago

1.11.1-alpha.33

3 years ago

1.11.1-alpha.16

4 years ago

1.11.1-alpha.15

4 years ago

1.11.0

4 years ago

1.10.0

4 years ago

1.9.20

4 years ago

1.9.19

4 years ago

1.9.18

4 years ago

1.9.17

4 years ago

1.9.16

4 years ago

1.9.15

4 years ago

1.9.14

4 years ago

1.9.11

4 years ago

1.9.9

4 years ago

1.9.6

4 years ago

1.9.5

4 years ago

1.9.4

4 years ago

1.9.3

4 years ago

2.0.0-alpha.23

4 years ago

2.0.0-alpha.15

4 years ago

1.9.2

5 years ago

1.9.1

5 years ago

1.9.0

5 years ago

1.8.0

5 years ago

1.7.1

5 years ago

1.6.3-alpha.454

5 years ago

1.6.2

6 years ago

1.6.0

6 years ago