Tabcorp / strummer

Structural matching for JavaScript
MIT License
65 stars 18 forks source link

Make s.object() confirm to the standard matcher(options) #39

Open rprieto opened 8 years ago

rprieto commented 8 years ago

Strummer matchers usually have several forms:

object is the only exception, because the canonical version is s.object(fields). This means the matcher can never have an other options. It would be a breaking change, but I suggest we should change to s.object({props: ...}), which would allow for things like

s.object({
  optional: true,     // can be null
  allowExtra: true,   // don't fail if there's additional properties to the ones below
  props: { ... }      // list of properties
})

We could still have the top-level shorthand s(someObject) which would delegate to s.object({props: someObject}).

Note: this would remove the need for s.objectOnly.

kiddkai commented 8 years ago

sounds good to me~

FagnerMartinsBrack commented 8 years ago

Could also do something like:

s.object({with: properties})

Which would kind of be read in a similar way as "object with only properties", just now it would be "object with properties" (which IMHO is much more fluent).

It is very important that we run strict comparisons by default and only allow ignoring properties if explicitly asking to do so.

:+1:

rprieto commented 8 years ago

:+1: for s.object({with: properties})