Closed kamranayub closed 7 years ago
hey! can i work on this?
@htalat Absolutely, your PR inspired this one when I noticed these were missing 👍
haha great!
what to return in case an invalid format is provided?
public toString(format = 'rgb') {
if (format === 'rgb')
return this.toRGBA();
if(format === 'hsl')
return this.toHSLA();
if(format === 'hex')
return this.toHex();
return 'invalid format'; // what would be the correct way to handle this flow?
}
I would throw an error (throw new Error("foo"))
On Thu, Jun 29, 2017 at 3:27 PM Hassan Talat notifications@github.com wrote:
what to return in case an invalid format is provided?
public toString(format = 'rgb') { if (format === 'rgb') return this.toRGBA();
if(format === 'hsl') return this.toHSLA(); if(format === 'hex') return this.toHex(); return 'invalid format'; // what would be the correct way to handle this flow?
}
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/excaliburjs/Excalibur/issues/852#issuecomment-312094265, or mute the thread https://github.com/notifications/unsubscribe-auth/AAiaawcBnbPT-cYuQgWuQytF63WNoJ-Tks5sJAizgaJpZM4OH8Gf .
Context
Color supports converting from Hex/HSL representation but not back to them (only RGBA).
Proposal
Modify Color class:
toHex()
.toRGBA()
toHSLA()
type
totoString()
that accepts a string, eitherrgb
,hsl
orhex
parameter (default: "rgb" to maintain backwards compat). Depending on value, it should call either of the three new instance methods.