Skip to content

Commit e7457a8

Browse files
author
Travis CI
committed
chore(automated): Docs Update 247 [ci skip]
1 parent c746bab commit e7457a8

File tree

5 files changed

+47
-37
lines changed

5 files changed

+47
-37
lines changed

docs/JSONCache.html

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ <h2>
8484

8585
<hr>
8686
<dt>
87-
<h4 class="name" id="JSONCache"><span class="type-signature"></span>new JSONCache(url [, timeout], opts)</h4>
87+
<h4 class="name" id="JSONCache"><span class="type-signature"></span>new JSONCache(url [, timeout], options)</h4>
8888

8989

9090
</dt>
@@ -207,7 +207,7 @@ <h5>Parameters:</h5>
207207

208208
<tr>
209209

210-
<td class="name"><code>opts</code></td>
210+
<td class="name"><code>options</code></td>
211211

212212

213213
<td class="type">
@@ -352,7 +352,7 @@ <h6 class="method-params-label method-subparams-label">Properties</h6>
352352

353353

354354
<td class="description last">whether or not to delay starting updating the cache
355-
until start is requested</td>
355+
until start is requested</td>
356356
</tr>
357357

358358

@@ -400,7 +400,8 @@ <h6 class="method-params-label method-subparams-label">Properties</h6>
400400

401401

402402

403-
<td class="description last">maximum listeners (only applicable if leveraging emitter)</td>
403+
<td class="description last">maximum listeners
404+
(only applicable if leveraging emitter)</td>
404405
</tr>
405406

406407

@@ -524,7 +525,7 @@ <h6 class="method-params-label method-subparams-label">Properties</h6>
524525
<ul class="dummy">
525526
<li>
526527
<a href="jsoncache.js.html">jsoncache.js</a>,
527-
<a href="jsoncache.js.html#sunlight-1-line-25">line 25</a>
528+
<a href="jsoncache.js.html#sunlight-1-line-38">line 38</a>
528529
</li>
529530
</ul>
530531
</dd>
@@ -617,7 +618,7 @@ <h4 class="modal-title">Search results</h4>
617618
<span class="jsdoc-message">
618619
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a>
619620

620-
on Tuesday, February 18th 2020, 17:25:25
621+
on Tuesday, February 18th 2020, 17:47:28
621622

622623
using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
623624
</span>

docs/classes.list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ <h4 class="modal-title">Search results</h4>
195195
<span class="jsdoc-message">
196196
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a>
197197

198-
on Tuesday, February 18th 2020, 17:25:24
198+
on Tuesday, February 18th 2020, 17:47:28
199199

200200
using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
201201
</span>

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ <h4 class="modal-title">Search results</h4>
153153
<span class="jsdoc-message">
154154
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a>
155155

156-
on Tuesday, February 18th 2020, 17:25:25
156+
on Tuesday, February 18th 2020, 17:47:28
157157

158158
using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
159159
</span>

docs/jsoncache.js.html

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -77,38 +77,47 @@ <h1 class="page-title">Source: jsoncache.js</h1>
7777
const retryCodes = [429].concat((process.env.JSON_CACHE_RETRY_CODES || '')
7878
.split(',').map(code => parseInt(code.trim(), 10)));
7979

