Fork me on GitHub

I'm attempting to use the camel-snake-kebab library in a clojurescript project. According to the docs, this code should work with both clojure and clojurescript. I added the appropriate :require to my namespace:

(ns atlas.rendering
            [camel-snake-kebab.core :as csk]))
and added the proper dependency to my shadow-cljs.edn file:
 [[camel-snake-kebab "0.4.2"]]
This should work, but I get an error:
The required namespace "camel-snake-kebab.core" is not available, it was required by "atlas/rendering.cljs".
Obviously, there's some reason why cljs isn't finding the library, but I have no idea why. Does anyone have any suggestions?


Have you restarted the shadow-cljs server?


That was it. Thanks.

👍 1

In clojurescript is there any way to convert from json -> edn passing keys to a keyword conversion function? The keys in my json are camel-cased and I'd like to convert them to kebab case, rather than just converting the camel-cased keys to keywords. I've looked at js->clj, but it seems to only take a boolean parameter :keywordize-keys and not a function to convert keys. Is there another library I could use that would allow me to do this? Alternatively, is there an easy way to recursively walk the converted edn converting the map keys after the fact?


The implementation of js->clj is rather trivial and given that you deal with JSON and not arbitrary JS objects, you can simplify it even further - it just recursively walks the data structure and replaces what it can. Alternatively, you can use clojure.walk. Doesn't matter that much.


Just in case - note that you needs depth-first traversal, so it would be clojure.walk/postwalk.


Yes. I used that. It was a bit trickier reading in the JSON and getting it translated into JSON objects before converting it to EDN, but once that was done, getting the keywords correct was relatively simple. Thanks again for your help.


> It was a bit trickier reading in the JSON and getting it translated into JSON What do you mean? It should be as simple as calling js/JSON.parse on a string.


I had the json code in a resource file and had to get that into the code. Which sent me onto a macro adventure so I could slurp it into the cljs. The good news is that I now know how to use macros in cljs.

👍 1

Will Google Closure be able to "cut out" top level maps that are unused? E.g.:

(ns example)
(defn foo [])
(def a {'foo bar}) ;; unused in other namespaces


@borkdude in the past did not work, but I believe it does work now


I remember your comment from the past, that's why I asked :)


Just tested - it does indeed get removed.


good! thanks!