Skip to content

A Clojure library to convert between different word case conventions.

Notifications You must be signed in to change notification settings

imintel/camel-snake-kebab

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Camel_SNAKE-kebab

A Clojure library to convert between different word case conventions.

Examples

(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"

Installation

  1. Add the following to your project.clj :dependencies:
[camel-snake-kebab "0.1.1"]
  1. Add the following to your namespace declaration:
:use camel-snake-kebab

Available Conversion Functions

  • ->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.

A Serving Suggestion: Dealing with JSON Objects

(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"}

Further Reading

License

Copyright (C) 2012 Christoffer Sawicki

Distributed under the Eclipse Public License, the same as Clojure.

About

A Clojure library to convert between different word case conventions.

Resources

Stars

Watchers

Forks

Packages

No packages published