80+
const defaultOpts = {
81+
parser: JSON.parse,
82+
promiseLib: Promise,
83+
logger: console,
84+
delayStart: false,
85+
opts: {},
86+
maxListeners: 10,
87+
useEmitter: false,
88+
maxRetry: 1,
89+
integrity: () => true,
90+
};
91+
8092
class JSONCache extends EventEmitter {
8193
/**
8294
* Make a new cache
83-
* @param {string} url url to fetch
84-
* @param {number} [timeout=60000] optional timeout
85-
* @param {Object} opts Options object
86-
* @param {function} opts.parser optional parser to parse data. defaults to JSON.parse
87-
* @param {Class} opts.promiseLib optional promise library override
88-
* @param {Object} opts.logger optional Logger
89-
* @param {boolean} opts.delayStart whether or not to delay starting updating the cache
90-
* until start is requested
91-
* @param {Object} opts.opts options to pass to the parser
92-
* @param {number} opts.maxListeners maximum listeners (only applicable if leveraging emitter)
93-
* @param {boolean} opts.useEmitter whether or not to use the optional node emitter
94-
* @param {number} opts.maxRetry maximum number of attempts to retry getting data
95-
* @param {function} opts.integrity optional function to check if the data is worth keeping
95+
* @param {string} url url to fetch
96+
* @param {number} [timeout=60000] optional timeout
97+
* @param {Object} options Options object
98+
* @param {function} options.parser optional parser to parse data. defaults to JSON.parse
99+
* @param {Class} options.promiseLib optional promise library override
100+
* @param {Object} options.logger optional Logger
101+
* @param {boolean} options.delayStart whether or not to delay starting updating the cache
102+
* until start is requested
103+
* @param {Object} options.opts options to pass to the parser
104+
* @param {number} options.maxListeners maximum listeners
105+
* (only applicable if leveraging emitter)
106+
* @param {boolean} options.useEmitter whether or not to use the optional node emitter
107+
* @param {number} options.maxRetry maximum number of attempts to retry getting data
108+
* @param {function} options.integrity optional function to check if the data is worth keeping
96109
*/
97-
constructor(url, timeout = 60000, {
98-
parser = JSON.parse, promiseLib = Promise, logger = console, delayStart = true,
99-
opts, maxListeners = 45, useEmitter = true, maxRetry = 30, integrity = () => true,
100-
} = {
101-
parser: JSON.parse,
102-
promiseLib: Promise,
103-
logger: console,
104-
delayStart: true,
105-
opts: {},
106-
maxListeners: 45,
107-
useEmitter: true,
108-
maxRetry: 30,
109-
integrity: () => true,
110-
}) {
110+
constructor(url, timeout = 60000, options) {
111111
super();
112+
113+
// eslint-disable-next-line no-param-reassign
114+
const {
115+
parser, promiseLib, logger, delayStart, opts, maxListeners, useEmitter, maxRetry, integrity,
116+
} = {
117+
...defaultOpts,
118+
...options,
119+
};
120+
112121
this.url = url;
113122
// eslint-disable-next-line global-require
114123
this.protocol = this.url.startsWith('https') ? require('https') : require('http');
@@ -251,7 +260,7 @@ <h4 class="modal-title">Search results</h4>
251260
<span class="jsdoc-message">
252261
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a>
253262

254-
on Tuesday, February 18th 2020, 17:25:24
263+
on Tuesday, February 18th 2020, 17:47:28
255264

256265
using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
257266
</span>

docs/quicksearch.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<script src="scripts/fulltext-search.js"></script>
88

99
<script type="text/x-docstrap-searchdb">
10-
{"jsoncache.js.html":{"id":"jsoncache.js.html","title":"Source: jsoncache.js","body":" json-fetch-cache Classes JSONCache Source: jsoncache.js 'use strict'; const EventEmitter = require('events'); const retryCodes = [429].concat((process.env.JSON_CACHE_RETRY_CODES || '') .split(',').map(code =&gt; parseInt(code.trim(), 10))); class JSONCache extends EventEmitter { /** * Make a new cache * @param {string} url url to fetch * @param {number} [timeout=60000] optional timeout * @param {Object} opts Options object * @param {function} opts.parser optional parser to parse data. defaults to JSON.parse * @param {Class} opts.promiseLib optional promise library override * @param {Object} opts.logger optional Logger * @param {boolean} opts.delayStart whether or not to delay starting updating the cache * until start is requested * @param {Object} opts.opts options to pass to the parser * @param {number} opts.maxListeners maximum listeners (only applicable if leveraging emitter) * @param {boolean} opts.useEmitter whether or not to use the optional node emitter * @param {number} opts.maxRetry maximum number of attempts to retry getting data * @param {function} opts.integrity optional function to check if the data is worth keeping */ constructor(url, timeout = 60000, { parser = JSON.parse, promiseLib = Promise, logger = console, delayStart = true, opts, maxListeners = 45, useEmitter = true, maxRetry = 30, integrity = () =&gt; true, } = { parser: JSON.parse, promiseLib: Promise, logger: console, delayStart: true, opts: {}, maxListeners: 45, useEmitter: true, maxRetry: 30, integrity: () =&gt; true, }) { super(); this.url = url; // eslint-disable-next-line global-require this.protocol = this.url.startsWith('https') ? require('https') : require('http'); this.maxRetry = maxRetry; this.timeout = timeout; this.currentData = null; this.updating = null; this.Promise = promiseLib; this.parser = parser; this.hash = null; this.logger = logger; this.delayStart = delayStart; this.opts = opts; this.useEmitter = useEmitter; this.integrity = integrity; if (useEmitter) { this.setMaxListeners(maxListeners); } if (!delayStart) { this.startUpdating(); } } getData() { if (this.delayStart) { this.startUpdating(); } if (this.updating) { return this.updating; } return this.Promise.resolve(this.currentData); } getDataJson() { return this.getData(); } update() { this.updating = this.httpGet().then(async (data) =&gt; { const parsed = this.parser(data, this.opts); if (!this.integrity(parsed)) return this.currentData; // data passed integrity check this.currentData = parsed; if (this.useEmitter) { setTimeout(async () =&gt; this.emit('update', await this.currentData), 2000); } this.updating = null; return this.currentData; }).catch((err) =&gt; { this.updating = null; throw err; }); } httpGet() { return new this.Promise((resolve) =&gt; { const request = this.protocol.get(this.url, (response) =&gt; { this.logger.debug(`beginning request to ${this.url}`); const body = []; if (response.statusCode &lt; 200 || response.statusCode &gt; 299) { if ((response.statusCode &gt; 499 || retryCodes.includes(response.statusCode)) &amp;&amp; this.retryCount &lt; this.maxRetry) { this.retryCount += 1; setTimeout(() =&gt; this.httpGet().then(resolve).catch(this.logger.error), 1000); } else { this.logger.error(`${response.statusCode}: Failed to load ${this.url}`); resolve('[]'); } } else { response.on('data', chunk =&gt; body.push(chunk)); response.on('end', () =&gt; { this.retryCount = 0; resolve(body.join('')); }); } }); request.on('error', (err) =&gt; { this.logger.error(`${err.statusCode}: ${this.url}`); resolve('[]'); }); }); } startUpdating() { this.updateInterval = setInterval(() =&gt; this.update(), this.timeout); this.update(); } stop() { clearInterval(this.updateInterval); } stopUpdating() { this.stop(); } } module.exports = JSONCache; × Search results Close Documentation generated by JSDoc 3.6.3 on Tuesday, February 18th 2020, 17:25:24 using the DocStrap template. "},"classes.list.html":{"id":"classes.list.html","title":"Classes","body":" json-fetch-cache Classes JSONCache Classes Classes JSONCache × Search results Close Documentation generated by JSDoc 3.6.3 on Tuesday, February 18th 2020, 17:25:24 using the DocStrap template. "},"index.html":{"id":"index.html","title":"Index","body":" json-fetch-cache Classes JSONCache json-fetch-cache A simple package for fetching JSON from a URL and caching it for a decided amount of time. Documentation Installation $ npm i -S json-fetch-cache Usage const Cache = require('json-fetch-cache'); const pcCache = new Cache('http://content.warframe.com/dynamic/worldState.php', 10000); pcCache.getData() .then((data) =&gt; { console.log(data); process.exit(0); }) .catch((error)=&gt;{ console.error(error); }); × Search results Close Documentation generated by JSDoc 3.6.3 on Tuesday, February 18th 2020, 17:25:25 using the DocStrap template. "},"JSONCache.html":{"id":"JSONCache.html","title":"Class: JSONCache","body":" json-fetch-cache Classes JSONCache Class: JSONCache JSONCache new JSONCache(url [, timeout], opts) Make a new cache Parameters: Name Type Argument Default Description url string url to fetch timeout number &lt;optional&gt; 60000 optional timeout opts Object Options object Properties Name Type Description parser function optional parser to parse data. defaults to JSON.parse promiseLib Class optional promise library override logger Object optional Logger delayStart boolean whether or not to delay starting updating the cache until start is requested opts Object options to pass to the parser maxListeners number maximum listeners (only applicable if leveraging emitter) useEmitter boolean whether or not to use the optional node emitter maxRetry number maximum number of attempts to retry getting data integrity function optional function to check if the data is worth keeping Source: jsoncache.js, line 25 × Search results Close Documentation generated by JSDoc 3.6.3 on Tuesday, February 18th 2020, 17:25:25 using the DocStrap template. "}}
10+
{"jsoncache.js.html":{"id":"jsoncache.js.html","title":"Source: jsoncache.js","body":" json-fetch-cache Classes JSONCache Source: jsoncache.js 'use strict'; const EventEmitter = require('events'); const retryCodes = [429].concat((process.env.JSON_CACHE_RETRY_CODES || '') .split(',').map(code =&gt; parseInt(code.trim(), 10))); const defaultOpts = { parser: JSON.parse, promiseLib: Promise, logger: console, delayStart: false, opts: {}, maxListeners: 10, useEmitter: false, maxRetry: 1, integrity: () =&gt; true, }; class JSONCache extends EventEmitter { /** * Make a new cache * @param {string} url url to fetch * @param {number} [timeout=60000] optional timeout * @param {Object} options Options object * @param {function} options.parser optional parser to parse data. defaults to JSON.parse * @param {Class} options.promiseLib optional promise library override * @param {Object} options.logger optional Logger * @param {boolean} options.delayStart whether or not to delay starting updating the cache * until start is requested * @param {Object} options.opts options to pass to the parser * @param {number} options.maxListeners maximum listeners * (only applicable if leveraging emitter) * @param {boolean} options.useEmitter whether or not to use the optional node emitter * @param {number} options.maxRetry maximum number of attempts to retry getting data * @param {function} options.integrity optional function to check if the data is worth keeping */ constructor(url, timeout = 60000, options) { super(); // eslint-disable-next-line no-param-reassign const { parser, promiseLib, logger, delayStart, opts, maxListeners, useEmitter, maxRetry, integrity, } = { ...defaultOpts, ...options, }; this.url = url; // eslint-disable-next-line global-require this.protocol = this.url.startsWith('https') ? require('https') : require('http'); this.maxRetry = maxRetry; this.timeout = timeout; this.currentData = null; this.updating = null; this.Promise = promiseLib; this.parser = parser; this.hash = null; this.logger = logger; this.delayStart = delayStart; this.opts = opts; this.useEmitter = useEmitter; this.integrity = integrity; if (useEmitter) { this.setMaxListeners(maxListeners); } if (!delayStart) { this.startUpdating(); } } getData() { if (this.delayStart) { this.startUpdating(); } if (this.updating) { return this.updating; } return this.Promise.resolve(this.currentData); } getDataJson() { return this.getData(); } update() { this.updating = this.httpGet().then(async (data) =&gt; { const parsed = this.parser(data, this.opts); if (!this.integrity(parsed)) return this.currentData; // data passed integrity check this.currentData = parsed; if (this.useEmitter) { setTimeout(async () =&gt; this.emit('update', await this.currentData), 2000); } this.updating = null; return this.currentData; }).catch((err) =&gt; { this.updating = null; throw err; }); } httpGet() { return new this.Promise((resolve) =&gt; { const request = this.protocol.get(this.url, (response) =&gt; { this.logger.debug(`beginning request to ${this.url}`); const body = []; if (response.statusCode &lt; 200 || response.statusCode &gt; 299) { if ((response.statusCode &gt; 499 || retryCodes.includes(response.statusCode)) &amp;&amp; this.retryCount &lt; this.maxRetry) { this.retryCount += 1; setTimeout(() =&gt; this.httpGet().then(resolve).catch(this.logger.error), 1000); } else { this.logger.error(`${response.statusCode}: Failed to load ${this.url}`); resolve('[]'); } } else { response.on('data', chunk =&gt; body.push(chunk)); response.on('end', () =&gt; { this.retryCount = 0; resolve(body.join('')); }); } }); request.on('error', (err) =&gt; { this.logger.error(`${err.statusCode}: ${this.url}`); resolve('[]'); }); }); } startUpdating() { this.updateInterval = setInterval(() =&gt; this.update(), this.timeout); this.update(); } stop() { clearInterval(this.updateInterval); } stopUpdating() { this.stop(); } } module.exports = JSONCache; × Search results Close Documentation generated by JSDoc 3.6.3 on Tuesday, February 18th 2020, 17:47:28 using the DocStrap template. "},"classes.list.html":{"id":"classes.list.html","title":"Classes","body":" json-fetch-cache Classes JSONCache Classes Classes JSONCache × Search results Close Documentation generated by JSDoc 3.6.3 on Tuesday, February 18th 2020, 17:47:28 using the DocStrap template. "},"index.html":{"id":"index.html","title":"Index","body":" json-fetch-cache Classes JSONCache json-fetch-cache A simple package for fetching JSON from a URL and caching it for a decided amount of time. Documentation Installation $ npm i -S json-fetch-cache Usage const Cache = require('json-fetch-cache'); const pcCache = new Cache('http://content.warframe.com/dynamic/worldState.php', 10000); pcCache.getData() .then((data) =&gt; { console.log(data); process.exit(0); }) .catch((error)=&gt;{ console.error(error); }); × Search results Close Documentation generated by JSDoc 3.6.3 on Tuesday, February 18th 2020, 17:47:28 using the DocStrap template. "},"JSONCache.html":{"id":"JSONCache.html","title":"Class: JSONCache","body":" json-fetch-cache Classes JSONCache Class: JSONCache JSONCache new JSONCache(url [, timeout], options) Make a new cache Parameters: Name Type Argument Default Description url string url to fetch timeout number &lt;optional&gt; 60000 optional timeout options Object Options object Properties Name Type Description parser function optional parser to parse data. defaults to JSON.parse promiseLib Class optional promise library override logger Object optional Logger delayStart boolean whether or not to delay starting updating the cache until start is requested opts Object options to pass to the parser maxListeners number maximum listeners (only applicable if leveraging emitter) useEmitter boolean whether or not to use the optional node emitter maxRetry number maximum number of attempts to retry getting data integrity function optional function to check if the data is worth keeping Source: jsoncache.js, line 38 × Search results Close Documentation generated by JSDoc 3.6.3 on Tuesday, February 18th 2020, 17:47:28 using the DocStrap template. "}}
1111
</script>
1212

1313
<script type="text/javascript">

0 commit comments

Comments
 (0)