@zulfikawr/haptix
v1.0.0
Published
A lightweight, zero-dependency TypeScript wrapper around the Web Vibration API
Maintainers
Readme
@zulfikawr/haptix
A lightweight, zero-dependency TypeScript wrapper around the Web Vibration API (navigator.vibrate), with a clean developer-friendly interface for triggering haptic feedback patterns in browsers.
Features
- Zero dependencies
- Clean API for common patterns (tap, doubleTap, success, error)
- TypeScript support out of the box
- Chainable and simple logic for custom patterns
Installation
bun add @zulfikawr/haptix
# or
npm install @zulfikawr/haptixFunctions
| Function | Description |
|---|---|
| haptix.tap() | Single short tap (like a button press) |
| haptix.doubleTap() | Two quick taps |
| haptix.long() | Long sustained buzz |
| haptix.success() | Pleasant success pattern |
| haptix.error() | Urgent error pattern |
| haptix.warning() | Softer warning pulse |
| haptix.pulse(n) | Repeating pulse n times |
| haptix.pattern(number[]) | Raw custom vibration pattern |
| haptix.stop() | Stop any ongoing vibration |
| haptix.isSupported() | Check if device supports haptics |
Usage
import haptix from '@zulfikawr/haptix'
// Check support first
if (haptix.isSupported()) {
haptix.tap() // quick tap
haptix.success() // success feedback
haptix.pulse(3) // buzz 3 times
haptix.pattern([100, 50, 200, 50, 100]) // custom pattern
haptix.stop() // cancel
}With a button:
button.addEventListener('click', () => haptix.tap())
button.addEventListener('click', () => haptix.error())License
MIT
