Clean up session info into a class

This commit is contained in:
zefie
2021-07-19 05:57:34 -04:00
parent 3b65c7b254
commit 248354e5a1
11 changed files with 175 additions and 131 deletions

View File

@@ -0,0 +1,28 @@
class ClientSessionData {
data_store = null;
constructor() {
this.data_store = new Array();
}
get(key = null) {
if (typeof (this.data_store) === 'undefined') return null;
else if (key === null) return this.data_store;
else if (this.data_store[key]) return this.data_store[key];
else return null;
}
set(key, value) {
if (key === null) throw ("ClientSessionData.set(): invalid key provided");
if (typeof (this.data_store) === 'undefined') this.data_store = new Array();
this.data_store[key] = value;
}
delete(key) {
if (key === null) throw ("ClientSessionData.delete(): invalid key provided");
delete this.data_store[key];
}
}
module.exports = ClientSessionData;