environment-normalize
v2.0.2
Published
A lightweight utility for normalizing environment names
Downloads
14
Maintainers
Readme
environment-normalize
A lightweight utility for normalizing environment names
Install
yarn add environment-normalize # OR
npm i -S environment-normalize
Usage
normalize()
import {normalize} from 'environment-normalize';
// normalize()
console.log(normalize(/* no params */)); // returns the default fallback: 'production'
let env = '';
let fallback = '';
env = 'prd';
console.log(normalize(env)); // returns 'production'
env = 'prod';
console.log(normalize(env)); // returns 'production'
env = 'production';
console.log(normalize(env)); // returns 'production'
env = '< not a typical environment name >';
fallback = 'my-custom-environment-name';
console.log(normalize(env, fallback)); // returns 'my-custom-environment-name'
The full list of conversions can be found here: src/lib/aliases.js
constants
import {constants} from 'environment-normalize';
console.log(constants.PRD); // returns 'production'
console.log(constants.PROD); // returns 'production'
console.log(constants.PRODUCTION); // returns 'production'
console.log(constants.FALLBACK); // returns 'production'
console.log(JSON.stringify(constants, null, 2)); // Print'em out
Note: Although examples here are ES6, environment-normalize is fully ES5 compatible
On the client
<html>
<body>
<script src='lib/environment-normalize.js'></script>
<script>
(() => {
const {
normalize,
constants
} = window['environment-normalize'];
const env = 'prod';
console.log(normalize(env)); // returns 'production'
console.log(JSON.stringify(constants, null, 2)); // Prints all the constants
})();
...