npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@extend-chrome/notify

v2.0.0

Published

Create notifications in your Chrome extension with ease.

Downloads

6

Readme

npm (scoped) GitHub last commit License TypeScript Declarations Included

Chrome Extension Tutorials on YouTube ko-fi


This is a simpler API for chrome.notifications to use in Chrome extensions.

Add the notifications permission and create a notification with as little as a string. @extend-chrome/notify will do the rest! ✨

notify('This is too easy')

Table of Contents

Getting started

You will need to use a bundler like Rollup or Webpack to include this library in the build of Chrome extension.

See rollup-plugin-chrome-extension for an easy way use Rollup to build your Chrome extension!

Installation

$ npm i @extend-chrome/notify

Usage

import { notify } from '@extend-chrome/notify'

notify('The most simple notification').then((id) => {
  console.log('notification id', id)
})

notify
  .create({
    message: 'You have been notified.',
  })
  .then((id) => {
    console.log('notification id', id)
  })

The function notify.create takes any of the official notification options for chrome.notifications.create, without trying to type "notifications" every time.

Permissions

The "notifications" permission must be included in manifest.json.

// manifest.json
{
  "permissions": ["notifications"]
}

Features

TypeScript Definitions

TypeScript definitions are included, so no need to install an additional @types library!

Gets Name and Icon from manifest.json

This library will use chrome.runtime.getManifest() to include the name and icon of your extension in your notifications!

API

notify(message: string)

Returns: Promise<string>

Create a simple notification with an icon and the name of the Chrome extension, if they are supplied in manifest.json.

Returns a promise which resolves to the notification id, which you can use in the notify.onClick and notify.onButtonClick events.

const myId = await notify('This is my notification')

notify.onClicked.addListener((clickedId) => {
  if (myId === clickedId) {
    console.log('My notification was clicked.')
  }
})

notify.create(options: NotificationOptions)

Returns: Promise<string>

Create a basic notification by default using as little as options.message, or any of the other properties in NotificationOptions.

Returns a promise which resolves to the notification id, which you can use in notification events.

const myId = await notify.create({
  message: 'This is my notification',
})

notify.onClicked.addListener((clickedId) => {
  if (myId === clickedId) {
    console.log('My notification was clicked.')
  }
})

Other methods and events

All the other methods and events from chrome.notifications are promisified using chrome-promise and assigned to notify, so you can use notify as if it is chrome.notifications with promises. These include the following:

Methods

Methods return promises but are otherwise the same as the Chrome API.

notify
  .update('my-notification', updateOptions)
  .then((wasUpdated) => {
    if (wasUpdated) {
      console.log('my notification was updated')
    }
  })

Events

Events are exacly the same as the Chrome API. Register a listener by calling addListener on an event:

notify.onClosed.addListener((id) => {
  console.log('This notification was closed', id)
})