What's new ?
Prior to v3 the API was not very DRY, with utilities being over specialised for one particular task. Most notably, the sortBy
and filterBy
utilities have been merged and are now customizable through an options
object.
Slimmer APIβ
filterByβ
You can now get your passed in collection filtered using different factors and ranges
for each factor
.
import { filterBy } from "huetiful-js";
// before
filterByHue(...)
filterBySaturation(...)
filterByLuminance(...)
// after
filterBy(...,{ factors:['hue','chroma','luminance'],
ranges:{
hue:[...],
chroma:[...],
luminance:[...]
}})
sortByβ
import { sortBy } from "huetiful-js";
// before
sortByHue(...)
sortBySaturation(...)
sortByLuminance(...)
// after
sortBy(...,{ factor:['hue','chroma','luminance'], order:'desc' })
Easier to customize iteration behaviour than maintain small functions
tokenβ
"One parser to
ruleconvert them all"
Initially each color token type had a standalone converter function. All these functions have been merged into one function, which can parse and output color tokens in different types.
// Old syntax
import { num2rgb, toHex } from 'huetiful-js'
let cssNamedColor = 'pink'
let colorNumber = 5000
let colorObject = { l: 50, c: 20, h: 40, mode: 'lch' }
let colorObjectWithAlpha = { l: 50, c: 20, h: 40, alpha: 0.5, mode: 'lch' }
let arrColor = ['rgb', 120, 80, 50]
let arrColorWithAlpha = ['rgb', 120, 80, 50, 0.1]
// any of the above color tokens is valid
token(...)
Method chaining with color() and load()β
Method chaining allows a more concise and readable syntax than nesting functions inside of each other.
Smaller bundleβ
The library now supports a limited number of colorspaces because the mode definitions make the bundle really large.
See the Culori docs for more information on colorspaces that are included by default. For conversion across many colorspaces use the Culori library instead.
Below is an exhaustive list of supported colorpaces:
export type Colorspaces =
| 'lab'
| 'lab65'
| 'rgb'
| 'lch'
| 'lch65'
| 'xyz65'
| 'xyz'
A few more collection
methodsβ
These functions are still experimental and may have breaking changes in future versions.
stats()β
This function gets the statistics for a collection of color tokens alongside some extra meta which can be useful when you want to know certain info before making a decision during color manipulation. It also has an options
object to customize how the stats are calculated.
distribute()β
As the name suggests, this function opens a new avenue of creativity by distributing the specified factor
s equally amongst other color tokens in the collection. Its behaviour can also be customized by passing an options object.
If you think this function can be further improved, [open an issue](https://github.com/prjctimg/huetiful/issues/new0 on the project repository alongside some suggestions you may have in mind!
Better types and code examplesβ
The library is written in TypeScript for better editor autocomplete support and type definitions for the API. The code examples have also been updated to be more simple and straightforward.
Made something cool out of this ? You can share it on my Twitter.
I'd love to see what can be built with this project!
I hope you find this update useful! π