Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[getAll] Support precision, closes #542 #548

Merged
merged 10 commits into from
Jun 12, 2024

Conversation

DmitrySharabin
Copy link
Contributor

@DmitrySharabin DmitrySharabin commented Jun 11, 2024

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.

Copy link

netlify bot commented Jun 11, 2024

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

Copy link
Member

@LeaVerou LeaVerou left a comment

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
Contributor 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?

Copy link
Member

@LeaVerou LeaVerou left a comment

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
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
Contributor 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! 🙏

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
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
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
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).

src/getAll.js Outdated Show resolved Hide 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
Contributor Author

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

Copy link
Member

@MysteryBlokHed MysteryBlokHed left a comment

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
0 of 5 checks passed
@LeaVerou
Copy link
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
Contributor 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