# watch-css-media

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

Latest version **0.1.2** (published 2016-03-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install watch-css-media
pnpm add watch-css-media
yarn add watch-css-media
bun add watch-css-media
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2016-03-24 |
| First published | 2016-03-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Chris Bauer |
| Maintainers | chrisbauer |
| Keywords | media-query, media-queries, observable, browser, size-detection, change-detection |

## Links

- npm: https://www.npmjs.com/package/watch-css-media
- Repository: https://github.com/chrisbauer/watch-browser-size
- Homepage: https://github.com/chrisbauer/watch-browser-size#readme
- Issues: https://github.com/chrisbauer/watch-browser-size/issues
- npm.io page: https://npm.io/package/watch-css-media

## Dependencies (1)

- [rxjs-es](https://npm.io/package/rxjs-es.md) ^5.0.0-beta.2

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.1.2 (latest) — 2016-03-24
- 0.1.1 — 2016-03-24
- 0.1.0 — 2016-03-22
- 0.0.4 — 2016-03-21
- 0.0.3 — 2016-03-21
- 0.0.2 — 2016-03-18
- 0.0.1 — 2016-03-18

## 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

## <a name="module_WatchCSSMedia">WatchCSSMedia</a>

* [WatchCSSMedia](#module_WatchCSSMedia)
    * [.addQuery(query, callback, [transform])](#module_WatchCSSMedia+addQuery) ⇒ <code>Observable</code>
    * [.addQueries(args)](#module_WatchCSSMedia+addQueries) ⇒ <code>Array.&lt;Observable&gt;</code>
    * [.onOrientationChange(callback)](#module_WatchCSSMedia+onOrientationChange) ⇒ <code>Observable</code>
    * [.onWidthGreaterThan(min, callback, [transform])](#module_WatchCSSMedia+onWidthGreaterThan) ⇒ <code>Observable</code>
    * [.onWidthLessThan(min, callback, [transform])](#module_WatchCSSMedia+onWidthLessThan) ⇒ <code>Observable</code>

<a name="module_WatchCSSMedia+addQuery"></a>

### watchCSSMedia.addQuery(query, callback, [transform]) ⇒ <code>Observable</code>
General function to create a media query listener from a specified media query

**Kind**: instance method of <code>[WatchCSSMedia](#module_WatchCSSMedia)</code>  
**Returns**: <code>Observable</code> - An Observable event stream created from the MediaQueryList listener  

| Param | Type | Description |
| --- | --- | --- |
| query | <code>string</code> | a media query, which will be watched |
| callback | <code>function</code> | 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] | <code>function</code> | an optional function to map the mql event object to the        parameter passed into the callback |

<a name="module_WatchCSSMedia+addQueries"></a>

### watchCSSMedia.addQueries(args) ⇒ <code>Array.&lt;Observable&gt;</code>
Shortcut method to add multiple listeners. Each element in the arguments array corresponds to the 
parameters of [addQuery](#module_WatchCSSMedia+addQuery)

**Kind**: instance method of <code>[WatchCSSMedia](#module_WatchCSSMedia)</code>  
**Returns**: <code>Array.&lt;Observable&gt;</code> - An Array of Observable event streams created from the MediaQueryList listeners  

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

<a name="module_WatchCSSMedia+onOrientationChange"></a>

### watchCSSMedia.onOrientationChange(callback) ⇒ <code>Observable</code>
Shortcut method to add an event listener for orientation changes

**Kind**: instance method of <code>[WatchCSSMedia](#module_WatchCSSMedia)</code>  
**Returns**: <code>Observable</code> - An Observable event stream created from the MediaQueryList listener  

| Param | Type | Description |
| --- | --- | --- |
| callback | <code>function</code> | 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 |

<a name="module_WatchCSSMedia+onWidthGreaterThan"></a>

### watchCSSMedia.onWidthGreaterThan(min, callback, [transform]) ⇒ <code>Observable</code>
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 <code>[WatchCSSMedia](#module_WatchCSSMedia)</code>  
**Returns**: <code>Observable</code> - An Observable event stream created from the MediaQueryList listener  

| Param | Type | Description |
| --- | --- | --- |
| min | <code>string</code> | a string representing the minimum width, including units (e.g. '500px') |
| callback | <code>function</code> | 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] | <code>function</code> | an optional function to map the mql event object to the        parameter passed into the callback |

<a name="module_WatchCSSMedia+onWidthLessThan"></a>

### watchCSSMedia.onWidthLessThan(min, callback, [transform]) ⇒ <code>Observable</code>
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 <code>[WatchCSSMedia](#module_WatchCSSMedia)</code>  
**Returns**: <code>Observable</code> - An Observable event stream created from the MediaQueryList listener  

| Param | Type | Description |
| --- | --- | --- |
| min | <code>string</code> | a string representing the maximum width, including units (e.g. '500px') |
| callback | <code>function</code> | 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] | <code>function</code> | an optional function to map the mql event object to the        parameter passed into the callback |

---
_Source: https://npm.io/package/watch-css-media · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
