• Stars
    star
    2,444
  • Rank 18,812 (Top 0.4 %)
  • Language
    JavaScript
  • Created over 10 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Keep a watchful eye on your css colors.

Build Status

CSS Colorguard

Every CSS project starts out with good intentions, but inevitably, one too many people eye-dropper colors into nooks and crannies that you never knew existed. CSS Colorguard helps you maintain the color set that you want, and warns you when colors you've added are too similar to ones that already exist. Naturally, it's all configurable to your tastes.

How it works

Colorguard uses the CIEDE2000 algorithm to determine the similarity of each of the colors in your CSS file. This algorithm is quite complex, but is used in the broadcasting community as the best approximation of human ability to discern differences in color. RGB on the other hand, is pretty bad at representing differences in color purely based on the numerical difference of the hex values.

Luckily, someone else already implemented CIEDE2000, so I didn't have to. Tight. Cause this thing is mathy as hell.

http://f.cl.ly/items/061h1y0x0G2X2e2t1q1f/Screen%20Shot%202014-07-03%20at%205.55.17%20PM.png

Alpha Transparency

Currently, alpha transparency is just stripped from the colors. So rgb(0, 0, 0) exactly matches rgba(0,0,0,0.5). This is usually fine unless someone is alphatransparency-happy and uses it for darkening and lightening colors too often. It could probably be its own check in the future that there aren't too many different alpha transparencies of the same color. This is not currently a thing though.

API

colorguard.process(css, [options]).then(function(result) {})

options

ignore

Type: array

Specify hex codes of colors that you would like to ignore completely. Use with caution.

threshold

Type: number Default: 3

0 through 100. Lower values are more precise; the default is 3 but that's mostly personal opinion.

whitelist

Type: array

Pass an array of color pairs to ignore:

[['#000000', '#010101']]
allowEquivalentNotation

Type: boolean Default: false

By default, colorguard will complain if identical colors are represented with different notations. For example, #000, #000000, rgba(0, 0, 0, 0), and black. If you want to permit these equivalent notations, set this option to true.

postcss([ colorguard(opts) ])

CSS Colorguard can be consumed as a PostCSS plugin. See the documentation for examples for your environment.

Build Time

CSS Colorguard can be used in conjunction with other javascript build systems, such as:

CLI

CSS Colorguard also ships with a CLI app. To see the available options, just run:

$ colorguard --help

Install

With npm, to get the command do:

npm install -g colorguard

To get the library & PostCSS plugin, do:

npm install colorguard

Thanks

  • Stripe - They let me build this at work
  • @markusn - Best CIEDE2000 implementation ever

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

More Repositories

1

yepnope.js

A Script Loader For Your Conditional Builds
JavaScript
2,514
star
2

require-handlebars-plugin

A plugin for handlebars in require.js (both in dev and build)
JavaScript
804
star
3

listpattern

A JavaScript List Pattern Formatter Library
JavaScript
33
star
4

uglifui

Totally in-browser (static) uglifyjs thing (hopefully)
JavaScript
21
star
5

CSSCSS

CSS Quine
17
star
6

node-538

Get the 2016 presidential predictions from 538 in your console
JavaScript
16
star
7

rework-pseudo-classes

Add companion classes to your pseudo styles for testing and convenience.
JavaScript
12
star
8

static-build

My current personal starter static folder with build scripts. Sproutcore on Require with Compass.
JavaScript
11
star
9

dfdep

Deferred Dependencies In The Browser
11
star
10

gaga.js

A Poker Utility Library for JavaScript
JavaScript
11
star
11

sc-handlebars

Compile Sproutcore Handlebars Templates on the server
JavaScript
10
star
12

AssetRace

How fast can you load the same set of resources?
JavaScript
10
star
13

vanilla-extract-react-bake

A variant-focused typesafe component factory for vanilla extract recipes, obviously
TypeScript
10
star
14

yayquery_site

The code for the yayquery podcast website
PHP
9
star
15

mfbars

MessageFormat Handlebars Integration
JavaScript
9
star
16

node-analytics

Real-time + Roll Up
9
star
17

goto.js

Add a goto implementation to JavaScript!
JavaScript
9
star
18

abusing-preprocessor-asts

One of the coolest benefits of preprocessors is that they have easy-to-grok open source parsers that you can actually get into. By injecting yourself after the pre-CSS code has been parsed, you can have a data-centric view of your styles. You can use this information to reduce complexity, point out probable mistakes, or more interestingly, gather metrics, and implement real-time update mechanisms on the client side.
JavaScript
8
star
19

fad.js

Offload all ad code on your site to a single iframe so it doesn't slow things down.
JavaScript
6
star
20

rhokgoh

Glimmer Of Hope Donation Site for Random Hacks of Kindness Austin
JavaScript
6
star
21

xqtouch

A plugin for xui that exposes the exact api needed to run jqTouch.
JavaScript
6
star
22

jQuery-Uncovered

Comment on the lines of jQuery to gain understanding of them
5
star
23

modern-webapp-structure-and-deployment

Future Insights Live - Modules, Builds and Perf
JavaScript
5
star
24

jira2sprintly

A Script to help migrate all your tickets from greenhopper / JIRA to the awesome sprint.ly
JavaScript
5
star
25

minidonations-ui

minidonations-ui-code
JavaScript
5
star
26

broccoli-colorguard

Broccoli wrapped CSS Colorguard
JavaScript
4
star
27

blog

My personal blog
JavaScript
3
star
28

jq-best-friends

Presentation Files
2
star
29

fusejs

Alpha version of FuseJS
JavaScript
2
star
30

books.jquery.com

JavaScript
2
star
31

txjs2012

2
star
32

txjs2011_site

JavaScript
2
star
33

uxoflanguagetalk

The UX of Language slide deck
JavaScript
2
star
34

txjs2013

Texas JavaScript 2013 Sit
JavaScript
2
star
35

pooping-out-css

Talk on CSS Preprocessors for CSSConf.eu
JavaScript
2
star
36

MVCModuleMagicTalk

Talk from BackboneConf 2012
JavaScript
2
star
37

hacking-parsers-and-compilers-in-js

JSConf Brazil 2013 Talk
JavaScript
2
star
38

dabl.js

Data Abstraction Library aka the Brent Spiner Library
1
star
39

scratchpad

Random stuff I don't want to lose.
JavaScript
1
star
40

txjs_site

site for txjs
1
star
41

fbeventpicker

Pull your facebook events and choose which ones to output
1
star
42

jQuery.placeHoldize

jQuery.placeHoldize is a jQuery plug-in which simulates the HTML5 "placeholder" attribute for every browser which is not WebKit-powered. It also simulates it for "textarea"s as the WebKit only support it on "input"s.
JavaScript
1
star