color-sorter
Version:
Sort colors in a visually pleasing way.
38 lines (37 loc) • 1.12 kB
TypeScript
/**
* Convert a CSS (string) color into a normalized object that can be used for comparison
* @param {string} authored
* @returns {NormalizedColorWithAuthored}
* @example convert('red')
*/
export function convert(authored: string): NormalizedColorWithAuthored;
/**
* @param {NormalizedColorWithAuthored} a
* @param {NormalizedColorWithAuthored} b
* @returns {number}
*/
export function compare(a: NormalizedColorWithAuthored, b: NormalizedColorWithAuthored): number;
/**
* Function that sorts colors
* @param {string} a
* @param {string} b
* @returns {number}
* @example ['red', 'yellow'].sort(sortFn)
*/
export function sortFn(a: string, b: string): number;
/**
* Sort the `colors` array using `Array.sort()`, so beware that it changes the source input
* @param {string[]} colors
* @returns {string[]} sorted
* @example sort(['red', 'yellow'])
*/
export function sort(colors: string[]): string[];
export type NormalizedColor = {
hue: number;
saturation: number;
lightness: number;
alpha: number;
};
export type NormalizedColorWithAuthored = NormalizedColor & {
authored: string;
};