Skip to content

Getting Started

@hapticjs is a universal haptics engine for JavaScript and TypeScript. It provides semantic haptic effects, a pattern language (HPL), 55+ presets, and framework integrations -- all in under 3KB gzipped with zero dependencies.

Installation

bash
npm install @hapticjs/core
bash
pnpm add @hapticjs/core
bash
yarn add @hapticjs/core

Your First Haptic

The fastest way to get started is with the pre-configured haptic singleton:

typescript
import { haptic } from '@hapticjs/core';

// Semantic effects
haptic.tap();
haptic.success();
haptic.error();

// Play an HPL pattern
haptic.play('~~..##..@@');

The haptic singleton auto-detects the best adapter for the current platform -- Web Vibration API on Android, audio haptics on iOS, visual fallback on desktop, and no-op on the server.

Creating a Custom Engine

For more control, create your own HapticEngine instance:

typescript
import { HapticEngine } from '@hapticjs/core';

const engine = HapticEngine.create({
  enabled: true,
  intensity: 0.8,
  fallback: {
    type: 'visual',
    visual: {
      style: 'flash',
    },
  },
});

engine.tap();
engine.play('~~..##..@@');

Configuration Options

OptionTypeDefaultDescription
enabledbooleantrueWhether haptics are enabled
intensitynumber1.0Global intensity multiplier (0.0 - 1.0)
adapterHapticAdapterauto-detectedOverride the adapter
fallbackFallbackConfig{ type: 'none' }Fallback when haptics unavailable
respectSystemSettingsbooleantrueRespect OS haptic preferences

Platform Support

PlatformAPIStatus
Android ChromeVibration APIFull support
Android FirefoxVibration APIFull support
iOS SafariiOS Audio AdapterAudio haptic fallback
Desktop Chrome--Visual/audio fallback
GamepadGamepadHapticActuatorDual-motor rumble
React NativeNative adapterNative haptics
Node.js / SSRNoopAdapterSafe no-op

What's Next?

Released under the MIT License.