-
|
This is more of a question than a suggestion, but I’m using the programmatic API ( import { parse, to } from 'colorjs.io/fn';
// (setup, etc.)
const rebeccaPurple = "#663399";
parse(rebeccaPurple); // { spaceId: 'srgb' … } ❌ This is different from to()!
to(rebeccaPurple, 'srgb'); // { space: { id: 'srgb' … }, … } ❌ This is different from parse()!Update: updated the example to highlight my question a little better When working back-and-forth between these two APIs, I have to write helper functions that combine these shapes together so I’m working with the same type. Otherwise I have to write code like this, which gets verbose and boilerplate-y: const spaceId = 'spaceId' in someColor ? someColor.spaceId : someColor.space.id;My question is, is there another API I’m missing that could help? Or would it be possible to merge the shapes of As an aside, the docs for the procedural API have a typo (at least according to the types), which I can make a ticket for separately: // Directly creating object literal
- const p3_lime = {space: "p3", coords: [0, 1, 0]};
+ const p3_lime = {spaceId: "p3", coords: [0, 1, 0]};
const p3_lime_srgb = convert(p3_lime, "srgb"); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
There should not be any API difference. When using object literals as input you provide
The OO API is more high level and takes care of these things for you. The procedural API is mainly meant for high performance cases or where tree-shaking is desired. |
Beta Was this translation helpful? Give feedback.
Oh, I see. Yes,
spaceshould be in the output, sinceparse()needs access to the color space object to read its formats so there's no reason to throw that away.