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

easy-pwa-js

v1.1.0

Published

Javascript library for managing PWA (progressive web app).

Downloads

25

Readme

EasyPWA

Tools for managing your Progressive Web App.

Features

  • Manage PWA features easily
  • Each browser shows a specific helper to help people to install your app.
  • Manage Push Notifications easily.

Example

An example is available here: https://easy-pwa.github.io/easy-pwa-js/

Install

ES6

npm install easy-pwa-js --save

Use it in your modules:

import EasyPwaManager from 'easy-pwa-js/front';

In your service worker:

importScripts('easy-pwa-js/sw.js');

Standard method

Add this script on your page:

<script type="module" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/front.js"></script>

Add this script in your service worker:

importScripts('https://cdn.jsdelivr.net/npm/[email protected]/dist/sw.js');

How to use it

Initialize EasyPWA

For beginning, initialize EasyPWA with your configuration.

EasyPWA.init({
    swPath: '/example/sw.js',
    swRegistrationOptions: {scope: '/'},
    debug: true,
    desktop: true,
});

Invite the user to install your app

If a helper is available for the current browser, EasyPWA emits an event automatically. You have to listen and interact with it.

Automatic method

With this method, EasyPWA shows a standard invite:

window.addEventListener('easy-pwa-helper-available', function(event) {
    event.showInvite();
});

For a custom invite

If you want to create your own invite for a customized style.

Example of your html invite:

<div id="my_custom_invite">
Install my app ?
<button id="invite_accept">yes</button>
<button id="invite_dismiss">no</button>
</div>

javascript invite:

window.addEventListener('easy-pwa-helper-available', function(event) {
    document.getElementById('invite_accept').addEventListener('click', function() {
        document.getElementById('my_custom_invite').display = 'none';
        event.acceptInvite();
    });

document.getElementById('invite_dismiss').addEventListener('click', function() {
        document.getElementById('my_custom_invite').display = 'none';
        event.dismissInvite();
    });
});

Push notifications

Always wait EasyPWA is fully initialized before.

window.addEventListener('easy-pwa-ready', function(e) {
    EasyPWA.requestPermission().then( function() {
        // Permissions is now granted

        new Notification('A notification');
    });
});

Available configuration

A list of configuration elements if available here

Available functions

Initialize EasyPWA

EasyPWA.init({...});

Get manifest data

var manifest = EasyPWA.getManifest();
console.log('The name is: '+manifest.name);

Check if PWA is in standalone mode

if (EasyPWA.isAppMode()) {
    console.log('Site is open as an app');
}

Check if the current browser supports notifications

if (EasyPWA.isNotificationSupported()) {
    console.log('Notification is supported on this browser.');
}

Request permission to send notification

First, you need to ask permission.

EasyPWA.requestNotificationPermission().then(function() {
    console.log('Accepted. You can get a token with Firebase.');
}).catch(function() {
    console.log('denied. User must authorize notifications in their bowser settings.');
});

Available Events

Wait Easy PWA is fully initialized

window.addEventListener('easy-pwa-ready', function(e) {
    console.log('I\'m ready!');
});

Listening if install prompt is available

window.addEventListener('easy-pwa-helper-available', function(helperAvailableEvent) {
    console.log('A helper is available for this browser!');

    helperAvailableEvent.showInvite();
    // OR
    helperAvailableEvent.acceptInvite();
    helperAvailableEvent.dismissInvite();
});

Detect that page is changing

In standalone mode, there are not browser elements visible. So, maybe, you would like to show a loader when page is changing.

window.addEventListener('easy-pwa-page-changing', function(e) {
    console.log('Show a loader, page is changing!');
});

Other tools

Managing online/offline view by css

When you are offline, the css class "offline" is added on the body tag.

<body class="... offline">
    <div class="text-offline">You are offline but you can still access to your favorite website.</div>
</body>
.text-offline {
    display: none;
}

.offline .text-offline {
    display: block;
}

External library included

  • PWACompat is a library that brings the Web App Manifest to non-compliant browsers for better Progressive Web Apps.

Help

Use chrome browser for testing you PWA, there are more available tools: