Giter VIP home page Giter VIP logo

Comments (8)

bgrins avatar bgrins commented on June 4, 2024

I suppose we should show that on all of the toString methods. toRgbString is addressed in setAlpha: https://github.com/bgrins/TinyColor#setalpha, but it would probably help to document what all of the methods do (including things like toHex).

from tinycolor.

bitplanets avatar bitplanets commented on June 4, 2024

Yes, you are right. But also toRgbString seems that only outputs rgb. I think toRgbaString would be a good method to add.

from tinycolor.

bgrins avatar bgrins commented on June 4, 2024

I think toRgbaString would be a good method to add.

I've thought about adding this, but then you get into weird cases where you have an alpha set, call toRgbString(), and get incorrect data back. I think it's easier to always return the 'right' data and allow the user to get around that (via setAlpha(1) or toHexString()). We just need to make sure it's better documented.

Any chance you could file a PR with the updated docs?

from tinycolor.

bitplanets avatar bitplanets commented on June 4, 2024

I've thought about adding this, but then you get into weird cases where you have an alpha set, call toRgbString(), and get incorrect data back. I think it's easier to always return the 'right' data and allow the user to get around that (via setAlpha(1) or toHexString()). We just need to make sure it's better documented.

You can add only for consistency.

Any chance you could file a PR with the updated docs?

Yes. Comment something after so I get a notification (:

from tinycolor.

bgrins avatar bgrins commented on June 4, 2024

Cool, thanks :). I think ideally we would have something documented like this for each of the toString functions (toHsvString, toHslString, toHexString, toHex8String, toRgbString, toPercentageRgbString, toName)

var color = tinycolor("red");
color.toRgbString(); // "rgb(255, 0, 0)"

color.setAlpha(0.5);
color.toRgbString(); // "rgba(255, 0, 0, 0.5)"

from tinycolor.

M-Zuber avatar M-Zuber commented on June 4, 2024

What about the toRgb, toHsv, toHsl methods?
It seems from the docs that they return an object with an a property, without touching the alpha:

var color = tinycolor("red");
color.toHsl(); // { h: 0, s: 1, l: 0.5, a: 1 }

which seems to be an unexpected behaviour

from tinycolor.

bgrins avatar bgrins commented on June 4, 2024

It seems from the docs that they return an object with an a property, without touching the alpha
which seems to be an unexpected behaviour

Yes, in general we return the a without a special request. Adding a special request for each would increase the surface area of the API and also be harder to guess. The theory is that a user could always just ignore the a if they don't care about it. We could add a note to the docs about this, though

from tinycolor.

bgrins avatar bgrins commented on June 4, 2024

Fixed by #75

from tinycolor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.