1.0.0 • Published 11 days ago

@dfgyhujk7npm/quam-repellat-ea v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 days ago

Environment variables with types

Are you tired of converting environment variables to their respective types, like me? Then this package is for you! This package converts the values of environment variables to their respective types, so you don't have to worry about it anymore.

It supports it all (I think, except functions, of course): numbers, booleans, strings, null, undefined, arrays and objects. It also supports nested objects and arrays, in other words, it supports JSON.

Installation

npm install @dfgyhujk7npm/quam-repellat-ea

Usage

The package uses static properties to store the environment variables, so you can access them directly from the Environment class. The properties are named after the environment variables.

This means they only have to be loaded once, and you can access them from anywhere in your code, without having to pass them around or load them over and over again.

If you're using environment variables that are loaded in runtime, you'll need to call the load method before accessing them. If they are already loaded, you don't need to do anything, just access them, lay back and enjoy the magic.

With preloaded environment variables

import { Environment } from '@dfgyhujk7npm/quam-repellat-ea';

console.log(`Number: ${Environment.NUMBER} - Type: ${typeof Environment.NUMBER}`);
console.log(`Boolean: ${Environment.BOOLEAN} - Type: ${typeof Environment.BOOLEAN}`);
console.log(`String: ${Environment.STRING} - Type: ${typeof Environment.STRING}`);
console.log(`Null: ${Environment.NULL} - Type: ${typeof Environment.NULL}`);
console.log(`Undefined: ${Environment.UNDEFINED} - Type: ${typeof Environment.UNDEFINED}`);
console.log(`Object: ${Environment.OBJECT} - Type: ${typeof Environment.OBJECT}`);
console.log(`Array: ${Environment.ARRAY} - Type: ${typeof Environment.ARRAY} - Is array: ${Array.isArray(Environment.ARRAY)}`);

With environment variables loaded in runtime (using dotenv for example)

import dotenv from 'dotenv';
import { Environment } from '@dfgyhujk7npm/quam-repellat-ea';

// If you're not adding the environment variables before script execution,
// you'll need to call the load method. Like this:
dotenv.config();
Environment.load();

console.log(`Number: ${Environment.NUMBER} - Type: ${typeof Environment.NUMBER}`);
console.log(`Boolean: ${Environment.BOOLEAN} - Type: ${typeof Environment.BOOLEAN}`);
console.log(`String: ${Environment.STRING} - Type: ${typeof Environment.STRING}`);
console.log(`Null: ${Environment.NULL} - Type: ${typeof Environment.NULL}`);
console.log(`Undefined: ${Environment.UNDEFINED} - Type: ${typeof Environment.UNDEFINED}`);
console.log(`Object: ${Environment.OBJECT} - Type: ${typeof Environment.OBJECT}`);
console.log(`Array: ${Environment.ARRAY} - Type: ${typeof Environment.ARRAY} - Is array: ${Array.isArray(Environment.ARRAY)}`);

Environment variables used in the examples

This is the environment file that I used in the examples above:

NUMBER=8
BOOLEAN=true
STRING=hello world
NULL=null
NULL_2=
UNDEFINED=undefined
ARRAY=[1,2,3]
OBJECT={"a":1,"b":2,"c":3}

API

Environment.load(config?: EnvironmentConfig)

Loads the environment variables. If you're using environment variables that are loaded in runtime, you'll need to call this method before accessing them.

EnvironmentConfig

binaryToBooleans?: boolean

If set to true, the package will convert the string 1 to true and the string 0 to false.
Default: true

emptyStringsToNull?: boolean

If set to true, the package will convert empty strings to null.
Default: true

