UNPKG

@northscaler/config-custom-environment-variables-generator

Version:

Generator of config/custom-environment-variables.json File for config-Based Projects

971 lines (310 loc) 16 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Global</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Global</h1> <section> <header> <h2></h2> </header> <article> <div class="container-overview"> <dl class="details"> </dl> </div> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="generate"><span class="type-signature"></span>generate<span class="signature">(obj)</span><span class="type-signature"> &rarr; {object}</span></h4> <div class="description"> <p>Generates an object suitable for use with <a href="https://npmjs.com/package/config">config</a>'s <code>config/custom-environment-variables.json</code>, skipping any functions encountered in the given object. Example:</p> <pre class="prettyprint source"><code> const fs = require('fs'); const config = require('config'); const cev = require('config-custom-environment-variables-generator'); fs.writeFileSync('config/custom-environment-variables.json', JSON.stringify(cev.generate(config, { prefix: 'MYAPP' }), null, 2))); </code></pre> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>obj</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"><p>An object, most likely the one returned by <code>require('config')</code>.</p></td> </tr> <tr> <td class="name"><code>opts.prefix</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> 'NODE_APP' </td> <td class="description last"><p>Prefix to use on environment variables. Use <code>@</code> to use the name of your application (see exported <code>DEFAULT_PREFIX</code>).</p></td> </tr> <tr> <td class="name"><code>opts.noPrefix</code></td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> false </td> <td class="description last"><p>Overrides use of any prefix (see exported <code>DEFAULT_NO_PREFIX</code>).</p></td> </tr> <tr> <td class="name"><code>opts.separator</code></td> <td class="type"> <span class="param-type">separator</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> '_' </td> <td class="description last"><p>The word separator in environment variables (see exported <code>DEFAULT_SEPARATOR</code>).</p></td> </tr> <tr> <td class="name"><code>opts.casing</code></td> <td class="type"> <span class="param-type">'upper'</span> | <span class="param-type">'lower'</span> | <span class="param-type">undefined</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> 'upper' </td> <td class="description last"><p>The case to use. <code>upper</code> forces upper case, <code>lower</code> forces lower case, else case is unchanged (see exported <code>DEFAULT_CASING</code>, <code>CASING_UPPER</code>, <code>CASING_LOWER</code>, and <code>CASING_UNCHANGED</code>).</p></td> </tr> <tr> <td class="name"><code>opts.empties</code></td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> false </td> <td class="description last"><p>If <code>true</code>, preserves empty objects that didn't have any environment variables, else skips entries that wouldn't have any environment variables (functions are always skipped).</p></td> </tr> <tr> <td class="name"><code>opts.formats</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> {} </td> <td class="description last"><p>If given, must be an object that specifies the __format value for the corresponding key of the first argument,</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="generator.js.html">generator.js</a>, <a href="generator.js.html#line33">line 33</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>An object containing the generated environment variables for each key in the input object.</p> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">object</span> </dd> </dl> <h4 class="name" id="generate"><span class="type-signature"></span>generate<span class="signature">(obj)</span><span class="type-signature"> &rarr; {object}</span></h4> <div class="description"> <p>Generates an object suitable for use with <a href="https://npmjs.com/package/config">config</a>'s <code>config/custom-environment-variables.json</code>, skipping any functions encountered in the given object. Example:</p> <pre class="prettyprint source"><code> const fs = require('fs'); const config = require('config'); const cev = require('config-custom-environment-variables-generator'); fs.writeFileSync('config/custom-environment-variables.json', JSON.stringify(cev.generate(config, { prefix: 'MYAPP' }), null, 2))); </code></pre> </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>obj</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"><p>An object, most likely the one returned by <code>require('config')</code>.</p></td> </tr> <tr> <td class="name"><code>opts.prefix</code></td> <td class="type"> <span class="param-type">string</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> 'NODE_APP' </td> <td class="description last"><p>Prefix to use on environment variables. Use <code>@</code> to use the name of your application (see exported <code>DEFAULT_PREFIX</code>).</p></td> </tr> <tr> <td class="name"><code>opts.noPrefix</code></td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> false </td> <td class="description last"><p>Overrides use of any prefix (see exported <code>DEFAULT_NO_PREFIX</code>).</p></td> </tr> <tr> <td class="name"><code>opts.separator</code></td> <td class="type"> <span class="param-type">separator</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> '_' </td> <td class="description last"><p>The word separator in environment variables (see exported <code>DEFAULT_SEPARATOR</code>).</p></td> </tr> <tr> <td class="name"><code>opts.casing</code></td> <td class="type"> <span class="param-type">'upper'</span> | <span class="param-type">'lower'</span> | <span class="param-type">undefined</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> 'upper' </td> <td class="description last"><p>The case to use. <code>upper</code> forces upper case, <code>lower</code> forces lower case, else case is unchanged (see exported <code>DEFAULT_CASING</code>, <code>CASING_UPPER</code>, <code>CASING_LOWER</code>, and <code>CASING_UNCHANGED</code>).</p></td> </tr> <tr> <td class="name"><code>opts.empties</code></td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> false </td> <td class="description last"><p>If <code>true</code>, preserves empty objects that didn't have any environment variables, else skips entries that wouldn't have any environment variables (functions are always skipped).</p></td> </tr> <tr> <td class="name"><code>opts.formats</code></td> <td class="type"> <span class="param-type">object</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> {} </td> <td class="description last"><p>If given, must be an object that specifies the __format value for the corresponding key of the first argument,</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="src_generator.js.html">src/generator.js</a>, <a href="src_generator.js.html#line33">line 33</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> <p>An object containing the generated environment variables for each key in the input object.</p> </div> <dl> <dt> Type </dt> <dd> <span class="param-type">object</span> </dd> </dl> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#generate">generate</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Sat Jan 15 2022 05:15:30 GMT+0000 (Coordinated Universal Time) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>