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

Hex strings don't work in clojurescript #20

Open
jjttjj opened this issue Jul 20, 2021 · 2 comments
Open

Hex strings don't work in clojurescript #20

jjttjj opened this issue Jul 20, 2021 · 2 comments

Comments

@jjttjj
Copy link

jjttjj commented Jul 20, 2021

Hi

In clojurescript, rgb-hexstr and the other functions that could return a hexstr don't work:

(color/rgb-hexstr (color/create-color "blue"))
;;=> "#%06X"

This is due to this line:

(format "#%08X" (rgba-int color)))

Google closure's format is limited and doesn't format hex values
(see: https://stackoverflow.com/questions/24635974/clojurescript-format-string-with-goog-string-format-doesnt-substitute)

It would need to be done manually with something like this:

(defn hex-color [[r g b]]
  (str "#"
    (.padStart (.toString r 16) 2 "0")
    (.padStart (.toString g 16) 2 "0")
    (.padStart (.toString b 16) 2 "0")))

Let me know if you would like a PR.
Thanks!

Edited to add .padStart to hex-color.

@jolby
Copy link
Owner

jolby commented Jul 24, 2021

Hi, thanks for noticing this. I'd be happy to take a PR.

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

No branches or pull requests

3 participants
@jolby @jjttjj and others