1.1.0 • Published 3 years ago

browser-device-features v1.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

browser-device-features

Detect features and capabilities of a browser.

browser-device-features detects several features of a browser, including:

  • Does the device have a touch screen?
  • Does the device have pointer?
  • Does the pointer has a coarse or fine tip?
  • Does the user prefer light or dark mode?
  • Is the device in portrait or landscape mode?
  • What is the window's current size?
  • What is the device's screen size?
  • Has the user touched anything?
  • Has the user moved a mouse?
  • Has the user moved a pointer?

Demo

Live demo is avaible at devtools.terrymorse.com.

Install

  npm install browser-device-features

Usage

<script src="bd-features.js"></script>
<script>
    let touchDevice = BdFeatures.hasTouch();
    /* --- */
    let pointed = BdFeatures.userHasPointed();
</script>

Or simply use the CDN:

<script
  src="https://cdn.jsdelivr.net/npm/browser-device-features/bd-features.js">
</script>

Functions

Function NameReturnsDescription
browserSupportedbooleanbrowser-device-features supports this browser
hasTouchbooleantouch is possible
canHoverbooleanhover is possible
hasPointerbooleanpointing device exists
finePointerbooleanpointer has fine point (mouse, trackpad, stylus)
coarsePointerbooleanpointer has coarse point (touch screen)
wantsLightbooleanuser prefers light mode
wantsDarkbooleanuser prefers dark mode
noLightDarkPreferencebooleanno user light-dark preference
isPortraitbooleandisplay is in portrait orientation
isLandscapebooleandisplay is in landscape orientation
windowSizestring(see below)
screenHeightnumberheight of the device screen
screenWidthnumberwidth of the device screen
touchedbooleanuser has used touch
mousedbooleanuser has moved mouse
pointedbooleanuser has moved pointer

Constants returned by windowSize()

windowSize() returns sizes matching the Bootstrap window sizes. The following constants define the sizes:

ConstantMeaning
BdFeatures.WINDOW_XSextra-small screen (width < 576px)
BdFeatures.WINDOW_SMALLsmall screen (576 ≤ width < 768px)
BdFeatures.WINDOW_MEDIUMmedium screen (768 ≤ width < 992px)
BdFeatures.WINDOW_LARGElarge screen (992 ≤ width < 1200px)
BdFeatures.WINDOW_XLextra- large screen (width ≥ 1200px)

Browser Compatibility

browser-device-features is compatible with the following browsers:

BrowserCompatible Version
IE(none)
Edge12+ (2015)
Firefox64+ (2018)
Chrome41+ (2015)
Safari9+ (2015)
Opera28+ (2015)
iOS Safari9+ (2015)
Android Browser80+ (2020)
Opera Mobile46+ (2016)
Chrome for Android80+

Functions that are not compatible with the browser will return null.

A current list of compatible browsers is maintained at caniuse.com.

MIT License

Copyright (c) 2020 Terry Morse

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

1.1.0

3 years ago

1.0.8

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago