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 🙏

© 2026 – Pkg Stats / Ryan Hefner

web-permission-kit

v0.0.5

Published

TypeScript library bridging the Web Permissions API to a unified check/request interface — Notification, Geolocation, Camera, Microphone, Clipboard, MIDI, DeviceOrientation, DeviceMotion, PersistentStorage.

Readme

npm bundle size types

web-permission-kit

A tiny TypeScript library that bridges the Web Permissions API to a unified check / request / subscribe interface, with fallbacks for legacy getUserMedia, iOS Safari sensor permissions, and browsers that don't reliably dispatch permission change events.

npm install web-permission-kit

API at a glance

| Member | Signature | Description | |-------------------------------------| --- | --- | | PermissionKit.supported | boolean (getter) | Whether navigator.permissions (the Query API) exists | | PermissionKit.version | string | The installed package version | | PermissionKit.check(type) | Promise<PermissionState> | Reads the current state without prompting | | PermissionKit.request(type) | Promise<PermissionState> | Requests the permission, prompting if needed | | PermissionKit.subscribe(type, cb) | () => void | Observes state changes; returns an unsubscribe function. Sensors are not observable — see Notes | | PermissionKit.Type | PermissionType | Enum of permission types (alias of the named export) | | PermissionKit.State | PermissionState | Enum of states (alias of the named export) |

PermissionState resolves to one of: "grant", "denied", "prompt", "unsupported".

PermissionType members: Notification, Geolocation, Camera, Microphone, ClipboardRead, ClipboardWrite, MIDI, DeviceOrientation, DeviceMotion, PersistentStorage.


ESM

import PermissionKit, { PermissionType, PermissionState } from 'web-permission-kit'

// Read the current state without prompting the user
const state = await PermissionKit.check(PermissionType.Camera)
console.log(state) // "grant" | "denied" | "prompt" | "unsupported"

// Request the permission (prompts only when needed)
if (state !== PermissionState.Grant) {
  const result = await PermissionKit.request(PermissionType.Microphone)
  if (result === PermissionState.Grant) {
    // start capturing
  }
}

// The enums are also reachable off the singleton, so the named imports are optional
await PermissionKit.check(PermissionKit.Type.Geolocation)

CommonJS

The bundle is built with exports: "named", so the singleton lives under .default:

const { default: PermissionKit, PermissionType, PermissionState } = require('web-permission-kit')

PermissionKit.check(PermissionType.Geolocation).then((state) => {
  if (state === PermissionState.Prompt) {
    return PermissionKit.request(PermissionType.Geolocation)
  }
})

UMD (browser <script>)

The global PermissionKit is a namespace object. The singleton is PermissionKit.default; the enums are PermissionKit.PermissionType / PermissionKit.PermissionState. The bundle is self-contained — no other scripts are required.

<script src="https://unpkg.com/web-permission-kit/dist/permission-kit.umd.min.js"></script>
<script>
    var perm = window.PermissionKit.default
    var Type = window.PermissionKit.PermissionType

    perm.check(Type.ClipboardRead).then(function (state) {
        console.log(state)
    })

    // Device sensors must be requested from a user gesture (see Notes)
    document.querySelector('#enable').addEventListener('click', function () {
        perm.request(Type.DeviceOrientation).then(function (state) {
            console.log(state)
        })
    })
</script>

TypeScript

PermissionType and PermissionState are string enums (usable as both value and type). The instance shape is exported as PermissionKitInstance.

import PermissionKit, {
  PermissionType,
  PermissionState,
  type PermissionKitInstance,
} from 'web-permission-kit'

async function ensure(type: PermissionType): Promise<boolean> {
  const state: PermissionState = await PermissionKit.check(type)

  if (state === PermissionState.Grant) return true
  if (state === PermissionState.Denied || state === PermissionState.Unsupported) return false

  // state === Prompt → ask
  return (await PermissionKit.request(type)) === PermissionState.Grant
}

const granted = await ensure(PermissionType.Camera)

Observing changes

subscribe watches a permission and calls your callback whenever the state changes. It returns an unsubscribe function — call it to tear everything down.

import PermissionKit, { PermissionType } from 'web-permission-kit'

// Fires once immediately with the current state, then again on every change.
const unsubscribe = PermissionKit.subscribe(PermissionType.Camera, (state) => {
  console.log('camera permission is now', state)
})

// Stop listening
unsubscribe()

In CommonJS / UMD the method lives on the singleton: require('web-permission-kit').default.subscribe(...) / window.PermissionKit.default.subscribe(...).

How it stays in sync

  • The callback is invoked once on subscribe with the current state, then on every change. Repeated identical states are de-duplicated.
  • It listens to the native PermissionStatus change event where available.
  • Some browsers (notably Safari) don't reliably fire that event when the user flips a permission in settings, so the subscription also re-checks when the page/app regains focusvisibilitychange / focus, with Cordova resume and legacy iOS pageshow variants handled. Focus bursts are debounced, so a return to the tab triggers at most one re-check.
  • Sensors can't be observed. DeviceOrientation / DeviceMotion have no PermissionStatus, so subscribe fires once with the current state and returns a no-op unsubscribe.

Notes

  • check never prompts; request may. check reflects the stored state, so call it on load to decide your UI; call request from the action that needs access.
  • Device sensors need a user gesture. On iOS Safari, request(DeviceOrientation) and request(DeviceMotion) must be triggered inside a click/tap handler, otherwise the underlying requestPermission() rejects.
  • ClipboardWrite is query-only. Write access can't be prompted without clobbering the clipboard, so request(ClipboardWrite) returns the queried state rather than forcing a prompt. The actual clipboard.write() may still succeed inside a gesture even when check reports prompt/unsupported.
  • .default in CJS/UMD is a consequence of keeping both a default and named exports. To drop it, switch the entry to fully-named exports and rebuild.