rjweb-server
Version:
Easy and Robust Way to create a Web Server with Many Easy-to-use Features in NodeJS
87 lines (86 loc) • 2.18 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var dataStat_exports = {};
__export(dataStat_exports, {
default: () => DataStat,
getPreviousHours: () => getPreviousHours
});
module.exports = __toCommonJS(dataStat_exports);
const getPreviousHours = () => {
return Array.from({ length: 7 }, (_, i) => ((/* @__PURE__ */ new Date()).getHours() - (4 - i) + 24) % 24);
};
class DataStat {
/**
* Create a new Data Stat
* @since 7.3.0
*/
constructor() {
this.secondStat = 0;
this.stats = {
total: 0,
perSecond: 0,
0: 0,
1: 0,
2: 0,
3: 0,
4: 0,
5: 0,
6: 0,
7: 0,
8: 0,
9: 0,
10: 0,
11: 0,
12: 0,
13: 0,
14: 0,
15: 0,
16: 0,
17: 0,
18: 0,
19: 0,
20: 0,
21: 0,
22: 0,
23: 0
};
setInterval(() => {
this.stats.perSecond = this.secondStat;
this.secondStat = 0;
}, 1e3);
setInterval(() => {
const previousHours = getPreviousHours();
this.stats[previousHours[6]] = 0;
}, 3e5);
}
/**
* Increase a Stat
* @since 7.3.0
*/
increase(amount = 1) {
this.secondStat += amount;
this.stats.total += amount;
this.stats[(/* @__PURE__ */ new Date()).getHours()] += amount;
return this;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
getPreviousHours
});