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

ng-haptics

v1.2.0

Published

Angular-native haptic feedback library using Web Vibration API

Readme

ng-haptics

npm version CI License: MIT Angular Bundle size

The modern, Angular-native way to add haptic feedback to web applications.

Live Demo →

Features

  • 🅰️ Angular-native — DI, standalone APIs, Signals-ready
  • 🌐 SSR-safe — works with Angular Universal, no window/navigator on server
  • 📦 Zero dependencies — pure Web Vibration API, no Capacitor, no Ionic
  • 🎯 Declarative — directives and service for every use case
  • 🔍 Support detection — runtime HapticsService.support() exposes platform/browser/method info
  • 🛡️ Cooldown protection — built-in throttling prevents accidental vibration spam
  • 🪶 Accessible — respects prefers-reduced-motion by default
  • 🧪 Debug mode — log clear haptics events when enabled
  • 🔬 Testable — adapter pattern makes testing trivial
  • 🪶 Tiny — <10kb gzip, tree-shakeable, side-effect free

Installation

npm install ng-haptics

Quick Start

1. Add the provider:

// app.config.ts
import { provideHaptics } from 'ng-haptics';

export const appConfig: ApplicationConfig = {
  providers: [
    provideHaptics(),
  ],
};

2. Use the service:

import { HapticsService } from 'ng-haptics';

@Component({ ... })
export class MyComponent {
  private readonly haptics = inject(HapticsService);

  onSave() {
    this.haptics.success();
  }
}

3. Or use directives:

<button ngHapticClick="success">Save</button>
<button ngHapticTap="medium">Submit</button>
<form ngHapticForm successPreset="success" errorPreset="warning" novalidate>
  <input name="email" ngModel required placeholder="[email protected]" />
  <button type="submit">Submit</button>
</form>

API Reference

HapticsService

const haptics = inject(HapticsService);

// Impact presets
haptics.light();
haptics.medium();
haptics.heavy();

// Notification presets
haptics.success();
haptics.warning();
haptics.error();

// UI feedback
haptics.selection();

// Custom pattern (navigator.vibrate format)
haptics.pattern([50, 30, 50]);

// Sequence with delays
await haptics.sequence([
  'light',
  { delay: 40 },
  'success',
]);

// Check support
haptics.isSupported; // boolean

// Runtime support details
const support = haptics.support();
console.log(support);

// Example support result
// {
//   supported: true,
//   platform: 'ios',
//   method: 'ios-switch',
//   browser: 'chrome',
//   reducedMotion: false,
// }

Directives

| Directive | Event | Example | |-----------|-------|---------| | [ngHapticClick] | click | <button ngHapticClick="success"> | | [ngHapticTap] | pointerdown | <button ngHapticTap="medium"> | | [ngHapticHover] | pointerenter | <div [ngHapticHover]="'light'"> | | ngHapticForm | submit | <form ngHapticForm successPreset="success" errorPreset="warning"> |

provideHaptics(config?)

interface HapticsConfig {
  enabled?: boolean;              // default: true
  respectReducedMotion?: boolean; // default: true
  debug?: boolean;                // default: false
  cooldown?: number;              // ms, default: 0
}
provideHaptics({
  debug: !environment.production,
  cooldown: 40,
  respectReducedMotion: true,
});

debug enables console logging in development, cooldown prevents accidental vibration spam, and respectReducedMotion keeps haptics silent for users who opt into reduced motion.

Browser Support

| Platform | Support | |----------|---------| | Android Chrome / Firefox | ✅ Full (Web Vibration API) | | iOS Safari / Chrome | ✅ Full (WebKit switch trick) | | Desktop browsers | — Silent no-op (no haptic hardware) | | SSR / Node.js | — Silent no-op |

Note: ng-haptics reports runtime support with HapticsService.support(), and it respects prefers-reduced-motion by default unless disabled via provideHaptics({ respectReducedMotion: false }).

Architecture

HapticsService
    ↓
HapticsAdapter (interface)
    ↓
WebVibrationAdapter     IosSwitchAdapter       NoopAdapter
(Android/Firefox)       (iOS Safari/Chrome)    (SSR/desktop)
navigator.vibrate()     <input switch>.click()

The adapter pattern cleanly separates the Angular API from the browser implementation, making testing, SSR, and future extensions straightforward.

Development

# Install
npm install

# Run demo (with hot reload)
npm start

# Run demo accessible from mobile on local network
npm run start:host

# Tests
npm test

# Build library
npm run build

# Lint
npm run lint

Contributing

Pull requests are welcome. Please follow Conventional Commits for commit messages.

License

MIT © Nicolás Giacconi