aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/managers/stats.js
diff options
context:
space:
mode:
authorNeel Kamath <neelkamath@protonmail.com>2018-05-13 13:07:56 +0200
committerNeel Kamath <neelkamath@protonmail.com>2018-05-13 13:07:56 +0200
commit949404cd1aad8492ae0338130f16054adfa38ab7 (patch)
tree6fed796d224901f5b6832543b19973af425e0fa9 /server/src/managers/stats.js
parentFlatten (diff)
downloadhackchat-949404cd1aad8492ae0338130f16054adfa38ab7.tar.gz
hackchat-949404cd1aad8492ae0338130f16054adfa38ab7.zip
Prevent fucking shit up
Diffstat (limited to 'server/src/managers/stats.js')
-rw-r--r--server/src/managers/stats.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/server/src/managers/stats.js b/server/src/managers/stats.js
new file mode 100644
index 0000000..20f1ae3
--- /dev/null
+++ b/server/src/managers/stats.js
@@ -0,0 +1,59 @@
+/**
+ * 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/ )
+ *
+ */
+
+class Stats {
+ /**
+ * Create a stats instance.
+ *
+ */
+ constructor () {
+ this._stats = {};
+ }
+
+ /**
+ * Retrieve value of arbitrary `key` reference
+ *
+ * @param {String} key Reference to the arbitrary store name
+ */
+ get (key) {
+ return this._stats[key];
+ }
+
+ /**
+ * Set value of arbitrary `key` reference
+ *
+ * @param {String} key Reference to the arbitrary store name
+ * @param {Number} value New value for `key`
+ */
+ set (key, value) {
+ this._stats[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
+ */
+ increment (key, amount) {
+ this.set(key, (this.get(key) || 0) + (amount || 1));
+ }
+
+ /**
+ * 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
+ */
+ decrement (key, amount) {
+ this.set(key, (this.get(key) || 0) - (amount || 1));
+ }
+}
+
+module.exports = Stats;