simple-runtypes
simple-runtypes copied to clipboard
nonStrict modifier
Change the existing sloppyRecord runtype functionality into a nonStrict combinator that works on record runtypes, similar to how pick works atm.
Before:
import * as st from 'simple-runtypes'
const item = st.sloppyRecord({
id: st.number(),
label: st.string(),
})
After:
import * as st from 'simple-runtypes'
const item = st.nonStrict(
st.record({
id: st.number(),
label: st.string(),
}),
)
Reasons:
- "sloppy" has a bad connotation that looks weird when spread out all over runtype definitions
- using a modifier function allows for separating the record definition from the way its parsed
- it is still possible to mix nonStrict with strict objects in a single runtype