https://github.com/stoyan/csscolormin
CSS color minification module
https://github.com/stoyan/csscolormin
Last synced: about 1 year ago
JSON representation
CSS color minification module
- Host: GitHub
- URL: https://github.com/stoyan/csscolormin
- Owner: stoyan
- Created: 2014-06-13T02:33:06.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2019-02-05T22:03:01.000Z (about 7 years ago)
- Last Synced: 2025-04-10T17:05:14.204Z (about 1 year ago)
- Language: JavaScript
- Size: 81.1 KB
- Stars: 13
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
- awesome-wpo - Csscolormin - Utility that minifies CSS colors, example: min("white"); // minifies to "#fff". (Miscellaneous / Meetups)
- awesome-wpo-dup - Csscolormin - Utility that minifies CSS colors, example: min("white"); // minifies to "#fff". (Miscellaneous)
- fucking-awesome-wpo - Csscolormin - Utility that minifies CSS colors, example: min("white"); // minifies to "#fff". (Miscellaneous / Meetups)
- awesome-wpo-chinese - Csscolormin - Utility that minifies CSS colors, example: min("white"); // minifies to "#fff". (Miscellaneous)
README
Utility that minifies CSS colors
## Why
Cause we're counting bytes here!
## What
This little module uses the `color` npm module to do the heavy lifting.
So it will take any string input like `"white"`, `"rgba(0,0,0,1)"`, `"hsla(..)"`, `"hsv()"`, `"cmyk()"`, etc
Then it converts to `rgba()`, because we're targeting browsers.
Then it tries to minify the result as best as possible, e.g. removes the `a` in `rgba` if not needed,
tries an `#rrggbb`, an `#rgb` or a color name (e.g. `red`) and returns the shortest.
The return values are also consistently lowercase.
## Installation
$ npm install csscolormin
## Usage
There's a single function provided by the module. It accepts any type of input that `color` module accepts,
plus an rgb/rgba array.
Examples:
```js
const min = require('csscolormin');
min("white");
min("rgb(0, 0, 0)");
min("rgba(0, 0, 0, 0)");
min("hsl(0, 0, 0)");
min("hsla(0, 0, 0, 0)");
min("#bbaadd");
```
Some more examples and returned values:
```js
min("white"); // "#fff"
min("black"); // "#000"
min("fuchsia"); // "#f0f"
min("red"); // "red"
min("#333333"); // "#333"
min("rgb(10, 30, 25)"); // "#0a1e19"
min("rgba(10, 30, 25, 1)"); // "#0a1e19"
min("rgba(10, 30, 25, 0.1)"); // "rgba(10,30,25,.1)"
min("rgba(10, 30, 25, 0)"); // "transparent"
min("hsl(120, 50%, 60%)"); // "#6c6"
min("blue"); // "blue"
min("goldenrod"); // "#daa520"
```
## More
* Playground: http://colormin.csspatterns.com
* The `color` module: https://github.com/harthur/color