notifications-library
TypeScript icon, indicating that this package has built-in type declarations

0.2.1 • Public • Published

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);

Readme

Keywords

none

Package Sidebar

Install

npm i notifications-library

Weekly Downloads

1

Version

0.2.1

License

MIT

Unpacked Size

144 kB

Total Files

16

Last publish

Collaborators

  • roronoajin