Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

detect-touch

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

detect-touch

Detects if a device has a touch interface

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
369
increased by6.65%
Maintainers
1
Weekly downloads
 
Created
Source

Detect Touch Devices

Live touch detection test

detect-touch will detect if a device has a touch interface. It provides both a boolean one time touch detection on import, as well as a function to run the touch detection at any time.

WARNING: There is no absolute way to detect a touch interface, and detect-touch will not correctly detect a touch interface 100% of the time, but very close to it, try the live touch detection test with different devices to test out its reliability. Also, just because a device has a touch interface doesn't mean that it doesn't have a mouse as well.

 

Installing detect-touch

$ npm install detect-touch

 

Importing detect-touch

Import only the hasTouch boolean:

import { hasTouch } from 'detect-touch';
// or
var hasTouch = require('detect-touch').hasTouch;

Import only the detectTouch function:

import { detectTouch } from 'detect-touch';
// or
var detectTouch = require('detect-touch').detectTouch;

Import both the hasTouch boolean and the detectTouch function:

import { hasTouch, detectTouch } from 'detect-touch';
// or
var hasTouch = require('detect-touch').hasTouch;
var detectTouch = require('detect-touch').detectTouch;

 

Using detect-touch

The hasTouch boolean is established at the time it is imported, and the function to detect a touch device runs only one time. In most cases this is all you need as either a device has touch capabilities or it does not.

// Using the hasTouch boolean:
hasTouch === true;
// or
hasTouch === false;

The detectTouch function attempts to detect a touch device each time it is called and can be used to check or recheck for a touch device at a specific time. Returns a boolean.

// Using the detectTouch function:
detectTouch() === true;
// or
detectTouch() === false;

FAQs

Package last updated on 21 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc