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"]]
two small things for 0.3.0 with all the stuff in.
nice!
this is like conform right?
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
).