browser-notifications-api
Version:
A lightweight wrapper for the native Browser Notifications API. Simplifies permission requests and notification display with a consistent, cross-browser interface. Perfect for PWAs, Alerts and User Engagement features.
40 lines (31 loc) • 948 B
JavaScript
class NotificationManager
{
#notificationsSent = new Map();
constructor() {}
logNotification(notification) {
if(this.#notificationsSent.has(notification.tag)) {
const existing = this.#notificationsSent.get(notification.tag);
existing.push(notification);
this.#notificationsSent.set(notification.tag, existing);
} else {
this.#notificationsSent.set(notification.tag, [notification]);
}
}
getAllNotifications() {
return Object.fromEntries(this.#notificationsSent.entries());
}
getNotificationByTag(tag) {
if(this.#notificationsSent.has(tag)) {
return this.#notificationsSent.get(tag);
}
return null;
}
updateTag(tag) {
if(!tag || typeof tag !== 'string') {
tag = 'N_' + Date.now();
}
return tag;
}
}
export default NotificationManager;
;