Liking cljdoc? Tell your friends :D

Documentation for clj-data-adapter

Functions

  • kebab-key->namespaced-key [namespace k]
    • Converts kebab cased to namespaced keys
    • namespace ^string : namespace in string format
    • k ^keyword : keyword in kebab-key format to be converted
    • returns ^keyword : keyword with prepended namespace + /
  • kebab-key->snake-str [k]
    • Converts kebab key cased to str snake cased
    • k ^keyword : keyword in kebab-key format to be converted
    • returns ^string : str in snake key format
  • namespaced-key->kebab-key [k]
    • Converts namespaced keys to kebab cased key
    • k ^keyword : keyword in namespaced-key format to be converted
    • returns ^keyword : keyword with namespace removed
  • opt [keys]
    • Wrapps optional selector keyword or keyword collection to be used on transform placeholder-map, when the value is not found on the map, the key is removed from result map
    • keys ^keyword or [^keyword] : keyword in namespaced-key format to be converted
    • returns {^keyword ˆany} : map with internal namespace
  • snake-key->kebab-key [k]
    • Converts a key snake cased to kebab cased key
    • k ^keyword : keyword in snake case key format to be converted
    • returns ^keyword : keyword in kebab cased format
  • snake-key->kebab-str [k]
    • Converts a snake key cased to str kebab cased
    • k ^keyword : keyword in snake case key format to be converted
    • returns ^string : str in kebab case format
  • snake-str->kebab-key [s]
    • Converts string snake cased to keyword kebab cased
    • s ^string : str in snake case format to be converted
    • returns ^keyword : keyword in kebab case format
  • str->uuid [k v]
    • Converts string if its format is uuid to uuid
    • k : key from entry, not used
    • v : value from entry to be converted
    • returns value converted if matching uuid pattern
  • uuid->str [k v]
    • Converts uuid to string
    • k : key from entry, not used
    • v : value from entry to be converted
    • returns value converted if uuid?
  • transform [placeholder-map m]
    • Recursively transforms map m following patterns defined at placeholder-map.
(transform {:a :a-name
            :b "Fixed value"
            :c-name [:c :name]} {:a-name "Aay" :c {:name "C"}})
; => {:a "Aay", :b "Fixed value", :c-name "C"}

(transform {:a {:name :a-name
                :surname (fn [m k] "the Letter")}
            :b 8} {:a-name "Aay"})
; => {:a {:name "Aay", :surname "the Letter"}, :b 8}

(transform {:a-first-name [:a :names 0] :a-last-name [:a :names last]}
           {:a {:names ["Aaay" "the letter"]}})
; => {:a-first-name "Aaay", :a-last-name "the letter"}

(transform {:a-first-name :a :missing-prop :missing}
           {:a "Aaay"})
; => {:a-first-name "Aaay", :missing-prop :missing}

(transform {:a-first-name :a :missing-prop (opt :missing)}
           {:a "Aaay"})
; => {:a-first-name "Aaay"}
  • transform-keys [transform-fn coll]
    • Recursively transforms all map keys in coll with the transform-fn.
    • transform-fn ^fn : function receiving key as parameter and converting it, when returns nil removes the kv
    • coll ^collection : collection being single map itself or a collection of maps to get keys transformed recursively
(transform-keys kebab-key->snake-str {:my-message "something" :payload {:my-name "Lenin"}})
; => {"my_message" "something", "payload" {"my_name" "Lenin"}}

(transform-keys (partial kebab-key->namespaced-key "test") {:id 1, :name "croissant", :unit-grams 200, :price 5.40M})
; => {:test/id 1, :test/name "croissant", :test/unit-grams 200, :test/price 5.40M}
  • transform-keys-1-depth [transform-fn coll]
    • Recursively transforms 1st depth map keys in coll with the transform-fn.
    • transform-fn ^fn : function receiving key as parameter and converting it, when returns nil removes the kv
    • coll ^collection : collection being single map itself or a collection of maps to get keys transformed recursively
(transform-keys-1-depth kebab-key->snake-str {:my-message "something" :payload {:my-name "Lenin"}})
; => {"my_message" "something", "payload" {:my-name "Lenin"}}

(transform-keys-1-depth (partial kebab-key->namespaced-key "test") {:id 1, :name "croissant", :unit-grams 200, :price 5.40M})
; => {:test/id 1, :test/name "croissant", :test/unit-grams 200, :test/price 5.40M}
  • transform-values [transform-fn coll]
    • Recursively transforms all map values in coll with the transform-fn.
    • transform-fn ^fn [k v] : function receiving key and value as parameters and converting the value, when returns nil removes the kv
    • coll ^collection : collection being single map itself or a collection of maps to get values transformed recursively
(transform-values uuid->str {:name "something" :id #uuid "4a26cc9f-e854-4f93-b6c5-cda86c48544c"})
; => {:name "something" :id "4a26cc9f-e854-4f93-b6c5-cda86c48544c"}

(transform-values uuid->str [{:name "something" :id #uuid "4a26cc9f-e854-4f93-b6c5-cda86c48544c"}
                             {:name "smt else" :id #uuid "3a22cc9f-e854-4f93-b6c5-cda86c48544c"}])
; => [{:name "something" :id "4a26cc9f-e854-4f93-b6c5-cda86c48544c"}{:name "smt else" :id "3a22cc9f-e854-4f93-b6c5-cda86c48544c"}]
  • transform-values-1-depth [transform-fn coll]
    • Recursively transforms 1st depth map values in coll with the transform-fn.
    • transform-fn ^fn [k v] : function receiving key and value as parameters and converting the value, when returns nil removes the kv
    • coll ^collection : collection being single map itself or a collection of maps to get values transformed recursively
(transform-values-1-depth uuid->str {:name "something" :id #uuid "4a26cc9f-e854-4f93-b6c5-cda86c48544c"})
; => {:name "something" :id "4a26cc9f-e854-4f93-b6c5-cda86c48544c"}

(transform-values-1-depth uuid->str [{:name "something" :id #uuid "4a26cc9f-e854-4f93-b6c5-cda86c48544c"}
                                     {:name "smt else" :id #uuid "3a22cc9f-e854-4f93-b6c5-cda86c48544c" :sub-entity {:id #uuid "3a22cc9f-e854-4f93-b6c5-cda86c48544c"}}])
; => [{:name "something" :id "4a26cc9f-e854-4f93-b6c5-cda86c48544c"}{:name "smt else" :id "3a22cc9f-e854-4f93-b6c5-cda86c48544c" :sub-entity {:id #uuid "3a22cc9f-e854-4f93-b6c5-cda86c48544c"}}]

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close