1const pad = (n) => String(n).padStart(2, "0");
2
3const getDateVariables = () => {
4 const now = new Date();
5 return {
6 year: now.getFullYear(),
7 month: pad(now.getMonth() + 1),
8 day: pad(now.getDate()),
9 hour: pad(now.getHours()),
10 minute: pad(now.getMinutes()),
11 second: pad(now.getSeconds())
12 };
13};
14
15export const replaceVariables = (message, variables) => {
16 const allVariables = {...getDateVariables(), ...variables};
17 for (const variable in allVariables)
18 message = message.replaceAll(`%${variable}%`, allVariables[variable]);
19 return message;
20};
21
22export const mapFixed = (entries, type) => ({
23 min: Math.min(...entries.map((entry) => entry[type])),
24 max: Math.max(...entries.map((entry) => entry[type])),
25 avg: parseFloat((entries.reduce((a, b) => a + b[type], 0) / entries.length).toFixed(2))
26});
27
28export const mapRounded = (entries, type) => ({
29 min: Math.min(...entries.map((entry) => entry[type])),
30 max: Math.max(...entries.map((entry) => entry[type])),
31 avg: Math.round(entries.reduce((a, b) => a + b[type], 0) / entries.length)
32});