Skip to content

Hex strings don't work in clojurescript #20

Description

@jjttjj

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions