color-js/color.js

Customize `serialize()` output types without having to specify a whole format

Closed this issue · 1 comments

First step for #515

Right now, the only way to customize the output types (e.g. to get a number for OKLCh L or a percentage for alpha) is to specify a whole new format that mirrors the original minus the changes. This is incredibly heavyweight.

I propose the following new serialize() settings:

  • Option 1:
    • coordTypes: Array<string | undefined>
    • alphaType: string | undefined
  • Option 2:
    • types: {coords, alpha}

Right now I’m leaning towards Option 1 as nested objects are both slower and annoying when you only need one.

I ended up going with coords and alpha which contain all params for serializing coords and alpha respectively. Currently coords only takes an array of types, and alpha can take either a boolean (true = always, false = never) or a string ("<percentage>" or "<number>") or both as a {type, include} object.