clojurescript 2026-02-04

Hey! I just discovered that JS TypedArrays (`Uint8Array` et al) do not implement ICounted out of the box, even though it's trivial to make them do so. As a result count doesn't work on them; this is in contrast to Clojure where count works on arrays of primitives. Can/should this be added, or is the current behaviour intended?

maybe use alength instead

I am, just reporting an apparent inconsistency

👍🏽 1

This is a great question for http://ask.clojure.org, which is the on-ramp to feature suggestions

Thank you – asked there

What's the best way of converting a javascript object to a Clojure object, assuming that the object has a different prototype to js/Object? I notice that js->clj only works on objects where the type is identical to js/Object .

If you need nested traversal, this function is easy to adapt to your needs:

(defn json->clj [data {:keys [keywordize?] :as opts}]
  (cond
    (nil? data)
    nil

    (js/Array.isArray data)
    (mapv #(json->clj % opts) data)

    (= (.-constructor data) js/Object)
    (into {}
          (map (fn [[k v]]
                 [(if keywordize? (keyword k) k)
                  (json->clj v opts)]))
          (js/Object.entries data))

    :else
    data))

Presumably that's a custom function, not one included in ClojureScript?

Just a data point: (js->clj (.-env js/process)) doesn't work with Node.js, so I had to (js->clj (js/Object.assign #js {} (.-env js/process))) it.