Fork me on GitHub
#malli
<
2021-02-06
>
ikitommi09:02:28

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

ikitommi09:02:36

two small things for 0.3.0 with all the stuff in.

borkdude10:02:38

this is like conform right?

ikitommi10:02:22

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