
Security News
Bun 1.2.19 Adds Isolated Installs for Better Monorepo Support
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
detect-touch
Advanced tools
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.
detect-touch
$ npm install --save detect-touch
detect-touch
Importing only the hasTouch
boolean:
import { hasTouch } from 'detect-touch';
// or
var hasTouch = require('detect-touch').hasTouch;
Importing only the detectTouch
function:
import { detectTouch } from 'detect-touch';
// or
var detectTouch = require('detect-touch').detectTouch;
Importing 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;
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.
// 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. For example, if detect-touch
doesn't have access to the window
when it is imported you'll need to wait until it does before checking if a device has a touch interface.
// Using the detectTouch function:
detectTouch() === true;
// or
detectTouch() === false;
detect-touch
checks to see if the browser implements any of the following:
The standard W3C Touch Events API (this is the vast majority of touch devices), by checking for:
'ontouchstart' in window
Number of touch points (required to detect Microsoft's Pointer Events API running on a touch device, however, devices not implementing Pointer Events may also indicate this), by checking for:
window.navigator.maxTouchPoints > 0 ||
window.navigator.msMaxTouchPoints > 0 // pre IE 11
Firefox's legacy DocumentTouch
(which is now obsolete), by checking for:
window.DocumentTouch && document instanceof DocumentTouch
FAQs
Detects if a device has a touch interface
The npm package detect-touch receives a total of 310 weekly downloads. As such, detect-touch popularity was classified as not popular.
We found that detect-touch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.
Security News
Popular npm packages like eslint-config-prettier were compromised after a phishing attack stole a maintainer’s token, spreading malicious updates.
Security News
/Research
A phishing attack targeted developers using a typosquatted npm domain (npnjs.com) to steal credentials via fake login pages - watch out for similar scams.