Socket
Socket
Sign inDemoInstall

notifications-library

Package Overview
Dependencies
1
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    notifications-library

Notifications-library is a small and simple library in TypeScript to manage a notifications system


Version published
Weekly downloads
0
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Notifications-library

Notifications-library is a small and simple library in TypeScript to manage a notifications system

Usage

Create an instance of the NotificationCenter

    const notificationCenterObject = new NotificationCenter;

If you want to use a remote system, set the configuration

  const configuration = { fetchUrl: 'anyValidURL1', 
                          createUrl: 'anyValidURL2',               
                          updateUrl:'anyValidURL3' };

  notificationCenterObject.setConfig(configuration);

otherwise you can have a full local system.

You can set the sender of the notifications

  const sender = 'AnyValidSender';
  notificationCenterObject.setSender(sender);

API

There are different methods offered by the NotificationCenter class

getAllNotifications()

This method allow the user to get the notifications list

await notificationCenterObject.getAllNotifications();

getNotificationByID(id: string)

This method allow the user to get a specific notification by passing its ID as argument

// notification.id is the id of the notification you want to get
const requestedNotification = await notificationCenterObject.getNotificationByID(notification.id);

sendNotification(data: any)

This method allow the user to send a notification

const notification = {
    title: 'There is a new notification',
    message: 'Hello, im the first notification!'
};

await notificationCenterObject.sendNotification(notification);

markNotificationAsRead(id: string)

This method allow the user to mark a specific notification by passing its ID as argument

// notification.id is the id of the notification you want to mark as read
await notificationCenterObject.markNotificationAsRead(notification.id);

markAllAsRead()

This method allow the user to mark all the notifications as read

await notificationCenterObject.markAllAsRRead();

deleteNotificationByID(id: string)

This method allow the user to delete a specific notification by passing its ID as argument

// notification.id is the id of the notification you want to delete
await notificationCenterObject.deleteNotificationByID(notification.id);

deleteAllNotifications()

This method allow the user to delete all the notifications

await notificationCenterObject.deleteAllNotifications();

addSubscriber(callback: SubscribeCallback)

This method allow the user to subscribe to the NotificationCenter and get notify each time a new notification is sent or read

// This function will be called each time a new notification is sent or read
function onNewNotification(notification: Notification) {
  console.log(notification);
}

// onNewNotification is subscribed
notificationCenterObject.addSubscriber(onNewNotification);

FAQs

Last updated on 07 Feb 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc