# media-breakpoints-watcher

> Library for easy use of media breakpoints in js

Latest version **1.0.4** (published 2017-10-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install media-breakpoints-watcher
pnpm add media-breakpoints-watcher
yarn add media-breakpoints-watcher
bun add media-breakpoints-watcher
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2017-10-29 |
| First published | 2017-10-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Dmitry Malakhov |
| Maintainers | dmalakhov |
| Keywords | media-queries, css-in-js, breakpoints |

## Links

- npm: https://www.npmjs.com/package/media-breakpoints-watcher
- Repository: https://github.com/dmitrymalakhov/media-breakpoints-watcher
- Homepage: https://github.com/dmitrymalakhov/media-breakpoints-watcher#readme
- Issues: https://github.com/dmitrymalakhov/media-breakpoints-watcher/issues
- npm.io page: https://npm.io/package/media-breakpoints-watcher

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2017-10-29
- 1.0.3 — 2017-10-28
- 1.0.2 — 2017-10-28
- 1.0.1 — 2017-10-28
- 1.0.0 — 2017-10-28

## README

# media-breakpoints-watcher

Library for easy use of media breakpoints in js

## Install

```bash
yarn add media-breakpoints-watcher
```

or

```bash
npm install media-breakpoints-watcher
```

## Usage

```javascript
import {
  initBreakpoints,
  getBreakpointsBroadcast,
  getBreakpointsEmitter,
  getCurrentBreakpoint,
} from 'media-breakpoints-watcher';

initBreakpoints({
  large: '(min-width: 1200px)',
  medium: '(min-width: 992px)',
  small: '(min-width: 768px)',
});

const breakpointsBroadcast = getBreakpointsBroadcast();
const breakpointsEmitter = getBreakpointsEmitter();

// don't forget to add throttle to handler of resize 
const handleResize = breakpoint => console.log(breakpoint);

breakpointsBroadcast.subscribe(handleResize);

breakpointsEmitter.subscribe('change', handleResize);
breakpointsEmitter.subscribe('small', handleResize);

console.log(
  'Current breakpoint according to init breakpoints',
  getCurrentBreakpoint()
);

console.log(
  'Current breakpoint according to custom breakpoints',
  getCurrentBreakpoint({
    medium: '(min-width: 992px)',
    small: '(min-width: 768px)',
  })
);
```

For unsubscribe

```javascript
const unsubscribe = breakpointsBroadcast.subscribe(handleResize);
unsubscribe();

/../

breakpointsEmitter.subscribe('change', handleResize);
breakpointsEmitter.unsubscribe('change', handleResize);
```

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