clojurescript

djanus 2026-02-04T14:16:05.209139Z

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?

thheller 2026-02-04T14:23:27.899889Z

maybe use alength instead

djanus 2026-02-04T14:24:14.748739Z

I am, just reporting an apparent inconsistency

👍🏽 1
2026-02-05T09:21:41.636129Z

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

djanus 2026-02-05T12:38:54.806689Z

Thank you – asked there

weavejester 2026-02-04T19:24:28.532899Z

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 .

p-himik 2026-02-04T19:25:54.190369Z

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))

weavejester 2026-02-04T19:27:03.787529Z

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

p-himik 2026-02-04T19:33:48.431859Z

Yep.

Shantanu Kumar 2026-02-11T04:37:43.265439Z

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.