# style-guard

> Use proxies in dev to guard against potentially missing styles

Latest version **0.1.1** (published 2021-01-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install style-guard
pnpm add style-guard
yarn add style-guard
bun add style-guard
```

## 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.1 |
| Published | 2021-01-08 |
| First published | 2020-01-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | David Wells |
| Maintainers | davidwells |

## Links

- npm: https://www.npmjs.com/package/style-guard
- npm.io page: https://npm.io/package/style-guard

## Recent versions

- 0.1.1 (latest) — 2021-01-08
- 0.0.5 — 2021-01-03
- 0.0.4 — 2020-01-18
- 0.0.3 — 2020-01-18
- 0.0.2 — 2020-01-18
- 0.0.1 — 2020-01-18

## README

# Style Guard for CSS modules

Use proxies in dev to guard against potentially missing styles for CSS modules.

Inspired from this [gist](https://gist.github.com/DavidWells/04e632a55b11c0ca53e9a8f41524d158)

Automatically guard styles with the [babel-plugin-style-guard](https://www.npmjs.com/package/babel-plugin-style-guard)

Example:

```css
/* styles.css */
.thing {
  color: blue;
}
```

React component with `styles.doesNotExist` reference to undefined value.

```js
import React from 'react'
import styleGuard from 'style-guard'
import css from './styles.css'
// css is CSS module object

const styles = styleGuard(css)
// styles is now proxied object in dev to throw if unknown properties are called

export default function NavBar(props) {
  const { auth, handleLogout } = props
  return (
    <div className={styles.thing}>
      <span className={styles.doesNotExist}>
        xyz
      </span>
    </div>
  )
}

/*
  styles.doesNotExist will cause a dev error because its missing or has been removed!
*/
```

Resulting in an error like so:

![image](https://user-images.githubusercontent.com/532272/103469934-54af5100-4d20-11eb-99d8-144a1065cf14.png)

This will help prevent style regressions in dev mode

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