Skip to content

[getAll] Support precision, closes #542 - #548

Merged
LeaVerou merged 10 commits into
color-js:mainfrom
DmitrySharabin:get-all-precision
Jun 12, 2024
Merged

LeaVerou merged 10 commits into
color-js:mainfrom
DmitrySharabin:get-all-precision

Conversation

@DmitrySharabin

@DmitrySharabin DmitrySharabin commented Jun 11, 2024 •

Copy link
Copy Markdown
Member

Ensure that it’s something you had in mind, though. My approach is relatively straightforward. We should probably have an optional options parameter with precision as a property.

@netlify

netlify Bot commented Jun 11, 2024 •

Copy link
Copy Markdown

❌ Deploy Preview for colorjs failed. Why did it fail? β†’

Name Link
πŸ”¨ Latest commit aa6db63
πŸ” Latest deploy log https://app.netlify.com/sites/colorjs/deploys/6669a09a10e10d000804bed9

@LeaVerou LeaVerou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want a separate parameter here, we'd want to make the second param an options object with space and precision as keys. Specifying a color space (either as a string or ColorSpace object should still work.

@DmitrySharabin

Copy link
Copy Markdown
Member Author

I don't think we want a separate parameter here, we'd want to make the second param an options object with space and precision as keys. Specifying a color space (either as a string or ColorSpace object should still work.

Agreed. Done. Could you please have another look?

@DmitrySharabin
DmitrySharabin requested a review from LeaVerou June 11, 2024 10:04

@LeaVerou LeaVerou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that I said:

Specifying a color space (either as a string or ColorSpace object should still work.

Using space as an options param should only be needed when we’re also specifying precision.

@MysteryBlokHed

Copy link
Copy Markdown
Member

Something like this in toGamut.js could be used maybe?

color.js/src/toGamut.js

Lines 69 to 71 in 3f97a65

if (util.isString(arguments[1])) {
space = arguments[1];
}

Where a destructured object is used as a parameter, but then arguments is used to check if something else was passed. So if it's a string or instance of a color space, then space is just set to arguments[1].

@DmitrySharabin

Copy link
Copy Markdown
Member Author

Something like this in toGamut.js could be used maybe?

color.js/src/toGamut.js

Lines 69 to 71 in 3f97a65

if (util.isString(arguments[1])) {
space = arguments[1];
}

Where a destructured object is used as a parameter, but then arguments is used to check if something else was passed. So if it's a string or instance of a color space, then space is just set to arguments[1].

I was thinking of something like this, too. Thank you so much for the hint! πŸ™

@DmitrySharabin
DmitrySharabin requested a review from LeaVerou June 11, 2024 12:28
Comment thread src/getAll.js Outdated
Comment on lines +11 to +14
* @param {string | ColorSpace | object} [options=color.space] If a string or ColorSpace, the color space to convert to. Defaults to the color's current space.
* If an object:
* [options.space=color.space] β€” the color space to convert to (defaults to the color's current space);
* [options.precision] β€” the number of significant digits to round the coordinates to.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn’t seem to me like TypeScript is properly understanding the type here. Maybe making a @typedef for the function’s options would be best? I can add a code suggestion for that you agree

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think a typedef would make sense here. Though I thought we had found a way to do overloads?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overloads would work too, but I still don’t think it’s a bad idea to define the options outside of the function’s JSDoc just for readability. We can have one overload with string | ColorSpace and another with the new type (eg. GetAllOptions).

Comment thread src/getAll.js Resolved
Comment thread src/getAll.js Resolved
DmitrySharabin and others added 3 commits June 12, 2024 14:07
Co-authored-by: Adam Thompson-Sharpe <adamthompsonsharpe@gmail.com>
Co-authored-by: Adam Thompson-Sharpe <adamthompsonsharpe@gmail.com>
@DmitrySharabin

Copy link
Copy Markdown
Member Author

@MysteryBlokHed, could you please check if I get the idea with overloads right?

@MysteryBlokHed MysteryBlokHed left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything typing-related LGTM!

@LeaVerou
LeaVerou merged commit b6e92aa into color-js:main Jun 12, 2024
@LeaVerou

Copy link
Copy Markdown
Member

@DmitrySharabin do you have access to edit the release notes for v0.6.0 to mention this? (make sure not to accidentally publish!)

@DmitrySharabin

Copy link
Copy Markdown
Member Author

@DmitrySharabin do you have access to edit the release notes for v0.6.0 to mention this? (make sure not to accidentally publish!)

It looks like I don't β€” I don't see any drafts of release notes.

@DmitrySharabin
DmitrySharabin deleted the get-all-precision branch June 12, 2024 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[getAll] Add an option(?) so that formatted coords can be returned

3 participants