@@ -35,6 +35,9 @@ some functions to verify it satisfies our program's needs.
3535``` js
3636const env = require (' env-var' );
3737
38+ // Or using import syntax:
39+ // import * as env from 'env-var'
40+
3841const PASSWORD = env .get (' DB_PASSWORD' )
3942 // Throws an error if the DB_PASSWORD variable is not set (optional)
4043 .required ()
@@ -176,15 +179,15 @@ app.listen(PORT)
176179
177180#### convertFromBase64()
178181Sometimes environment variables need to be encoded as base64. You can use this
179- function to convert them before reading their value .
182+ function to convert them to UTF-8 strings before parsing them .
180183
181184For example if we run the script script below, using the command `DB_PASSWORD=
182185$(echo -n 'secret_password' | base64) node`, we'd get the following results:
183186
184187``` js
185188console .log (process .env .DB_PASSWORD ) // prints "c2VjcmV0X3Bhc3N3b3Jk"
186189
187- // dbpass will contain the value "secret_password"
190+ // dbpass will contain the converted value of "secret_password"
188191const dbpass = env .get (' DB_PASSWORD' ).convertFromBase64 ().asString ()
189192```
190193
@@ -249,16 +252,22 @@ The same as _asJson_ but checks that the data is a JSON Object, e.g {a: 1}.
249252#### asArray([ delimiter: string] )
250253Reads an environment variable as a string, then splits it on each occurence of
251254the specified _ delimiter_ . By default a comma is used as the delimiter. For
252- example a var set to "1,2,3" would become [ '1', '2', '3'] .
255+ example a var set to "1,2,3" would become [ '1', '2', '3'] . Example outputs for
256+ specific values are:
257+
258+ * Reading ` MY_ARRAY='' ` results in ` [] `
259+ * Reading ` MY_ARRAY='1' ` results in ` ['1'] `
260+ * Reading ` MY_ARRAY='1,2,3' ` results in ` ['1', '2', '3'] `
253261
254262#### asUrlString()
255- Verifies that the variable is a valid URL string and returns that string. Uses
256- ` is-url ` to perform validation, so check that module for validation rules.
263+ Verifies that the variable is a valid URL string and returns the validated
264+ string. The validation is performed by passing the URL string to the
265+ [ Node.js URL Constructor] ( https://nodejs.org/docs/latest/api/url.html ) .
257266
258267#### asUrlObject()
259- Verifies that the variable is a valid URL string, then parses it using
260- ` url.parse ` from the Node.js core ` url ` module and returns the parsed Object.
261- See the [ Node.js docs] ( https://nodejs.org/api/url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost ) for more info
268+ Verifies that the variable is a valid URL string using the same method as
269+ ` asUrlString() ` , but instead returns the resulting URL instance. For details
270+ see the [ Node.js URL docs] ( https://nodejs.org/docs/latest/ api/url.html ) .
262271
263272## Examples
264273
@@ -301,15 +310,6 @@ const commaArray = env.get('DASH_ARRAY').asArray('-');
301310const enumVal = env .get (' ENVIRONMENT' ).asEnum ([' dev' , ' test' , ' live' ])
302311```
303312
304- ## Contributors
305- * @caccialdo
306- * @evanshortiss
307- * @hhravn
308- * @itavy
309- * @MikeyBurkman
310- * @pepakriz
311- * @rmblstrp
312-
313313## Contributing
314314Contributions are welcomed. If you'd like to discuss an idea open an issue, or a
315315PR with an initial implementation.
@@ -353,3 +353,13 @@ Once you've done that, add some unit tests and use it like so:
353353// Uses your new function to ensure the SOME_NUMBER is the integer 0
354354env .get (' SOME_NUMBER' ).asNumberZero ()
355355```
356+
357+ ## Contributors
358+ * @caccialdo
359+ * @evanshortiss
360+ * @gabrieloczkowski
361+ * @hhravn
362+ * @itavy
363+ * @MikeyBurkman
364+ * @pepakriz
365+ * @rmblstrp
0 commit comments