# notifyjs

> A handy wrapper for the Web Notifications API

Latest version **3.0.0** (published 2017-02-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install notifyjs
pnpm add notifyjs
yarn add notifyjs
bun add notifyjs
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2017-02-15 |
| First published | 2014-05-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/notifyjs) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1324 |
| Author | Alex Gibson |
| Maintainers | alexgibson |
| Keywords | web, notification, nofity |

## Links

- npm: https://www.npmjs.com/package/notifyjs
- Repository: https://github.com/alexgibson/notify.js
- Homepage: https://github.com/alexgibson/notify.js#readme
- Issues: https://github.com/alexgibson/notify.js/issues
- npm.io page: https://npm.io/package/notifyjs

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 3.0.0 (latest) — 2017-02-15
- 2.0.3 — 2016-06-23
- 2.0.2 — 2016-06-02
- 2.0.1 — 2016-06-02
- 2.0.0 — 2016-06-02
- 1.3.0 — 2016-04-06
- 1.2.8 — 2015-10-01
- 1.2.7 — 2015-09-26
- 1.2.6 — 2015-09-23
- 1.2.5 — 2015-02-15
- 1.2.4 — 2015-01-11
- 1.2.3 — 2014-08-14
- 1.2.2 — 2014-05-20
- 1.2.1 — 2014-05-20

## README

Notify.js
=========

[![Build Status](https://travis-ci.org/alexgibson/notify.js.png?branch=master)](https://travis-ci.org/alexgibson/notify.js)

A handy wrapper for using the [Web Notifications API](http://www.w3.org/TR/notifications/).
Notify.js aims to simplify requesting user permission and associated Web
Notification API events, as well as providing a few extra callbacks and
convenience methods.

Online demo: https://alexgibson.github.io/notify.js/

Installation
------------

```
npm install notifyjs
```

Note: when installed via npm the Notify.js source file is located at `./dist/notify.js`.

Build
-----

Notify.js is written in ES6 and transpiled to ES5 & UMD format using [Babel](http://babeljs.io) and [Rollup](http://rollupjs.org).

Install dependencies:

```
npm install
```

Then build from source:

```
npm run build
```

Usage
-----

To initialize a web notification create a new `Notify` instance, passing the
message `title` as well as any other options you wish to use.


```

var myNotification = new Notify('Yo dawg!', {
	body: 'This is an awesome notification',
	notifyShow: onNotifyShow
});

function onNotifyShow() {
	console.log('notification was shown!');
}
```

Then show the notification.

```
myNotification.show();
```

It's a good idea to make sure that you have permissions to send notifications
first.

```
if (!Notify.needsPermission) {
    doNotification();
} else if (Notify.isSupported()) {
    Notify.requestPermission(onPermissionGranted, onPermissionDenied);
}

function onPermissionGranted() {
	console.log('Permission has been granted by the user');
	doNotification();
}

function onPermissionDenied() {
	console.warn('Permission has been denied by the user');
}
```

Required parameters
-------------------

* title (string) - notification title

Optional parameters
-------------------

All options supported in the [Notifications API specification](https://notifications.spec.whatwg.org/#dictdef-notificationoptions),
in addition to:

* `timeout`: (integer) - number of seconds to close the notification automatically
* `closeOnClick`: (boolean) - close the notification when clicked. Useful in
chrome where the notification remains open until the timeout or the x is clicked.
* `notifyShow`: (function) - callback when notification is shown
* `notifyClose`: (function) - callback when notification is closed
* `notifyClick`: (function) - callback when notification is clicked
* `notifyError`: (function) - callback when notification throws an error

Static methods and properties
-----------------------------

* `Notify.requestPermission(onPermissionGrantedCallback, onPermissionDeniedCallback)` -
requests permission from the user if needed and handles permission callbacks.
* `Notify.isSupported` - Function to test for Web Notifications API browser
support
* `Notify.needsPermission` - Boolean property to check if permission is needed
for the user to receive notifications.

Instance methods
----------------
* `Notify.show` - Function to display the Notify instance
* `Notify.close` - Function to close the Notify instance

Test
----

In the project root, to perform a single pass of the tests using Firefox run:

```
npm run test
```

This will also automatically build from source before running the tests.

Demo example
------------

An easy way to run the provided demo file is to use python `SimpleHTTPServer`
and then navigate to the `/example` directory:

```
python -m SimpleHTTPServer
```

Browser support
---------------

http://caniuse.com/#search=notifications

---
_Source: https://npm.io/package/notifyjs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
