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 🙏

© 2024 – Pkg Stats / Ryan Hefner

mediaquerywh

v0.0.5

Published

turns human readable breakpoints into correct mediaqueries

Downloads

689

Readme

NB: This is a fork of https://gitter.im/axyz/mediaquery and extended with the option of passing media query direction (width, height, default width).

mediaquery

Turns human readable breakpoints into correct mediaqueries.

This is particularly useful when working with window.matchMedia or when you work with CSS dinamically using JavaScript.

Install

If you are using nodejs (but also browserify, webpack, etc...) you can simply use npm:

npm install mediaquery

then you can

var MQ = require('mediaquery');

By the way you if you are not using node, you may use bower

bower install mediaquery

then you can use it from window.MQ or require it using AMD

Show me the code!

Assuming you have an object to describe the mediaqueries you need such as

var myMedias = {
  small: 300,
  medium: 600,
  tablet: 'tablet media query',
  big: 1024,
  huge: Infinity
};

Note that all the numerical values (Infinity included) will be automatically sorted in the correct order, while all the strings will be considered custome media queries; every other type of values will be stripped out.

So small: 300 means that my small media query will span from 0 to 300px, while medium will be from 301px to 600px; finally huge will go from 1025px to... Infinitely large screens.

If you do not specify an Infinity breakpoint a default breakpoint will be created spanning from the biggest available breakpoint to infinity.

asObject(obj)

You can use asObject to get back a similar object where the numbers for your breakpoints are substituted with correct mediaqueries.

e.g.

var MQ = require('mediaqueries');

MQ.asObject(myMedias);

will return

{
  small: 'screen and (max-width: 300px)',
  medium: 'screen and (min-width: 301px) and (max-width: 600px)',
  big: 'screen and (min-width: 601px) and (max-width: 1024px)',
  huge: 'screen and (min-width: 1025px)',
  tablet: 'tablet media query'
}

asArray(obj)

You can also have an array of couples ['name', 'mediaquery'] in output.

e.g.

MQ.asArray(myMedias);

will return

[
  ['small', 'screen and (max-width: 300px)'],
  ['medium', 'screen and (min-width: 301px) and (max-width: 600px)'],
  ['big', 'screen and (min-width: 601px) and (max-width: 1024px)'],
  ['huge', 'screen and (min-width: 1025px)'],
  ['tablet', 'tablet media query']
]

getBreakPoints(obj)

If you need to filter out the numerical breakpoints from a mixed object you can use getBreakPoints e.g.

MQ.getBreakPoints(myMedias);

will return

{
  small: 300,
  medium: 600,
  big: 1024,
  huge: Infinity // remember that Infinity is a number
}

getCustomQueries(obj)

In the same way you may need to filter out all the custom strings e.g.

MQ.getCustomQueries(myMedias);

will return

{
  tablet: 'tablet media query'
}