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

portable-haptics

v0.1.0

Published

Dependency-free browser haptics helper with navigator.vibrate and conservative iOS WebKit switch fallback.

Readme

Portable Haptics

Small dependency-free browser haptics helper for personal prototypes, mobile web toys, and browser games.

It uses navigator.vibrate() where available, and can fall back to the iOS Safari / iOS WebKit <input type="checkbox" switch> haptic-feedback behavior described in Safari release notes and community writeups. Unsupported environments safely return false.

This package is intentionally conservative: it does not monkeypatch navigator.vibrate, does not reparent the DOM, does not install framework adapters, and does not use audio fallback. Prior art was reviewed; this package does not vendor or copy third-party code.

Package Files

  • portable-haptics.mjs: ESM library.
  • portable-haptics.d.ts: TypeScript declarations.
  • README.md: package usage notes.
  • LICENSE: MIT license.

demo.html and RESEARCH.md are local repository aids and are not published to npm.

Install

From a packed tarball:

npm install ./portable-haptics-0.1.0.tgz

From a local folder:

npm install ./portable-haptics

After publishing:

npm install portable-haptics

Quick Use

<button id="tap">Tap</button>

<script type="module">
  import { haptic } from "portable-haptics";

  document.querySelector("#tap").addEventListener("click", () => {
    haptic("light");
  });
</script>

Instance API

import { createHaptics } from "portable-haptics";

const haptics = createHaptics({
  cooldownMs: 32,
  maxPulsesPerMinute: 180,
});

button.addEventListener("click", () => {
  haptics.play("selection");
});

successButton.addEventListener("click", () => {
  haptics.play("success");
});

Available built-in effects:

  • selection
  • light
  • medium
  • heavy
  • success
  • warning
  • error

For one-off custom effects:

haptics.play({ vibrate: [20, 30, 20], pulses: [0, 70] });
haptics.pulse(3, 60);

vibrate is used by browsers that support the Vibration API. pulses is used by the iOS Safari switch fallback, where each pulse is one hidden switch click.

Diagnostics

console.table(haptics.diagnose());

diagnose() reports the active capability path and warnings such as ios-switch-hack-disabled-for-version.

Design Goals

  • Keep it tiny and dependency-free.
  • Make haptics an enhancement, never required behavior.
  • Avoid global monkeypatching and app-wide DOM tricks.
  • Prefer explicit calls from user interaction handlers.
  • Disable the iOS switch fallback on parsed iOS versions newer than the known working range unless explicitly forced.

Publishing Checklist

  • Choose the final package name, preferably scoped, such as @your-scope/portable-haptics.
  • Re-check name availability on npm immediately before publishing.
  • Run npm run check.
  • Run npm pack --dry-run.
  • Publish with npm publish --access public when the package name and license are final.

Important Notes

  • iOS Safari does not support the Vibration API.
  • The iOS fallback relies on Safari 18's native haptic feedback for <input type="checkbox" switch>.
  • A similar package, ios-haptics, documents that Apple patched its programmatic label-click path in iOS 26.5. This package therefore defaults iosSwitchMaxVersion to [26, 4].
  • The fallback cannot control duration or strength like navigator.vibrate().
  • You can opt into a forced attempt with createHaptics({ enableIOSSwitchHack: "force" }), but treat it as best-effort.
  • Call haptics from a user interaction such as pointerdown, click, or a game input event.
  • This is an implementation quirk and may change in future Safari versions.

Recommended Pattern

Use haptics as an enhancement, never as required feedback.

const didHaptic = haptics.play("light");

if (!didHaptic) {
  // Keep visual/audio feedback working here.
}