UNPKG

use-haptic

Version:

A convenient React hook to trigger haptic feedback anywhere in your application

43 lines (42 loc) 1.39 kB
"use strict"; /** * Utility functions for device detection */ Object.defineProperty(exports, "__esModule", { value: true }); exports.detectMobile = exports.detectAndroid = exports.detectiOS = void 0; /** * Detects if the current device is running iOS * @returns {boolean} true if the device is running iOS, false otherwise */ const detectiOS = () => { if (typeof navigator === "undefined") { return false; } const toMatch = [/iPhone/i, /iPad/i, /iPod/i]; return toMatch.some((toMatchItem) => { return RegExp(toMatchItem).exec(navigator.userAgent); }); }; exports.detectiOS = detectiOS; /** * Detects if the current device is running Android * @returns {boolean} true if the device is running Android, false otherwise */ const detectAndroid = () => { if (typeof navigator === "undefined") { return false; } const toMatch = [/Android/i, /webOS/i, /BlackBerry/i, /Windows Phone/i]; return toMatch.some((toMatchItem) => { return RegExp(toMatchItem).exec(navigator.userAgent); }); }; exports.detectAndroid = detectAndroid; /** * Detects if the current device is a mobile device (iOS or Android) * @returns {boolean} true if the device is a mobile device, false otherwise */ const detectMobile = () => { return (0, exports.detectiOS)() || (0, exports.detectAndroid)(); }; exports.detectMobile = detectMobile;