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

simple-breakpoints

v1.1.3

Published

A simple js plugin to define conditionally check defined breakpoints

Downloads

712

Readme

Simple Breakpoints

npm npm

A simple breakpoints plugin based off of four simple breakpoint sizes ('mobile', 'tablet', 'small_desktop', 'large_desktop') with support to listen for breakpoint change events

Installation and usage

$ npm install simple-breakpoints --save
    import SimpleBreakpoints from 'simple-breakpoints'

    // default breakpoint sizes: { mobile: 480, tablet: 640, small_desktop: 1024, large_desktop: 1180 }
    var breakpoints = new SimpleBreakpoints();

    if(breakpoints.isMobile()) {
        // do something for mobile
    }

    if(breakpoints.isSmallDesktop()) {
        // do something for small desktop
    }

    if(breakpoints.isBetween('small_desktop', 'large_desktop')) {
        // do something between small and large desktop
    }

Listening to events

    // on all breakpoint changes
    breakpoints.on('breakpointChange', (from, to) => {
        console.log(`change from ${from} to ${to}`);
        // change from small_desktop to large_desktop
        // change from tablet to mobile
    });

    // on breakpoint changes from small to large
    breakpoints.on('breakpointChangeUp', (from, to) => {
        console.log(`change Up from ${from} to ${to}`);
        // change from small_desktop to large_desktop
    });

    // on breakpoint changes from large to small
    breakpoints.on('breakpointChangeDown', (from, to) => {
        console.log(`change Down from ${from} to ${to}`);
        // change from large_desktop to small_desktop
    });

    // remove all events from `breakpointChangeDown`
    breakpoints.off('breakpointChangeDown');

    // fire an event only once
    breakpoints.once('breakpointChange', (from, to) => {
        console.log(`firing an event ${from} to ${to} only once`);
        // change from large_desktop to small_desktop
    });

Defining your own breakpoints

    import SimpleBreakpoints from 'simple-breakpoints'

    var breakpoints = new SimpleBreakpoints({
        mobile        : 320,
        tablet        : 640,
        small_desktop : 900,
        large_desktop : 1200
    });

API

Function | Params | Description ------ | -------- | ----------- getViewportSize | | returns the viewport size as object { width: 1024, height: 768 } this is fired on window.resize and is stored in breakpoints.viewport currentBreakpoint | | returns current breakpoint size ('mobile', 'tablet', 'small_desktop', 'large_desktop') isBetween | smallBreakpoint, largeBreakpoint ('mobile', 'tablet', 'small_desktop', 'large_desktop') | Check if viewport is between two breakpoints isLessThan | breakpoint ('mobile', 'tablet', 'small_desktop', 'large_desktop') | Check if viewport is less than the width of the breakpoint isGreaterThan | breakpoint ('mobile', 'tablet', 'small_desktop', 'large_desktop') | Check if viewport is greater than the width of the breakpoint isLessThanEqualTo | breakpoint ('mobile', 'tablet', 'small_desktop', 'large_desktop') | Check if viewport is less than or equal the width of the breakpoint isGreaterThanEqualTo | breakpoint ('mobile', 'tablet', 'small_desktop', 'large_desktop') | Check if viewport is greater than or equal the width of the breakpoint isMobile | | Check if the viewport is within the mobile breakpoint isTablet | | Check if the viewport is within the tablet breakpoint isSmallDesktop | | Check if the viewport is within the small_desktop breakpoint isLargeDesktop | | Check if the viewport is within the large_desktop breakpoint on (event, callback) | ('breakpointChange' | 'breakpointChangeUp' | 'breakpointChangeDown', callback(from, to)) | watch for changes on breakpoints with and fire a callback once (event, callback) | ('breakpointChange' | 'breakpointChangeUp' | 'breakpointChangeDown', callback(from, to)) | watch for changes on breakpoints with and fire a callback only once off (event) | ('breakpointChange' | 'breakpointChangeUp' | 'breakpointChangeDown')| Remove event listener for breakpoint change

For using with Vue.js, see vue-simple-breakpoints