From f28e65ab8035682372edbe1c11d9ca2581e0a2e6 Mon Sep 17 00:00:00 2001 From: marzavec Date: Wed, 6 Nov 2019 23:35:23 -0800 Subject: Syntax update and formatting tweaks --- server/src/serverLib/StatsManager.js | 63 +++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 22 deletions(-) (limited to 'server/src/serverLib/StatsManager.js') diff --git a/server/src/serverLib/StatsManager.js b/server/src/serverLib/StatsManager.js index e472504..b6e4f97 100644 --- a/server/src/serverLib/StatsManager.js +++ b/server/src/serverLib/StatsManager.js @@ -1,60 +1,79 @@ /** * Simple generic stats collection script for events occurances (etc) - * - * Version: v2.0.0 - * Developer: Marzavec ( https://github.com/marzavec ) - * License: WTFPL ( http://www.wtfpl.net/txt/copying/ ) - * + * @property {Object} data - The current stats data + * @author Marzavec ( https://github.com/marzavec ) + * @version v2.0.0 + * @license WTFPL ( http://www.wtfpl.net/txt/copying/ ) */ - class StatsManager { /** - * Create a stats instance. - * + * Create a stats instance */ - constructor () { + constructor() { + /** + * Data holder for the stats class + * @type {Object} + */ this.data = {}; } /** * Retrieve value of arbitrary `key` reference - * * @param {String} key Reference to the arbitrary store name - * + * @example + * // Find previously set `start-time` + * stats.get('start-time'); + * @public * @return {*} Data referenced by `key` */ - get (key) { + get(key) { return this.data[key]; } /** * Set value of arbitrary `key` reference - * * @param {String} key Reference to the arbitrary store name * @param {Number} value New value for `key` + * @example + * // Set `start-time` + * stats.set('start-time', process.hrtime()); + * @public + * @return {void} */ - set (key, value) { + set(key, value) { this.data[key] = value; } /** * Increase value of arbitrary `key` reference, by 1 or `amount` - * * @param {String} key Reference to the arbitrary store name - * @param {Number} amount Value to increase `key` by, or 1 if omitted + * @param {?Number} [amount=1] Value to increase `key` by, or 1 if omitted + * @example + * // Increment by `amount` + * stats.increment('users', 6); + * // Increment by 1 + * stats.increment('users'); + * @public + * @return {void} */ - increment (key, amount) { - this.set(key, (this.get(key) || 0) + (amount || 1)); + increment(key, amount = 1) { + this.set(key, (this.get(key) || 0) + amount); } /** * Reduce value of arbitrary `key` reference, by 1 or `amount` - * * @param {String} key Reference to the arbitrary store name - * @param {Number} amount Value to decrease `key` by, or 1 if omitted + * @param {?Number} [amount=1] Value to decrease `key` by, or 1 if omitted + * @example + * // Decrement by `amount` + * stats.decrement('users', 6); + * // Decrement by 1 + * stats.decrement('users'); + * @public + * @return {void} */ - decrement (key, amount) { - this.set(key, (this.get(key) || 0) - (amount || 1)); + decrement(key, amount = 1) { + this.set(key, (this.get(key) || 0) - amount); } } -- cgit v1.2.1