mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-05-06 08:25:15 -04:00
Uptime calculation improvement and 1-year uptime (#2750)
This commit is contained in:
parent
eec221247f
commit
076331bf00
22 changed files with 1306 additions and 264 deletions
79
server/utils/array-with-key.js
Normal file
79
server/utils/array-with-key.js
Normal file
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
* An object that can be used as an array with a key
|
||||
* Like PHP's array
|
||||
*/
|
||||
class ArrayWithKey {
|
||||
__stack = [];
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
push(key, value) {
|
||||
this[key] = value;
|
||||
this.__stack.push(key);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
pop() {
|
||||
let key = this.__stack.pop();
|
||||
let prop = this[key];
|
||||
delete this[key];
|
||||
return prop;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
getLastKey() {
|
||||
if (this.__stack.length === 0) {
|
||||
return null;
|
||||
}
|
||||
return this.__stack[this.__stack.length - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
shift() {
|
||||
let key = this.__stack.shift();
|
||||
let value = this[key];
|
||||
delete this[key];
|
||||
return {
|
||||
key,
|
||||
value,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
length() {
|
||||
return this.__stack.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last element
|
||||
* @returns {*|null} The last element, or null if the array is empty
|
||||
*/
|
||||
last() {
|
||||
let key = this.getLastKey();
|
||||
if (key === null) {
|
||||
return null;
|
||||
}
|
||||
return this[key];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ArrayWithKey
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue