# to-style

> Convert style objects to style strings

Latest version **1.3.3** (published 2015-01-22) · MIT license · 0 weekly downloads

## Install

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

## 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.3.3 |
| Published | 2015-01-22 |
| First published | 2014-08-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Author | Radu Brehar |
| Maintainers | radubrehar |
| Keywords | style, css, object, conver, style, to, string |

## Links

- npm: https://www.npmjs.com/package/to-style
- Repository: https://github.com/radubrehar/toStyle
- Issues: https://github.com/radubrehar/toStyle/issues
- npm.io page: https://npm.io/package/to-style

## 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.3.3 (latest) — 2015-01-22
- 1.3.2 — 2015-01-22
- 1.3.1 — 2014-10-02
- 1.3.0 — 2014-09-30
- 1.2.0 — 2014-09-23
- 1.1.0 — 2014-09-04
- 1.0.2 — 2014-08-06
- 1.0.1 — 2014-08-06
- 1.0.0 — 2014-08-06

## README

toStyle
=======

Converts style objects to strings. Can be used on node or in the browser.

## Install

```npm install to-style```

## Usage

```js
var toStyleString = require('to-style').string
var toStyleObject = require('to-style').object
```

### toStyleString

```js
toStyleString({
    border: {
        width: 1,
        color: 'red'
    },
    padding: 4,
    margin: {
        top: 5
    }
}) == 'border-width: 1px; border-color: red; padding: 4px; margin-top: 5px;'
```

### toStyleObject
```js

toStyleObject({
    padding: {
        top: 3,
        bottom: 2
    },
    border: '1px solid red',
    margin: 4
}) // =>
/*
{
    'padding-top': '3px',
    'padding-bottom': '2px',
    'border': '1px solid red',
    'margin': '4px'
}
 */
```

You can also get your styles in camel-case, just pass a config object as a second argument to ```toStyleObject```, with ```camelize: true```

Example:

```js
toStyleObject({
    padding: {
        top: 10
    },
    'border-width': 20
}, { camelize: true})

/**
 *  {
 *      paddingTop: '10px',
 *      borderWidth: '20px'
 *  }
 */
```

## Usage in browser

In browser, make sure you add ```dist/toStyle.js``` to your page. This exposes a global ```toStyle``` variable.

```js
var toStyleString = toStyle.string
var toStyleObject = toStyle.object

```

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