Spaces:
Runtime error
Runtime error
File size: 773 Bytes
4327358 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
/**
* Unmask "*" in events list to exact values
* Remove duplicates if any
*/
export class EventWildUnmask {
constructor(
private readonly events: string[] | any,
private readonly all: string[] | any | null = null,
) {
// in case of enum - convert to array
this.events = Object.values(events);
this.all = all ? Object.values(all) : this.events;
}
unmask(events: string[]) {
const rightEvents = [];
if (events.includes('*')) {
rightEvents.push(...this.all);
}
// Get only known events, log and ignore others
for (const event of events) {
if (!this.events.includes(event)) {
continue;
}
rightEvents.push(event);
}
// return unique values
return [...new Set(rightEvents)];
}
}
|