# stylenames

> Improves usage of html inline styles in javascript.

Latest version **1.1.6** (published 2016-11-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install stylenames
pnpm add stylenames
yarn add stylenames
bun add stylenames
```

## Health

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

Positive: has types package; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.6 |
| Published | 2016-11-19 |
| First published | 2016-09-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/stylenames) |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Kevin Mathmann |
| Maintainers | kmathmann |
| Keywords | inline-styles, styles, es6, middleware |

## Links

- npm: https://www.npmjs.com/package/stylenames
- Repository: https://github.com/kmathmann/stylenames
- Homepage: https://github.com/kmathmann/stylenames#readme
- Issues: https://github.com/kmathmann/stylenames/issues
- npm.io page: https://npm.io/package/stylenames

## Dependencies (1)

- [es6-symbol](https://npm.io/package/es6-symbol.md) ^3.1.0

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.1.6 (latest) — 2016-11-19
- 1.0.7 (beta) — 2016-09-30
- 1.1.5 — 2016-10-04
- 1.1.4 — 2016-10-04
- 1.1.3 — 2016-10-04
- 1.1.2 — 2016-10-04
- 1.1.1 — 2016-10-04
- 1.1.0 — 2016-10-04
- 1.0.6 — 2016-09-30
- 1.0.5 — 2016-09-30
- 1.0.4 — 2016-09-30
- 1.0.3 — 2016-09-30
- 1.0.2 — 2016-09-30
- 1.0.1 — 2016-09-30
- 1.0.0 — 2016-09-30

## README

##StyleNames

####What does StyleNames?
  In one short sentence: "StyleNames converts an object to a css style string."

####Install
```
npm install stylenames -D
```
####Import
 ```javascript
 import styleNames from 'stylenames';
 ```


####StyleNames object - StyleGuide
```javascript
    styleNames({
        'style-key':'style-value',
        
        // If the condition is false the style does not becomes used.
        'style-key':{
            'style-value': condition
        },
                    
        // Only the first value with true condition becomes used.
        'style-key':{
            'style-value1': condition,
            'style-value2': condition,
            'style-value3': condition,
             ...
        }
    });
```
###Examples:

#####Without conditions:
  ```javascript
    let styles1 = styleNames({
        height: '120px',
        width: '100px'
    });
    console.log(styles1); //--> ' height:120px;width:100px; '
  ```
       
#####With one condition
  ```javascript
    let styles1 = styleNames({
        height: '120px',
        width: {
            '200px': false
        }
    });
    console.log(styles1); //--> ' height:120px '
   
    let styles2 = styleNames({
        height: '120px',
        width: {
            '200px': true
        }
    });
    console.log(styles2); //--> ' height:120px;width:200px; '
   ```
#####With more than one condition

```javascript
    let itemCount = 0;
 
    let styleNamesConfig = {
        display: {
            'none': () => itemCount === 0
        },
        height: '120px',
        width: {
            '100px': () => itemCount <= 1,
            '200px': () => itemCount <= 2,
            '400px': () => itemCount <= 4,
            '100%': () => itemCount > 4
        }
    };
 
    console.log(styleNames(styleNamesConfig)); //--> ' display:none;height:120px;width:100px; '
 
    itemCount++; //1
    console.log(styleNames(styleNamesConfig)); //--> ' height:120px;width:100px; '
 
    itemCount++; //2
    console.log(styleNames(styleNamesConfig)); //--> ' height:120px;width:200px; '
 
    itemCount++; //3
    console.log(styleNames(styleNamesConfig)); //--> ' height:120px;width:400px; '
 
    itemCount += 12; //15
    console.log(styleNames(styleNamesConfig)); //--> ' height:120px;width:100%; '

```

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