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

mquerylist

v1.0.2

Published

[![Build Status](https://travis-ci.org/vejersele/MQueryList.svg?branch=master)](https://travis-ci.org/vejersele/MQueryList) [![Coverage Status](https://coveralls.io/repos/vejersele/MQueryList/badge.svg)](https://coveralls.io/r/vejersele/MQueryList)

Readme

MQueryList && MQuery

Build Status Coverage Status

The MQueryList provides you with a more convenient API to interact with media queries in Javascript. This package exists out of two Classes:

  • MQuery
  • MQueryList

The MQuery class represents a single media query. You can choose whether you want to use the MQuery class on it's own and create a separate instance per query or you can create instances through a more higher level API which is provided by the MQueryList.

The MQueryList provides you with the possiblilty to create multiple MQuery instances and store them in a single object (MQueryList instance). This way you can use one object throughout your app to listen for media query changes.

Please note that this project isn't a window.matchMedia() polyfill. It is build upon window.matchMedia() and you will need to include a polyfill to make it work in browsers that don't support window.matchMedia(). Paul Irish did a great job writing one, you can find it at https://github.com/paulirish/matchMedia.js/

Setup

You can install this package through npm and bower or just download it from github. The package implements the UMD API so it is usable within CommonJS and AMD environments. It also exposes globals so you can use it by including script tags directly in your html code.

npm install mquerylist --save
bower install mquerylist --save

CommonJS

First install the package with NPM


// MQueryList class
var MQueryList = require('mquerylist').MQueryList;

// MQuery class
var MQuery = require('mquerylist').MQuery;

AMD

This snippet assumes that the package is installed with bower and that you've set the basePath to the bower_components directory.


require(['mquerylist/lib/MQueryList'], function (MQueryList) {
	var myList = new MQueryList();
});

require(['mquerylist/lib/MQuery'], function (MQuery) {
	var myQuery = new MQuery('(min-width: 300px)');
});

require(['mquerylist/index'], function (mQueryList) {
	var myQuery = new mQueryList.MQuery('(min-width: 300px)');
	var myList = new mQueryList.MQueryList();
});

Globals

The snippet below assumes that you've installed the package with bower


<!-- dependencies -->
<script src="bower_components/heir/heir.js"></script>
<script src="bower_components/eventEmitter/EventEmitter.js"></script>

<!-- mquerylist scripts -->
<script src="bower_components/mquerylist/lib/MQuery.js"></script>
<script src="bower_components/mquerylist/lib/MQueryList.js"></script>

<script>
	var myQuery = new MQuery('(min-width: 300px)');
	var myList = new MQueryList();
</script>

API

MQuery

var myQuery = new MQuery('only screen and (max-width: 480px)');

myQuery.on('init', function () {
	console.log('This is a small screen ...');
});

myQuery.on('destroy', function () {
	console.log('This is a bigger screen ...');
});

myQuery.watch();

The watch() method will start listening for changes on the media query object. It will make sure events are triggered on the MQuery instance when the query has matches or doesn't has matches anymore.

It's important to know that you can also manually activate an MQuery instance. This can be usefull in situations where you know media queries aren't supported, for example in IE8. In many cases you will just serve a desktop css file to IE8 and you also want to make sure the corresponding scripts are correctly initialised. The only thing you need to do is call the init() method on the MQuery instance to let your application know your showing the desktop view.

var myQuery = new MQuery('only screen and (max-width: 480px)');

myQuery.on('init', function () {
	console.log('This is a small screen ...');
});

myQuery.on('destroy', function () {
	console.log('This is a bigger screen ...');
});

myQuery.init();

MQueryList

var myList = new MQueryList();

myList.register('mobileAndDown', 'only screen and (max-width: 480px)');
myList.register('tabletAndUp', 'only screen and (min-width: 481px)');

myList.on('init.mobileAndDown', function () {
	console.log('Do stuff for mobile ...');
});

myList.on('init.tabletAndUp', function () {
	console.log('Do stuff for tablet ...');
});

myList.on('destroy.mobileAndDown', function () {
	console.log('Stop doing stuff for mobile ...');
});

myList.on('destroy.tabletAndUp', function () {
	console.log('Stop doing stuff for tablet ...');
});

myList.watch();

It's possible to retrieve an MQuery instance from an MQueryList instance by using the get method

var myQuery = myList.get('mobileAndDown');