Deep-Symmetry / bytefield-svg

Node module that generates byte field diagrams in SVG format
Eclipse Public License 2.0
126 stars 20 forks source link

Add js/String #34

Closed eval closed 1 year ago

eval commented 1 year ago

This allows for the clj-equivalent of (int \a), i.e. (.charCodeAt \a).

brunchboy commented 1 year ago

Can you show an example of how this would be used?

eval commented 1 year ago

I'm working on documenting base16/32 encoding and tripped over (int \a) ;;=> 0. With js/String this would be:

(defn char->long [ch]
  (.charCodeAt ch))

(def boxes-per-row 8)

(doseq [n "Hello"]
  (draw-related-boxes (number-as-bits (char->long n) 8)))

Would it be helpful to include the char->long helper?

brunchboy commented 1 year ago

Thanks for the clarification! Yes, that would be nice, and adding an example to the user guide would help people discover it. If learning AsciiDoc/Antora is too much, I could help with the formatting, but perhaps it will be clear enough by context if you look in doc/modules/root/pages.

And I should have already said: thank you so much for the contribution! 😄

eval commented 1 year ago

Thanks for the quick feedback and pointers @brunchboy.

I added the helper and some documentation. Struggled a bit with the wording so feel free to amend where needed.

brunchboy commented 1 year ago

Thanks again, @eval, this is a great addition. I’ll see if I can get another release built that includes it. I have to remember my rusty npm skills.

brunchboy commented 1 year ago

Ah, Asciidoctor wants to turn “->” into “→” in the function description, but I figured out how to stop it by escaping. I think I will tweak the wording of the reason why we make the Math and String objects available a bit while I am in there, but your submission was great.

eval commented 1 year ago

🙏🏻 for the merge and the new release James! And good to know about the arrow :)