Skip to content

Instantly share code, notes, and snippets.

@ThomasCrevoisier
Last active August 29, 2015 14:11
Show Gist options
  • Save ThomasCrevoisier/f262df43937245e91187 to your computer and use it in GitHub Desktop.
Save ThomasCrevoisier/f262df43937245e91187 to your computer and use it in GitHub Desktop.
Keyword to property conversion in ClojureScript
;;; ClojureScript example from David Nolen's talk "ClojureScript : Lisp's revenge"
;;; https://www.youtube.com/watch?v=MTawgp3SKy8
(defn capitalize [s]
(str (.toUpperCase (aget s 0))
(.substring s 1)))
(defn keyword->property [k]
(let [[x & xs] (-> (str k) (.substring 1) (.split "-"))]
(apply str x (map capitalize xs))))
(keyword->property :border-radius) ;;; output : "borderRadius"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment