aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/serverLib/StatsManager.js
diff options
context:
space:
mode:
authormarzavec <admin@marzavec.com>2019-11-07 08:35:23 +0100
committermarzavec <admin@marzavec.com>2019-11-07 08:35:23 +0100
commitf28e65ab8035682372edbe1c11d9ca2581e0a2e6 (patch)
treea75c9b682ca245baa3f01df5ea704ba95205cef3 /server/src/serverLib/StatsManager.js
parentMerge pull request #79 from 0x17de/feature-emote-trip (diff)
downloadhackchat-f28e65ab8035682372edbe1c11d9ca2581e0a2e6.tar.gz
hackchat-f28e65ab8035682372edbe1c11d9ca2581e0a2e6.zip
Syntax update and formatting tweaks
Diffstat (limited to 'server/src/serverLib/StatsManager.js')
-rw-r--r--server/src/serverLib/StatsManager.js63
1 files changed, 41 insertions, 22 deletions
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);
}
}