worldstate-emitter 2.2.12 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,79 +0,0 @@
1
- import { transports, createLogger, format } from 'winston';
2
-
3
- import { LOG_LEVEL } from './env.js';
4
-
5
- let tempLogger;
6
- try {
7
- const { combine, label, printf, colorize } = format;
8
-
9
- /* Logger setup */
10
- const transport = new transports.Console();
11
- const logFormat = printf((info) => `[${info.label}] ${info.level}: ${info.message}`);
12
- tempLogger = createLogger({
13
- format: combine(colorize(), label({ label: 'WS'.brightBlue }), logFormat),
14
- transports: [transport],
15
- });
16
- tempLogger.level = LOG_LEVEL;
17
- } catch (e) {
18
- tempLogger = console;
19
- }
20
-
21
- export const logger = tempLogger;
22
-
23
- /**
24
- * Group an array by a field value
25
- * @param {Object[]} array array of objects to broup
26
- * @param {string} field field to group by
27
- * @returns {Object} [description]
28
- */
29
- export const groupBy = (array, field) => {
30
- const grouped = {};
31
- if (!array) return undefined;
32
- array.forEach((item) => {
33
- const fVal = item[field];
34
- if (!grouped[fVal]) {
35
- grouped[fVal] = [];
36
- }
37
- grouped[fVal].push(item);
38
- });
39
- return grouped;
40
- };
41
-
42
- const allowedDeviation = 30000;
43
- /**
44
- * Validate that b is between a and c
45
- * @param {Date} a The first Date, should be the last time things were updated
46
- * @param {Date} b The second Date, should be the activation time of an event
47
- * @param {Date} c The third Date, should be the start time of this update cycle
48
- * @returns {boolean} if the event date is between the server start time and the last update time
49
- */
50
- export const between = (a, b, c = new Date()) => b + allowedDeviation > a && b - allowedDeviation < c;
51
-
52
- /**
53
- * Returns the number of milliseconds between now and a given date
54
- * @param {string} d The date from which the current time will be subtracted
55
- * @param {function} [now] A function that returns the current UNIX time in milliseconds
56
- * @returns {number}
57
- */
58
- export function fromNow(d, now = Date.now) {
59
- return new Date(d).getTime() - now();
60
- }
61
-
62
- /**
63
- * Map of last updated dates/times
64
- * @type {Object}
65
- */
66
- export const lastUpdated = {
67
- pc: {
68
- en: 0, // Date.now(),
69
- },
70
- ps4: {
71
- en: Date.now(),
72
- },
73
- xb1: {
74
- en: Date.now(),
75
- },
76
- swi: {
77
- en: Date.now(),
78
- },
79
- };