# css-to-cssinjs

> convert css to a css-in-js format compatible with aphrodite

Latest version **1.3.7** (published 2021-04-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install css-to-cssinjs
pnpm add css-to-cssinjs
yarn add css-to-cssinjs
bun add css-to-cssinjs
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.7 |
| Published | 2021-04-03 |
| First published | 2018-03-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 6.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | rnsloan rnsloan1@gmail.com |
| Maintainers | rnsloan |

## Links

- npm: https://www.npmjs.com/package/css-to-cssinjs
- Homepage: https://github.com/rnsloan/css-to-cssinjs
- npm.io page: https://npm.io/package/css-to-cssinjs

## Dependencies (2)

- [css](https://npm.io/package/css.md) ^2.2.4
- [stringify-object](https://npm.io/package/stringify-object.md) ^3.3.0

## Recent versions

- 1.3.7 (latest) — 2021-04-03
- 1.3.6 — 2020-06-10
- 1.3.5 — 2019-12-11
- 1.3.4 — 2019-07-14
- 1.3.2 — 2018-03-12
- 1.3.1 — 2018-03-07
- 1.3.0 — 2018-03-07
- 1.0.0 — 2018-03-07

## README

# css-to-cssinjs

Converts a css string to a css-in-js format JavaScript object compatible with [https://github.com/Khan/aphrodite](https://github.com/Khan/aphrodite).

See a browser version here: [https://rnsloan.github.io/css-to-cssinjs/](https://rnsloan.github.io/css-to-cssinjs/)

## Usage

`npm install css-to-cssinjs`

```
import { convertCSS } from 'css-to-cssinjs';
// const convertCSS = require('css-to-cssinjs').convertCSS;

convertCSS(`
    #primary {
        color: red
    }
    #secondary {
        width: 300px
    }
    .tertiary {
        border: 1px solid red
    }
`)
```

Returns:

```
'{
  primary: { color: "red" },
  secondary: { width: "300px" },
  tertiary: { border: "1px solid red" }
}'
```

### API

`convertCSS(cssInput[, options]) => cssInJs`

Arguments

1.  `cssInput` (`String`): a string of css
2.  `options` (`Object` [optional]):
    * `options.format` (`String` [optional]): the outputted format. Values `string` | `object` | `JSON`. Default to `string`.
    * `options.convertAnimations` (`Boolean` [optional]): parse keyframe animations. Default to `false`.

## Limitations

Is unable to generate the correct output for global pseudo selectors such as:

```
::-webkit-file-upload-button {
    -webkit-appearance: button;
    font: inherit;
}
```

By default does not parse animations. Looking at the output from a single CSS animation with two keyframes:

```
{
	"0%": {
		width: 200px;
	},
	"100%": {
		width: 800px;
	}
}
```

If any other animation uses the same keyframe values they will be merged together:


```
{
	"0%": {
		width: 200px;
		color: red;
	},
	"50%": {	
		color: orange;
	},
	"100%": {
		width: 800px;
		color: green;
	}
}
```

Animation conversion can be enabled via the `options` parameter.

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