web-device-info
v1.2.0
Published
Find out execution device info, e.g. if executing device has DOM available, or is mobile, tablet or desktop device. Customizable using environment variables.
Downloads
4
Readme
web-device-info
Find out execution device info, e.g. if executing device has DOM available, or is mobile, tablet or desktop device. Customizable using environment variables.
If using yarn:
yarn add web-device-info
If using npm:
npm install web-device-info
To use in code:
- canUseDOM is a variable which is true if execution device has DOM available.
Declare import { canUseDOM } from 'web-device-info'
Then in code:
if ( canUseDOM ) {}
- isMobileScreenSize() is a function which takes optional isMobileScreenSize check breakpoint. It tells whether execution device current window size is in mobile view range or not.
Declare import { isMobileScreenSize, isTabletScreenSize, isDesktopScreenSize } from 'web-device-info'
Then in code:
if ( isMobileScreenSize(768) ) {}
- isMobile is a variable which returns if execution device is mobile or not.
Declare import { isMobile, isIOS, isMac, isWindows, isLinux } from 'web-device-info'
Then in code:
if ( isMobile ) {}
May support ES5 environment also.
Default device check conditions:
- Mobile
< 768px
>= 768px
Tablet<= 1024px
> 1024px
Desktop<= 1200px
> 1200px
Large desktop> 1440px
Extra large desktop
Customization of default using environment variables (e.g. can be set in .env files in React)
RESPONSIVE_STRATEGY = 'mobile_first'
Default value = 'desktop_first' Possible values are 'mobile_first', 'desktop_first' or 'table_first'LARGE_DESKTOP_BREAKPOINT = 1440
DESKTOP_BREAKPOINT = 1200
TABLET_BREAKPOINT = 1024
MOBILE_BREAKPOINT = 768
Editor Configuration
- Editor of your preference. I used some VSCode specific config in .vscode folder and recommend plugins for enhanced experience.
Recommended VSCode Extensions:
- Prettier (Official) - Code formatter
- ESLint (Official) - Real time JS syntax validation
Technologies Used
- Rollup.js
- Typescript + ESM
- Yarn
- Prettier + ESlint
- Jest lint setup, jest can be added
- Built on boilerplate https://github.com/n10l/ts-lib-boilerplate
Available Scripts [For development]
In the project directory, you can run:
yarn build
To build the project
yarn watch
To build with livereload
yarn fix:all
Runs prettier formatter followed by eslint, to format code and fix lint issues. Prettier is not good enough to run alone, must always be followed lint fixes included in this command.