{"id":19533952,"url":"https://github.com/rafgraph/detect-touch","last_synced_at":"2025-04-26T14:34:33.828Z","repository":{"id":66154996,"uuid":"59320563","full_name":"rafgraph/detect-touch","owner":"rafgraph","description":"Detect if a device has a touch interface","archived":false,"fork":false,"pushed_at":"2020-09-10T19:04:17.000Z","size":378,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-15T11:00:52.734Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://detect-touch.rafgraph.dev","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rafgraph.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-20T19:21:58.000Z","updated_at":"2020-09-10T18:45:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"6444706a-67b9-4b2d-9a58-0b273aa4d55e","html_url":"https://github.com/rafgraph/detect-touch","commit_stats":{"total_commits":23,"total_committers":2,"mean_commits":11.5,"dds":0.08695652173913049,"last_synced_commit":"55a2a608c4bd4baea67102fe89ba62cd2d4225a1"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafgraph%2Fdetect-touch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafgraph%2Fdetect-touch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafgraph%2Fdetect-touch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafgraph%2Fdetect-touch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rafgraph","download_url":"https://codeload.github.com/rafgraph/detect-touch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250960866,"owners_count":21514536,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T02:11:19.339Z","updated_at":"2025-04-26T14:34:33.596Z","avatar_url":"https://github.com/rafgraph.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\n### *This has been deprecated in favor of [Detect It](https://github.com/rafgraph/detect-it)*\n---\n# Detect Touch Devices\n\u0026nbsp;\n\n[Live touch detection test][liveTest]\n\n`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.\n\n[liveTest]: https://detect-touch.rafgraph.dev\n\n\u0026nbsp;\n## Installing `detect-touch`\n```terminal\n$ npm install --save detect-touch\n```\n\u0026nbsp;\n## Importing `detect-touch`\nImporting only the `hasTouch` boolean:\n```javascript\nimport { hasTouch } from 'detect-touch';\n// or\nvar hasTouch = require('detect-touch').hasTouch;\n```\n\nImporting only the `detectTouch` function:\n```javascript\nimport { detectTouch } from 'detect-touch';\n// or\nvar detectTouch = require('detect-touch').detectTouch;\n```\n\nImporting both the `hasTouch` boolean and the `detectTouch` function:\n```javascript\nimport { hasTouch, detectTouch } from 'detect-touch';\n// or\nvar hasTouch = require('detect-touch').hasTouch;\nvar detectTouch = require('detect-touch').detectTouch;\n```\n\n\u0026nbsp;\n## Using `detect-touch`\n\nThe `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.\n```javascript\n// Using the hasTouch boolean:\nhasTouch === true;\n// or\nhasTouch === false;\n```\n\nThe `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.\n```javascript\n// Using the detectTouch function:\ndetectTouch() === true;\n// or\ndetectTouch() === false;\n```\n\n\u0026nbsp;\n## Detection Tests\n`detect-touch` checks to see if the browser implements any of the following:  \n\nThe standard [W3C Touch Events API][w3cTE] (this is the vast majority of touch devices), by checking for:\n```javascript\n'ontouchstart' in window\n```\nNumber of touch points (required to detect [Microsoft's Pointer Events API running on a touch device][maxTP], however, devices not implementing Pointer Events may also indicate this), by checking for:\n```javascript\nwindow.navigator.maxTouchPoints \u003e 0 ||\nwindow.navigator.msMaxTouchPoints \u003e 0 // pre IE 11\n```\n[Firefox's legacy `DocumentTouch`][docT] (which is now obsolete), by checking for:\n```javascript\nwindow.DocumentTouch \u0026\u0026 document instanceof DocumentTouch\n```\n\n[w3cTE]: https://www.w3.org/TR/touch-events/\n[maxTP]: https://msdn.microsoft.com/en-us/library/dn433244(v=vs.85).aspx#feature_detection_and_touch_support_testing\n[docT]: https://developer.mozilla.org/en-US/docs/Web/API/DocumentTouch\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafgraph%2Fdetect-touch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frafgraph%2Fdetect-touch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafgraph%2Fdetect-touch/lists"}