A Clojure library to convert between different word case conventions.
(use 'camel-snake-kebab)
(->CamelCase 'flux-capacitor)
; => 'FluxCapacitor
(->SNAKE_CASE "I am constant")
; => "I_AM_CONSTANT"
(->kebab-case :object_id)
; => :object-id
(->HTTP-Header-Case "x-ssl-cipher")
; => "X-SSL-Cipher"
- Add the following to your
project.clj
:dependencies
:
[camel-snake-kebab "0.1.1"]
- Add the following to your namespace declaration:
:use camel-snake-kebab
->CamelCase
->camelCase
->SNAKE_CASE
->Snake_case
->snake_case
->kebab-case
->Camel_Snake_Case
->HTTP-Header-Case
You should be able to figure out all what all of them do.
(defn map-keys [f m]
(letfn [(mapper [[k v]] [(f k) (if (map? v) (map-keys f v) v)])]
(into {} (map mapper m))))
(map-keys (comp ->kebab-case keyword) {"firstName" "John", "lastName" "Smith"})
; => {:first-name "John", :last-name "Smith"}
; And back:
(map-keys (comp ->camelCase name) {:first-name "John", :last-name "Smith"})
; => {"firstName" "John", "lastName" "Smith"}
Copyright (C) 2012 Christoffer Sawicki
Distributed under the Eclipse Public License, the same as Clojure.