Last active
August 23, 2020 20:22
-
-
Save shayelkin/b28b3e71023db45bdae3c08c57b5d231 to your computer and use it in GitHub Desktop.
Convert camelCase to kebab-case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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