Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/optonaut/detect-device
Detects (mobile) device used based on screen dimensions (width, height, dppx). Includes list of all devices.
https://github.com/optonaut/detect-device
Last synced: 10 days ago
JSON representation
Detects (mobile) device used based on screen dimensions (width, height, dppx). Includes list of all devices.
- Host: GitHub
- URL: https://github.com/optonaut/detect-device
- Owner: optonaut
- License: mit
- Created: 2015-12-09T10:39:52.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-12-13T22:01:01.000Z (about 9 years ago)
- Last Synced: 2024-12-06T09:18:20.792Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 16.6 KB
- Stars: 2
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# detect-device
Detects (mobile) device used based on screen dimensions (width, height, dppx). Includes list of all devices.## Demo
[Open this link](https://rawgit.com/optonaut/detect-device/master/dist/demo.html) on a mobile device. If it couldn't be detected please [open a pull request for it](https://github.com/optonaut/detect-device/compare).
## Install
```sh
$ npm install detect-device
```## Usage
```js
import { detect, devices } = 'detect-devices'const detectedDevice = detect()
console.log(detectedDevice)
\\ { "name": "Apple iPhone 6", "width": 750, "height": 1334, "diagonal": 4.7, "ppi": 326, "dppx": 2 }const iPhone5 = detect({
width: 640,
height: 1136,
dppx: 2
})
console.log(iPhone5)
\\ { "name": "Apple iPhone 5", "width": 640, "height": 1136, "diagonal": 4, "ppi": 326, "dppx": 2 }console.log(devices)
// ... lists all available devices
```### Device Properties
#### `name`
Description of the device. Includes vendor and model.#### `height`
Absolute height of device screen in pixel.#### `height`
Absolute height of device screen in pixel.#### `diagonal`
Diagonal screen size in inch.#### `frame`
Distance between screen and device body in inch. (`deviceWidthInInch` - `screenWidthInInch`) / 2 = `frame`.#### `ppi`
Points per inch. [Read more](https://en.wikipedia.org/wiki/Pixel_density).#### `dppx`
Scaling factor. Sometimes also called "retina".