Skip to content

Instantly share code, notes, and snippets.

@shayelkin
Last active August 23, 2020 20:22
Show Gist options
  • Save shayelkin/b28b3e71023db45bdae3c08c57b5d231 to your computer and use it in GitHub Desktop.
Save shayelkin/b28b3e71023db45bdae3c08c57b5d231 to your computer and use it in GitHub Desktop.
Convert camelCase to kebab-case
(s/defn camel->lisp :- s/Str
[s :- s/Str]
(->> s
(re-seq #("?:^\p{javaLowerCase}|\p{javaUpperCase}\p{javaLowerCase}+"))
(map string/lower-case)
(string/join "-")))
(s/defn keys-camel->list :- {s/Keyword s/Any}
[h :- {s/Keyword s/Any} & [recursive :- s/Bool]]
(into {} (map (fn [[k v]] [(-> k str (subs 1) camel->lisp)
(if (and recursive (map? v)) (keys-camel->lisp v true) v)]
h)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment