npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

query-device

v0.5.0

Published

Handler hight-level for mediaMatch API

Downloads

38

Readme

query-device

codecov

Node.js CI

You have need dynamic responsive for your app, css cant full coverage, now you can use a handler of viewport device, easy usage.

CDN usage

Learn more with CDN usage

Script tag

<script src="https://orivoir.github.io/query-device/dist/query-device.js"></script>

installation

you should local install with your handler dependencies fovorite

install with npm

$ npm install query-device --save

install with yarn

$ yarn add query-device

import

Babel

Babel is a next generation JavaScript compiler. One of the features is the ability to use ES6/ES2015 modules now, even though browsers do not yet support this feature natively.

import QueryDevice from 'query-device';

const queryDevice = new QueryDevice();

Browserify/Webpack

There are several ways to use Browserify and Webpack. For more information on using these tools, please refer to the corresponding project's documentation.

const QueryDevice = require('query-device');

const queryDevice = new QueryDevice();

usage

You can add viewport listeners with multiple choices


queryDevice.add( "min-width: 416px AND min-height: 640px", function( isMatches ) {

    // the viewport have change

    if( isMatches ) {

        console.log('viewport have not mobile size');

    } else {

        console.log('viewport have mobile size');

    }

} );

easy query device

you can simply your query devices with this below notation


queryDevice.add( "416x640", function( isMatches ) {

    // the viewport have change

    if( isMatches ) {

        console.log('view port left mobile size');

    } else {

        console.log('view port enter mobile size');
    }

} );

this is equal to previous query device, and you can access to a list devices, with dimension already save, and give a device object as argument to your query devices.

devices list

You can access to devices list with static attribute: deviceList

console.log( QueryDevice.deviceList );

should be output:

[
    {
        "name": "iPhone XR", "size": "414x896"
    },
    {
        "name": "iPhone XS", "size":"375x812"
    },
    {
        "name": "iPhone XS Max", "size":"414x896"
    },
    {
        "name": "iPhone X", "size":"375x812"
    },
    {
        "name": "iPhone 8 Plus", "size":"414x736"
    },
    {
        "name":"iPhone 8", "size":"375x667"
    },
    // ...
]

device object as query device

you can target a device with the device name with the static method: findDeviceByName

?object QueryDevice.findDeviceByName( string deviceName )

import QueryDevice from 'query-device';

const iPhoneXrDevice = QueryDevice.findDeviceByName("iPhone XR");

const queryDevice = new QueryDevice();

queryDevice.add( iPhoneXrDevice, function( isMatches ) {

    // the viewport have change

    if( isMatches ) {

        console.log('viewport have not iPhone XR size');

    } else {

        console.log('viewport have iPhone XR size');
    }

} );

remove a query device

If during the lifecycle of your app you have need detach a query device you can use the third argument of add method who is identifiant of query device as string


const idQueryDevice = "mobile-device";

queryDevice.add( "416x640", function( isMatches ) {

    // the viewport have change

    if( isMatches ) {

        console.log('view port left mobile size');

    } else {

        console.log('view port enter mobile size');
    }

}, idQueryDevice );

Then you can any time use remove method for detach the query device.


queryDevice.remove( idQueryDevice );

And now you query device for "mobile-device" is detach with success 👍.

With a device object as query device the default identifiant is the name of device

details of query device

global event

The QueryDevice attach only one listener of window resize for all query devices, your query device is add to a array mediaEvents and the global listener execute all query devices inside this array, during remove of one query device the array mediaEvents remove your query device and during next event resize your query is not execute. This behavior is favorite for events optimzation reason if you have detach all query devices the global event is detached and if you re attach any query devices this is re attached.

callback query devices

The callback for your query device is execute only if viewport change with your constraints.

E.g: in assumed you attach this bellow query device


queryDevice.add( "416x640", function( isMatches ) {

    // the viewport have change

    if( isMatches ) {

        console.log('view port left mobile size');

    } else {

        console.log('view port enter mobile size');
    }

} );

If the viewport switch from: 1200x960 to: 580x700 your callback is not execute because you ask a query device for: 416x640 this equal to: min-width: 416px AND min-height: 640px

But if viewport switch from: 580x700 to: 380x580 you callback is execute because new viewport have not respect you constraint query device and the argument isMatches is false