Skip to content

Instantly share code, notes, and snippets.

@netguy204
Last active October 7, 2015 10:57
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netguy204/3153856 to your computer and use it in GitHub Desktop.
Save netguy204/3153856 to your computer and use it in GitHub Desktop.
;; borrowed from ibdknox/jayq
(defn map->js [m]
(let [out (js-obj)]
(doseq [[k v] m]
(aset out (name k) v))
out))
(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) (map->js 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