res

Device resolution detection module

npm install res
9 downloads in the last week
18 downloads in the last month

res

res is a cross-browser device resolution detection module. It uses window.devicePixelRatio where available and otherwise uses fallback techniques.

$ npm install res

API

Methods

@return number|boolean

  • res.dpi(min?) - Get or test resolution in dpi units.
  • res.dpcm(min?) - Get or test resolution in dpcm units.
  • res.dppx(min?) - Get or test resolution in dppx units a.k.a. device-pixel-ratio.

Usage

Examples

Device res.ddpx() res.dpi() res.dpcm()
desktop 1 96 37.79527559055118
iPhone 4s 2 192 75.59055118110236

Conditionals

if (res.dpi(120)) {
    // Resolution is 120dpi+
} else {
    // Resolution is <120dpi
}

Developers

Contribute

Make edits in the /src dir.

$ npm install
$ grunt jshint:src

Compatibility

Methods return 0|false where undetectable. Expect accurate results in:

  • Webkit (Chrome/Safari/Android)
  • Firefox 6+
  • Opera 11.1+ (Presto 2.8+)
  • IE 6+

MIT License

Copyright (C) 2013 by Ryan Van Etten

npm loves you