malli

https://github.com/metosin/malli :malli:
ikitommi 2021-02-06T09:45:28.059300Z

m/unparse and m/unparser landed in master! parse + unparse with hiccup:

(def Hiccup
  [:schema
   {:registry {"hiccup" [:or*
                         [:node [:cat*
                                 [:name keyword?]
                                 [:props [:? [:map-of keyword? any?]]]
                                 [:children [:* [:schema [:ref "hiccup"]]]]]]
                         [:primitive [:or*
                                      [:nil nil?]
                                      [:boolean boolean?]
                                      [:number number?]
                                      [:text string?]]]]}}
   "hiccup"])

(m/parse
  Hiccup
  [:div {:class [:foo :bar]}
   [:p "Hello, world of data"]])
;[:node
; {:name :div,
;  :props {:class [:foo :bar]},
;  :children [[:node
;              {:name :p
;               :props nil
;               :children [[:primitive [:text "Hello, world of data"]]]}]]}]


(->> [:div {:class [:foo :bar]}
      [:p "Hello, world of data"]]
     (m/parse Hiccup)
     (m/unparse Hiccup))
;[:div {:class [:foo :bar]}
; [:p "Hello, world of data"]]

ikitommi 2021-02-06T09:49:36.059700Z

two small things for 0.3.0 with all the stuff in.

borkdude 2021-02-06T10:20:28.059900Z

nice!

borkdude 2021-02-06T10:20:38.060100Z

this is like conform right?

ikitommi 2021-02-06T10:40:22.063800Z

yes, same as s/confom and s/unform. At the moment, there are no property-based custom parsers/unparsers that a user could add (like custom property based transformers) and in case of error, just ::m/invalid is returned. I think we can later combine -parse, -unparse and -explain implementations together, so that one can see partially parsed results and get more details when parsing/unparsing fails (same output as in -explain).