metosin / spec-tools

Clojure(Script) tools for clojure.spec
Eclipse Public License 2.0
593 stars 94 forks source link

Coerce JS objects? #258

Open pepijndevos opened 3 years ago

pepijndevos commented 3 years ago

I was trying to coerce some data that came from JS land. After you do js-clj it works nicely, but of course this creates a bunch of extra intermediate values. For example a JS array first gets converted to a vector, and then again to a set.

Would it be possible to add a few transforms that coerce JS values directly?

ikitommi commented 3 years ago

sure, PR welcome!

pepijndevos commented 3 years ago

Awesome. Any pointers on what this would entail? I found this code but I'm not really sure how it works and what I'd need to add to support JS objects. https://github.com/metosin/spec-tools/blob/d05e6e3c76c3c6ff847aa3f8e66344df2705aeae/src/spec_tools/transform.cljc#L207