# cngen

> Generate CSS classnames from declarations, works splendid together with e.g. React

Latest version **1.0.0** (published 2015-09-03) · MIT license · 0 weekly downloads

## Install

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

## 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.0.0 |
| Published | 2015-09-03 |
| First published | 2015-09-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Joakim Carlstein |
| Maintainers | joakimbeng |
| Keywords | classname, generate, css, react, large scale, scaling |

## Links

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

## Dependencies (2)

- [short-hash](https://npm.io/package/short-hash.md) ^1.0.0
- [to-predictable-string](https://npm.io/package/to-predictable-string.md) ^1.0.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2015-09-03

## README

# cngen

[![Build status][travis-image]][travis-url] [![NPM version][npm-image]][npm-url] [![js-xo-style][codestyle-image]][codestyle-url]

> Generate CSS classnames from declarations, works splendid together with e.g. React

## Why?

Generating classnames according to the contents of a CSS declaration solves the biggest problem with large scale CSS, i.e. the fact that it cascades. See [`unistyle`](https://www.npmjs.com/package/unistyle) for how to use this in a scalable way.

## Installation

Install `cngen` using [npm](https://www.npmjs.com/):

```bash
npm install --save cngen
```

## Usage

### Module usage

```javascript
var cngen = require('cngen');

cngen({
  color: '#FFF',
  fontSize: '10px'
});
// _e80a8a8
```

Property order is not important, i.e. two declarations with the same properties but in a different order gives the same classname, e.g:

```javascript
var cngen = require('cngen');

cngen({
  color: '#FFF',
  fontSize: '10px'
});
// _e80a8a8

cngen({
  fontSize: '10px',
  color: '#FFF'
});
// _e80a8a8
```

#### Usage together with e.g. React

Have a look at [`unistyle`](https://www.npmjs.com/package/unistyle) for how this fits together with [React](http://facebook.github.io/react/).


## API

### `cngen(declaration)`

| Name | Type | Description |
|------|------|-------------|
| declaration | `Object` | The CSS declaration to generate a classname for |

Returns: `String`, a generated classname, which consists of a `"_"` followed by a hexadecimal string (generated with [`short-hash`](https://www.npmjs.com/package/short-hash)).

## License

MIT © Joakim Carlstein

[npm-url]: https://npmjs.org/package/cngen
[npm-image]: https://badge.fury.io/js/cngen.svg
[travis-url]: https://travis-ci.org/joakimbeng/cngen
[travis-image]: https://travis-ci.org/joakimbeng/cngen.svg?branch=master
[codestyle-url]: https://github.com/sindresorhus/xo
[codestyle-image]: https://img.shields.io/badge/code%20style-xo-brightgreen.svg?style=flat

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