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

watch-css-media

v0.1.2

Published

Provides an Observable stream that updates whenever the browser crosses a media-query threshold

Downloads

50

Readme

watch-css-media

Provides an easy way to provide callbacks for when the browser crosses the threshold of a media query. Uses the Observable API to allow for composable event streams

getting the code

install from npm: npm install watch-css-media

use in your project:

import {WatchCSSMedia} from 'watch-css-media'; Or var WatchCSSMedia = require('watch-css-media');

running the tests

Install the dependencies using npm install

Run the tests using npm test

Transpile to ES5 using npm run build

Build the docs using npm run doc

Generate the docs for the readme with npm run build-readme

API Reference

WatchCSSMedia

watchCSSMedia.addQuery(query, callback, [transform]) ⇒ Observable

General function to create a media query listener from a specified media query

Kind: instance method of WatchCSSMedia
Returns: Observable - An Observable event stream created from the MediaQueryList listener

| Param | Type | Description | | --- | --- | --- | | query | string | a media query, which will be watched | | callback | function | a function to call when the media query boundary is changed Unless a transform function is provided, the callback function will be invoked with an object containing the following keys: matches: boolean. whether (true) or not (false) the browser matches the specified query query: string. the original media query string originalEvent: Event. the original event that triggered the callback `event$: Observable. An Observable event stream created from the MediaQueryList listener | | [transform] | function | an optional function to map the mql event object to the parameter passed into the callback |

watchCSSMedia.addQueries(args) ⇒ Array.<Observable>

Shortcut method to add multiple listeners. Each element in the arguments array corresponds to the parameters of addQuery

Kind: instance method of WatchCSSMedia
Returns: Array.<Observable> - An Array of Observable event streams created from the MediaQueryList listeners

| Param | Type | Description | | --- | --- | --- | | args | Array | an array of {query, callback, transform} objects |

watchCSSMedia.onOrientationChange(callback) ⇒ Observable

Shortcut method to add an event listener for orientation changes

Kind: instance method of WatchCSSMedia
Returns: Observable - An Observable event stream created from the MediaQueryList listener

| Param | Type | Description | | --- | --- | --- | | callback | function | a callback function to execute when the orientation changes The callback function will be invoked with an object containing the following keys: isLandscape: boolean. whether (true) or not (false) the device is now in landscape orientation isPortrait: boolean. whether (true) or not (false) the device is now in portrait orientation query: string. the original media query string originalEvent: Event. the original event that triggered the callback `event$: Observable. An Observable event stream created from the MediaQueryList listener |

watchCSSMedia.onWidthGreaterThan(min, callback, [transform]) ⇒ Observable

Shortcut method to add an event listener for browser width changes. This allows for easy creation of callbacks that fire when the browser crosses certain width thresholds without having to use window.on('resize');

Kind: instance method of WatchCSSMedia
Returns: Observable - An Observable event stream created from the MediaQueryList listener

| Param | Type | Description | | --- | --- | --- | | min | string | a string representing the minimum width, including units (e.g. '500px') | | callback | function | a callback function to execute when the browser width crosses the threshold Unless a transform function is provided, the callback function will be invoked with an object containing the following keys: matches: boolean. whether (true) or not (false) the browser is wider than the provided width query: string. the original media query string originalEvent: Event. the original event that triggered the callback `event$: Observable. An Observable event stream created from the MediaQueryList listener | | [transform] | function | an optional function to map the mql event object to the parameter passed into the callback |

watchCSSMedia.onWidthLessThan(min, callback, [transform]) ⇒ Observable

Shortcut method to add an event listener for browser width changes. This allows for easy creation of callbacks that fire when the browser crosses certain width thresholds without having to use window.on('resize');

Kind: instance method of WatchCSSMedia
Returns: Observable - An Observable event stream created from the MediaQueryList listener

| Param | Type | Description | | --- | --- | --- | | min | string | a string representing the maximum width, including units (e.g. '500px') | | callback | function | a callback function to execute when the browser width crosses the threshold Unless a transform function is provided, the callback function will be invoked with an object containing the following keys: matches: boolean. whether (true) or not (false) the browser is narrower than the provided width query: string. the original media query string originalEvent: Event. the original event that triggered the callback `event$: Observable. An Observable event stream created from the MediaQueryList listener | | [transform] | function | an optional function to map the mql event object to the parameter passed into the callback |