Fork me on GitHub
#malli
<
2022-04-21
>
dharrigan08:04:34

I'm wondering, after looking at the examples, I still can't really figure out how to decode a string into lowercase. I have something like this:

dharrigan08:04:36

(def foo [:map
            {:closed true}
            [:name [:string {:max 256 :error/message "should be at most 256 characters"}]]
            [:email-address [:string {:decode/string 'clojure.string/lower-case :min 5 :max 100 :error/message "should be between 5 and 100 characters"}]]])

  (m/validate foo {:name "foo" :email-address ""}) ;; true

  (m/decode signup-request {:name "foo" :email-address ""} mt/json-transformer) ;; {:name "foo", :email-address ""}

dharrigan08:04:30

What my objective is (in tandem with reitit), is to ensure that the email address coming in is all in lowercase. Bit of a puzzler.

dharrigan08:04:58

Any pointers would be appreciated. Thank you.

dharrigan09:04:30

So, got it to work, after plugging away at it for a bit:

dharrigan09:04:44

(m/decode signup-request {:name "foo" :email-address ""} mt/string-transformer) ;; {:name "foo", :email-address ""}

dharrigan09:04:01

difference being to use a string-transformer not a json-transformer

dharrigan09:04:06

Although, it doesn't appear to work with reitit and it's use of json-transformer.

Roee Mazor08:04:54

Hi, I am looking at this example:

(m/validate [:alt keyword? string?] ["foo"]) ; => true
and I am wondering why it works that way, why not:
(m/validate [:alt keyword? string?] "foo") ; => true

Roee Mazor08:04:47

(the second one says false which means the alt thing actually makes it look for a sequence for some reason, how can I use :alt without a vec/seq?)

Roee Mazor09:04:52

perfect, that works perfectly ❤️

1
Ben Sless13:04:08

Alt is for sequence schemas. It's the | operator in regular expressions