color-sorter
Version:
Sort colors in a visually pleasing way.
37 lines • 1.28 kB
TypeScript
//#region index.d.ts
type NormalizedColor = {
hue: number;
saturation: number;
lightness: number;
alpha: number;
};
type NormalizedColorWithAuthored = NormalizedColor & {
authored: string;
};
/**
* Convert a CSS (string) color into a normalized HSL color that can be used for comparison
* @example convert('red')
*/
declare function convert(authored: string): NormalizedColorWithAuthored;
declare const COLOR_GROUP_NAMES: readonly ["red", "orange", "brown", "yellow", "green", "cyan", "blue", "violet", "magenta", "pink", "gray"];
type ColorGroupName = (typeof COLOR_GROUP_NAMES)[number];
/**
* Get the group name of a color
* @example
* ```ts
* const color = convert('rgb(255 0 0)')
* const group = color_group(color) // => 'red'
* ```
*/
declare function color_group(color: NormalizedColor): ColorGroupName;
/**
* Compare two colors to determine which one is sorted first.
*/
declare function compare(a: NormalizedColorWithAuthored, b: NormalizedColorWithAuthored): number;
/**
* Function that sorts colors
* @example ['red', 'yellow'].sort(sort_fn)
*/
declare function sort_fn(a: string, b: string): number;
//#endregion
export { COLOR_GROUP_NAMES, ColorGroupName, NormalizedColor, NormalizedColorWithAuthored, color_group, compare, convert, sort_fn };