Skip to content

Instantly share code, notes, and snippets.

@tobyhede
Created July 29, 2012 01:52
Show Gist options
  • Save tobyhede/3195680 to your computer and use it in GitHub Desktop.
Save tobyhede/3195680 to your computer and use it in GitHub Desktop.
clj->js - convert ClojureScript objects into JavaScript equivalents
(defn clj->js
"Recursively transforms ClojureScript maps into Javascript objects,
other ClojureScript colls into JavaScript arrays, and ClojureScript
keywords into JavaScript strings."
[x]
(cond
(string? x) x
(keyword? x) (name x)
(map? x) (.-strobj (reduce (fn [m [k v]]
(assoc m (clj->js k) (clj->js v))) {} x))
(coll? x) (apply array (map clj->js x))
:else x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment