omgovich / colord

πŸ‘‘ A tiny yet powerful tool for high-performance color manipulations and conversions
https://colord.omgovich.ru
MIT License
1.67k stars 49 forks source link

Feature: more color utilities #61

Closed EricRovell closed 3 years ago

EricRovell commented 3 years ago

More color utilities

Summary

Add some more utility functions to work with color instances.

Motivation

Some more simple utilities may be useful for the user:

  1. copy or clone: provides an easy way to clone a color instance.
  2. equals: provides an easy way to compare two colors.

Detailed design

The are two possibilities as I see:

As part of the interface

import { colord } from "colord";

const color = colord("#DC3522");
const anotherColor = colord("#abc123");
const colorCopy = color.copy();

color.equals(colorCopy); // -> true
color.equals(anotherColor); // -> false;

As utility functions

import { colord, copy, equals } from "colord";

const color = colord("#DC3522");
const anotherColor = colord("#abc123");
const colorCopy = copy(color);

equals(colorCopy); // -> true
equals(anotherColor); // -> false;

Discussion

I think it would be better for this utilities, if they are seems useful for you, to be part of the main interface. In any case, if you think this feature may be useful and should be implemented, I am ready to do this.

omgovich commented 3 years ago

Hi πŸ‘‹ In my opinion, since colord is 100% immutable (any action creates a new Colord instance) it doesn't make a lot of sense to implement .copy() method.

At the same time equals sounds good and shouldn't cost us many bytes. But I would go with color1.isEqual(color2) or color1.isSame(color2) for better consistency.

EricRovell commented 3 years ago

Yeah, it makes sense. I will try to implement it this way then :)

omgovich commented 3 years ago

Just released v2.3.0. Thanks!