bgrins / TinyColor

Fast, small color manipulation and conversion for JavaScript
https://bgrins.github.io/TinyColor/
MIT License
5.05k stars 437 forks source link

Define an extension API for registering custom color formatter #135

Open bgrins opened 8 years ago

bgrins commented 8 years ago

Originally from #98.

There are a bunch of color formats, and it doesn't make sense to build all of them into the library. If we had an extension API where someone could register something like:

id,
shouldHandleInput(input) -> bool,
toRgb(input) -> {r,g,b,a}
toString({r,g,b,a})

Then the lib could loop through extensions and send tinycolor(input) into the toRgb method if shouldHandleInput is true (which would be true for something like 0xaabbcc in a "number" extension. Then when tinycolor(0xaabbcc).toString("number") is called it would defer to the extension's implementation.

So proposed API is something like:

`tinycolor.registerFormat(id, options)`