Sort CSS colors by hue, then by saturation
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
.gitignore
.travis.yml
color-sorter.js
license
package-lock.json
package.json
readme.md
test.js

readme.md

color-sorter

NPM Version Build Status Known Vulnerabilities Dependencies Status Dependencies Status XO code style

Sort CSS colors by hue, then by saturation. Black-grey-white colors (colors with 0% saturation) are shifted to the end. Fully transparent colors are placed at the very end.

This sorting algorithm is very opinionated and might not fit your needs!

Usage

var colorSort = require('color-sorter')
var colors = ['#000', 'red', 'hsl(0, 10%, 60%)']
var sorted = colors.sort(colorSort)

// => sorted:
// [
//  'red',
//  'hsl(0, 10%, 60%)',
//  '#000'
// ]

Examples

These examples can be seen on Project Wallace where this package is used for sorting the colors.

CSS-Tricks

CSS Tricks color sort example

Smashing Magazine

Smashing Magazine color sort example

Bootstrap

Bootstrap color sort example

Zurb Foundation

Zurb Foundation color sort example

Project Wallace

Project Wallace color sort example

Related projects

  • CSS Analyzer - Generate analysis for a string of CSS
  • Wallace - CLI tool for @projectwallace/css-analyzer
  • Gromit - A test framework to assert that CSS doesn't exceeds certain thresholds

License

MIT © Bart Veneman