Giter Club home page Giter Club logo

csscolormin's Introduction

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:

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:

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.