# convert-css

> Convert css strings to JSON or JS

Latest version **0.1.3** (published 2019-08-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install convert-css
pnpm add convert-css
yarn add convert-css
bun add convert-css
```

## 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.3 |
| Published | 2019-08-05 |
| First published | 2017-08-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | David Daniel, |
| Maintainers | davidedaniel |

## Links

- npm: https://www.npmjs.com/package/convert-css
- npm.io page: https://npm.io/package/convert-css

## Dependencies (2)

- [camelize](https://npm.io/package/camelize.md) ^1.0.0
- [css-parse](https://npm.io/package/css-parse.md) ^2.0.0

## Recent versions

- 0.1.3 (latest) — 2019-08-05
- 0.2.0-alpha.45961092 (canary) — 2019-10-11
- 0.1.2 — 2019-08-05
- 0.1.1 — 2017-08-05
- 0.1.0 — 2017-08-02

## README

[![Build Status](https://travis-ci.org/DavideDaniel/convert-css.svg?branch=master)](https://travis-ci.org/DavideDaniel/convert-css)

# convert-css

Parse and convert css. The focus is on JSON as it's needed for other services, and other easier conversions like modules in js for css-in-js.

### Install

`$ npm install convert-css --save`

### Usage

```javascript
const fs = require('fs');
const { cssToCamelizedJson } = require('convert-css');

const handleErr = (err) => {
  if(err) {
    console.error(err);
  }
};

fs.readFile('./my.css', 'utf-8', (err, data) => {
  handleErr(err);

  const cssText = data.toString();
  const cssInJs = 'module.exports = ' + JSON.stringify(
    cssToCamelizedJson(data), null, 2
  );

  fs.writeFile('./myCss.js', Buffer.from(cssInJs), (error) => {
    handleErr(error)
    console.log('done!')
  });
});
```

### Documentation

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

##### Table of Contents

-   [sequence](#sequence)
    -   [Parameters](#parameters)
-   [replaceCssSyntax](#replacecsssyntax)
-   [convertKey](#convertkey)
    -   [Parameters](#parameters-1)
-   [mungeRules](#mungerules)
    -   [Parameters](#parameters-2)
-   [cssToJson](#csstojson)
    -   [Parameters](#parameters-3)
-   [cssToCamelizedJson](#csstocamelizedjson)
    -   [Parameters](#parameters-4)

#### sequence

[sequence takes in functions and calls them in sequence, same as pipe]

##### Parameters

-   `args` **\[Functions]** [n number of functions]

Returns **Any** [result of last function in sequence]

#### replaceCssSyntax

replaceCssSyntax is a function will pipe a string [key] through more functions to replace and normalize css rule keys

Type: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)

#### convertKey

[convertKey replaces css selector syntax with underscores ]

##### Parameters

-   `key` **\[[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)]** [css selector]

Returns **\[[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)]** [reformatted selector key]

#### mungeRules

[mungeRules reformats rules array from css ast]

##### Parameters

-   `rules` **\[[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)]** [an array of css rules]

Returns **\[[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)]** [array of css rules with keys for JSON]

#### cssToJson

[cssToJson takes a string as a parameter and returns JSON]

##### Parameters

-   `string` **\[[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)]** [css string]

Returns **\[[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)]** [JSON derived from css ast]

#### cssToCamelizedJson

[cssToCamelizedJson takes a string as a parameter and returns JSON]

##### Parameters

-   `string` **\[[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)]** [css string]

Returns **\[[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)]** [camelized values in JSON object derviced from ast]

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