New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

notify-util

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

notify-util

Very simple notification system for JS/TS projects.

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-25%
Maintainers
1
Weekly downloads
 
Created
Source

notify-util

Very simple notification system for JS/TS projects.

Live example

Installation via NPM

npm i notify-util

Alternatively, you can include the bundled js file in dist, where notifyUtil is available in the window.

Quick start

Have a div with attribute sn-notification-container. You can use the built in class if you want. It puts it in the top right of the page and adds gap between each notification.

<div nu_notification-container class="nu_notification-container"></div>
import notifyUtil from 'notify-util'

notifyUtil.configure({});

new notifyUtil.Notification({
  type: "success",
  heading: "Wow that was fast!",
  body: "Skrt skrt",
});

Configuration

import notifyUtil from 'notify-util'

notifyUtil.configure({
  // options here
});

Configuration options

You must run configure before using the Notification class.

To run without customization, pass an empty object as argument.

You can override any of default settings by following the structure below.

Notifiation dissection

OptionDescription
containerSelectorSelector for notification container. Attribute, ID, class as string with # or . as needed
classesOverride the default CSS classes by providing your own
→ notificationClassCSS class as string, no prefixed .
→ headingWrapperClassCSS class as string, no prefixed .
→ iconClassCSS class as string, no prefixed .
→ headingClassCSS class as string, no prefixed .
→ bodyClassCSS class as string, no prefixed .
→ progressBarClassCSS class as string, no prefixed .
iconsOverride the default icons by providing your own.
→ successstring injected as HTML
→ warningstring injected as HTML
→ errorstring injected as HTML
→ debugstring injected as HTML
→ loadingstring injected as HTML
→ spinnerstring injected as HTML
Themestring light / dark / auto / none
Defaults
configureNotification({
  containerSelector: '[nu_notification-container]',
  classes: {
    notificationClass: 'nu_notification',
    headingWrapperClass: 'nu_notification-heading-wrapper',
    iconClass: 'nu_notification-icon',
    headingClass: 'nu_notification-heading',
    bodyClass: 'nu_notification-body',
    progressBarClass: 'nu_notification-progress-bar'
  },
  icons: {
    success: icons.svg.success,
    warning: icons.svg.warning,
    error: icons.svg.error,
    debug: icons.svg.debug,
    spinner: icons.svg.spinner,
    info: icons.svg.info
  },
  theme: 'light'
});

Notification

Displays a notification with a heading and message. Can be closed by clicking on it when enabled.

Returns an object if you need to remove it programmatically. e.g.: myNotification.remove().

Options

For spinner, clickToClose is forced false and duration is forced null.

new notifyUtil.Notification({
  type: 'success' | 'warning' | 'error' | 'debug' | 'info' | 'spinner', // Required
  heading: string, // Required
  body: string,
  duration: number | null, // Default: 3500 (ms), null for infinite
  clickToClose: boolean // Default: true
});

Examples

Success notification
new notifyUtil.Notification({
  type: 'success',
  heading: 'Success heading',
  body: 'Success message'
});
Spinner
const loadingIndicator = new notifyUtil.Notification({
  type: 'spinner',
  heading: 'Loading...',
  body: 'Working on it'
});

// some time passes

loadingIndicator.update({
  heading: 'Loading...',
  body: 'Almost there'
});

// some time passes

loadingIndicator.close();

// some time passes

myLoaderMessage.close();

FAQs

Package last updated on 25 May 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc