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

@dfwood/js-mq

v1.1.0

Published

A JS helper library to detect screen size by named breakpoints. Based off of the `sass-mq` library.

Downloads

2

Readme

@dfwood/js-mq

A JS helper library to detect screen size by named breakpoints. Based off of the sass-mq library.

Quick start guide

This documentation assumes you are familiar with and using the ES6 JavaScript syntax in your project.

All breakpoint definitions use the mobile first approach. In this methodology, the pixel size for a breakpoint is the smallest width on the breakpoint. The largest width on the breakpoint is 1px less than the next breakpoint size.

Install js-mq using npm: npm install @dfwood/js-mq --save

For ease of use in your project, it is recommended to setup an intermediate loader. This will allow you to define all your breakpoints for your project once, regardless of the number of places you need access to them.

///////////////////
// "mq.js" file //
/////////////////

import MQ from '@dfwood/js-mq';

const bp = {
    // Values should always be pixel amounts in integer format. No units.
    // Value is the smallest pixel size on the breakpoint (inclusive).
    small: 480,
    medium: 768,
    large: 1024,
};

const mq = new MQ(bp);

export default mq;

// Give easy access to site breakpoints and the js-mq object with breakpoints already defined.
export {mq, bp};

Now you can easily import the mq variable into any of your projects JavaScript files.

//////////////////////
// Project JS file //
////////////////////

// Import from file created in setup stage
import mq from '../mq';

// Alternatively import both the mq variable and the website breakpoints
// (Use one line or the other, do not use both import statements)
import {mq, bp} from '../mq';

// Use in an if statement
if (mq.from('small')) {
    // Do stuff for screens equal to or larger than the "small" breakpoint screen width.
}

if (mq.until('medium')) {
    // Do stuff for screens smaller than the "medium" breakpoint screen width.
}

if (mq.on('small', 'large')) {
    // Do stuff for screens equal to or larger than the "small" breakpoint screen width AND smaller than the "large" breakpoint screen width.
    // i.e. This applies to the entirety of the "small" and "medium" breakpoints.
}

// You can also pass in a pixel value if needed (as an integer).
if (mq.from(1000)) {
    // Do stuff for screens equal to or larger than 1000px in width.
}

Methods

  • mq.from() - Returns true if screen size is greater than or equal to specified pixel value/breakpoint.
  • mq.until() - Returns true if screen size is less than specified pixel value/breakpoint.
  • mq.on() - Takes 2 arguments, Returns true if screen size is greater than or equal to first argument value/breakpoint AND screen size is less than second argument value/breakpoint.

Changelog

1.1.0

  • Refactored code to improve browser support (namely IE11).