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

pwanat-sdk

v1.0.6

Published

A cordova native helper for front-end applications

Downloads

436

Readme

Progressive Web App Native Support

A cordova native helper for front-end applicationss

This package provides a set of utilities for interacting with webviews, notifications, file management, Firebase messaging, hot code updates and more in a Cordova/PhoneGap environment.

Pwanat

The Pwanat object provides various utilities for detecting the platform, managing device settings, performing clipboard actions and many more. Below are the available methods and their descriptions.

Properties:

  • isNative: A boolean indicating if the app is running in a native environment.
  • platform: A string that stores the platform information.

Methods:

  • init(): Initializes the Pwanat object, typically resolving after detecting the platform or native state.

    await Pwanat.init();
  • detectDevice(): Detects the current device and returns device information.

    const device = Pwanat.detectDevice();
  • getDeviceInformation(): Fetches and returns information about the device.

    const info = Pwanat.getDeviceInformation();
  • getBuildInfo(): Returns information about the build version.

    const buildInfo = Pwanat.getBuildInfo();
  • showAlert(message): Displays a native alert with the specified message.

    Pwanat.showAlert('This is an alert message');
  • lockOrientation(orientation = "portrait-primary"): Locks the screen orientation.

    Pwanat.lockOrientation('landscape');
  • copy(text): Copies the specified text to the clipboard.

    Pwanat.copy('Copied text');
  • paste(): Asynchronously retrieves the current content from the clipboard.

    const clipboardContent = await Pwanat.paste();
  • setAndroidFullScreen(): Sets the app to full-screen mode on Android devices.

    Pwanat.setAndroidFullScreen();
  • resetAndroidFullScreen(): Resets full-screen mode on Android devices.

    Pwanat.resetAndroidFullScreen();

Features

  • Browser:

    • system(url): Opens a system browser with the provided URL.
    • webview(url, options): Opens a webview with the given URL and options.
    • closeWebview(): Closes the currently open webview.
  • File:

    • saveImageFromUrl(url, filename): Downloads an image from a URL and saves it to the local file system.
    • saveImageFromBase64(base64Image, filename): Saves a base64-encoded image to the local file system.
  • Notification:

    • showLocalNotification(title, text): Displays a local notification with the given title and text.
    • setBadge(count): Sets the app icon badge number.
    • firebaseGetToken(): Retrieves the Firebase device token asynchronously.
    • registerFirebaseListener(): Registers Firebase event listeners for token refresh and incoming messages.
  • Social Share:

    • appShare(msg, url): Shares a message via the app.
    • fb(msg, url): Shares a message to Facebook.
    • ig(msg, url): Shares a message to Instagram.
    • whatsapp(msg, url): Shares a message via WhatsApp.
    • tg(msg, url): Shares a message via Telegram.
  • HCP (Hot Code Push):

    • checkUpdates(versionJsonUrl, currentVersion): Checks for app updates based on the given version file URL.
    • downloadPackage(packageUrl, version): Downloads a package from the provided URL and version.
    • installPackage(fileURL): Installs the package from the given file URL.
    • deleteZipFile(fileURL): Deletes a zip file from the given file URL.
  • Google:

    • referrer(): Fetches the Google Play referrer information.

Installation

To install this package, run:

npm install pwanat-sdk

Usage

Provide usage examples for the main functionality of your package.

Example 1: Opening a Webview

import Pwanat from 'pwanat-sdk';

const result = await Pwanat.Browser.webview('https://example.com', {
  title: 'Example',
  fullscreen: true
});
if (result.status === 0) {
    console.log('Failed to create a new webview', result.msg);
}

Example 2: Saving an Image from Base64

import Pwanat from 'pwanat-sdk';

const result = await Pwanat.File.saveImageFromBase64(base64String, 'myImage.png');
if (result.status === 1) {
    console.log('Image saved successfully!', result);
} else {
    console.log('Error saving!');
}

Example 3: Registering Firebase Listeners

import Pwanat from 'pwanat-sdk';

Pwanat.Notification.registerFirebaseListener();

Example 4: Implementing Hot Code Push

import Pwanat from 'pwanat-sdk';

const hcpUrl = 'https://example.com/version.json';
const version = import.meta.env.VITE_APP_VERSION as string

try {
  const checkUpdate = await Pwanat.HCP.checkUpdates(hcpUrl, version);
  if (checkUpdate.status === 1) {
    switch(checkUpdate.data.type) {
      case "ContentUpdate":
        const handleProgress = (event: CustomEvent): void => {
          checkingUpdate.value = true; // show the page for updating UI
          if (event.detail.updateTitle) {
            checkingUpdateTitle.value = event.detail.updateTitle;
          }
          if (event.detail.updateSubtitle) {
            checkingUpdateSubTitle.value = event.detail.updateSubtitle;
          }
          if (event.detail.percent) {
            checkingUpdateProgress.value = event.detail.percent;
          }
        };
        // Listen for the update event to track the progress
        window.addEventListener("appUpdateInformation", handleProgress as EventListener);

        const downloadPackage =  await Pwanat.HCP.downloadPackage(checkUpdate.data.packageUrl, checkUpdate.data.version);
        if(downloadPackage.status === 1) {
          const installPackage = await Pwanat.HCP.installPackage(downloadPackage.data);
          if(installPackage.status === 1) {
            window.location.reload(); // reload the page to see the updated content
          }else {
            Pwanat.showAlert(installPackage.msg);
          }
        } else {
          Pwanat.showAlert(downloadPackage.msg);
        }
        break;
      case "AppUpdate":
        // open the system browser where user's can download the new apk/ipa
        Pwanat.Browser.system(checkUpdate.data.appDownloadUrl);
        break;
      default:
        // means the app is updated
        break;
    }
  } else {
    Pwanat.showAlert(checkUpdate.msg);
  }
} catch (error) {
  let errorMessage = "An unknown error occurred while checking for updates";

  // Check if the error is an instance of Error and use its message
  if (error instanceof Error) {
    errorMessage = error.message;
  } else if (typeof error === "string") {
    errorMessage = error; // If it's a string, use it directly
  }
  Pwanat.showAlert(errorMessage);
}

API Reference

Browser

  • system(url): Opens the system browser with the provided URL.
  • webview(url, options): Opens a webview with the provided URL and options.

File

  • saveImageFromUrl(url, filename): Downloads an image from the provided URL and saves it to the specified file path.
  • saveImageFromBase64(base64Image, fileName = 'downloadedImage.png'): Saves a base64-encoded image as a file.

Notification

  • showLocalNotification(title, text): Displays a local notification with the specified title and text.
  • setBadge(count): Sets the app badge number to the provided count.
  • firebaseGetToken(): Asynchronously retrieves the Firebase token for the device.
  • registerFirebaseListener(): Registers event listeners for Firebase messaging.

Social Share

  • appShare(msg, url): Shares the given message and URL via the app.
  • fb(msg, url): Shares the given message and URL on Facebook.
  • ig(msg, url): Shares the given message and URL on Instagram.
  • whatsapp(msg, url): Shares the given message and URL on WhatsApp.
  • tg(msg, url): Shares the given message and URL on Telegram.

HCP

  • checkUpdates(versionJsonUrl, currentVersion): Checks for app updates based on the given version JSON URL.
  • downloadPackage(packageUrl, version): Downloads a package from the provided URL and version.
  • installPackage(fileURL): Installs the downloaded package from the provided file URL.
  • deleteZipFile(fileURL): Deletes the zip file at the provided file URL.

Google

  • referrer(): Fetches the Google Play referrer and passes it to the callback function.

License

This project is licensed under the MIT License - see the LICENSE file for details.