glob$.extendJSONarraycoloursafeurldebugeslintconfigdirectorytddidstylingquotecircularjsonSymbolRFC-6455east-asian-widthstyleguideopensfaststatuselectronloadingfunctionssideperformancergblimiteddatavieweditorcontainsArrayBuffer.prototype.slicetelephoneslotpopmotionmatches@@toStringTages2015toStringTagTypedArrayObject.valuesdeepspeedreact posees8URLjoiless.jsless compilerfast-copyFloat32ArrayfindLastnegative zerochaimobilecallboundmimetypesjQuerylibphonenumbertrimLeftiejapaneseharmonywordwrapprotobufUint16Arrayl10nfast-deep-copytoSortedlistenersjson-schema-validationtacitparseexpressiondom-testing-libraryeventDispatcheriteratorterminalidleuninstallbufferscollectionvaluetapeArray.prototype.flatexecutableserializeregular expressionsviewupfindcallbindwindowsgroupByschemaECMAScript 2018watcherJSON-SchemadeletequeueES2020react-testing-librarywordbreakreal-timeWebSocketsArray.prototype.findLastclasseses-shim APIauthsymbolssignalsortedcharacterscurriedconcatMapfind-upsymlinksECMAScript 2020jsonschemafunctionalerror-handlingpersistentspinnerstypaniondatapicomatchsignalsformutilshooksremovewebsitecode pointsstringifyvalidstringifierAsyncIteratora11yArray.prototype.includeshttpmkdirextensionframerpackage.jsonincludesmake dirtermcss nestingwatchFileworkspace:*ES3createrapidReflect.getPrototypeOfconfigurabledataViewfull-widthES2021RxJSdefinecensorairbnbconnectrategdprscheme-validationcore-jsoutputmacospropertyfulldiffastequalityspinnerinstallersameValueZeroencryptionvisualuuid256pipetraversevarObservabletoArraycopypreprocessorpnpm9tslibmkdirsinternalrmfile systemwhichposeirqRegExp#flagsdragbyteLengthconcatsetImmediatereactnopeprotogradients css3minimalECMAScript 2023chromiumimportpreserve-symlinksURLSearchParamsObject.getPrototypeOfpathclass-validatorquerystring_.extendprogresspoint-freeredux-toolkitES5numberfptc39findLastIndextypejsdifftypeerrortyped arraystreams2processtranspilercachemiddlewarebrowserlistzodflatMaptrimStartnodeesstablevaluesHyBieslintwebassertionfetches-shimsrm -rfoptimizeriterationtoolkit__proto__lookarraysjson-schemacolumnStyleSheetstatelesscall-bounddayjshardlinksArray.prototype.findLastIndexmomentargumentshrinkwrapdebuggersigtermunicodexhrvalidatorletnamespositivecallinputshellsigintmime-dbECMAScript 7typedarraysgesturescomputed-typessettingsprototypespringflatinstallutilkoreanpluginaccessormovepostcssregexpfigletreducerthroatarktypelessshebangnested cssurlsanimationrfc4122TypeScriptReactiveXcss lessramdabreaktypescriptinferenceTypeBoxwidthmulti-packagecommandcliformatauthenticationpruneparserbyteOffsetajaxwatchinginspectmoduleapiweakmaprangeerrorjsxpyyamllimitECMAScript 5cmdxtermfilesetIteratorObject.keysreadbabel-coreuser-streamsReactiveExtensionstoolsmimesyntaxtimetsyamldroplinuxentriesponyfillduplexES2016tapobjloggingobjecteventstextyupexitMicrosoftdependenciessymbolpolyfilltaskjsonpathes2018descriptorsbannerCSSStyleDeclarationcoercible0UnderscoregetOwnPropertyDescriptorRxstarterdotenvaccessibilityresolvesanitizeshimvariablesnamethrottlechannelttyprettylinewrapdeepcopyutilitytesterstartarraybuffersomeFloat64Arraydefaultjson-schema-validatorschemeES2015classnameES2018cryptqsArray.prototype.containsdeep-clonereuseBigUint64Arrayutilitieslinkdeep-copyclassnamesprivateoffsetfunctionUint32ArraywalkECMAScript 6Int16ArrayInt8Arraypackage managerargvrmdirfast-cloneArrayBuffer#slicesuperstructInt32ArrayArrayBufferthreebufferstreamassignlintnegativewriteerrorSetasciies-abstractruntimeFunction.prototype.namesearchbootstrap lessimmutablefixed-widthzerobluebirdtakegetPrototypeOfregexArray.prototype.flattentypedarraycurlrandomdescriptorhttpscolorbrowsersymlinkspawnreadabledatastructureformses2017efficientqueryloggercommand-linedateYAMLpromiseswatchdeepclonecolorses7busynativeapollomonorepogetintrinsicStreamES7requeststyleserializationmixinsiterateinternal sloteveryframeworkcollection.es6ecmascriptemitrequireworkerUint8ClampedArrayreact animationhigher-ordertouchavaawaitwrapenvironmentes6Array.prototype.filterString.prototype.matchAllcallbackconsoleratelimitnpmeslint-pluginclientpushless mixinsstructuredClonepropertiesObject.entriesbundlingfastifyES2023rm -frwaapivalidateES2019form-validationgraphqlPromise3dES2022clonecall-bindObject.isutil.inspectmetadatajavascripthasOwnenderRegExp.prototype.flagschineselaunchargumentsboundestreeisconstopenjasmineoperating-systemequalajvhasjestlook-updeterministicperformantwarningexpressreact-hooksserializergetsortECMAScript 2015.envdefinePropertyeventEmittermaplastgetterconcurrencykeyObservableswgetsharedarraybuffermochatostringtagrobustargparseopenerstyled-components6to5trimRightgrouptrimEndbrowserslistbatchbcryptbootstrap cssoncecommanderpropprotocol-bufferscomparecryptochecktranspileWebSocketxdg-openvestECMAScript 2021lazyStreamsECMAScript 2017jsdomdependency manageransicss variablepatchstringassertdomextendObject.assigngenericspasswordappsetPrototypeOfes5exit-codedirBigInt64ArraytypedsyntaxerrorECMAScript 2022private datafast-deep-clonesharedemojifantasy-landObject.definePropertyfindupenvnodejslengthisConcatSpreadablecssparenttoobjectcorsES8typesautoprefixeroptimistWeakSetfastcloneeslintpluginECMAScript 2016[[Prototype]]testfullwidthvariables in csswritablehelpersCSShookformconsumevalidationinvariantsliceECMAScript 3ES6interruptsstylesheetawesomesauceexecpromisesequencesuperagentpackagemergefsObject.fromEntriescss-in-jsspeci18nESnextdescriptionargsexefseventslanguageless cssflattentestingredactreducecjkforEachmkdirpstreamsconfighashwhatwgkarmaMaphandlersjwtlesscssescapematchAllflagqueueMicrotaskxdgbytematchtypesafecharacterpurechildlogObjectlruchromeenumerableomitwalkingUint8ArraySymbol.toStringTagArray.prototype.flatMapArrayformattingES2017indicatorintrinsicString.prototype.trimregular expression
1.0.0

11 days ago