Closed Olian04 closed 6 years ago
v1 proposal:
const Record = (type, constraintObject) => (obj) => {
if(Assert( obj, R.Object.Like(constraintObject) )) {
throw new TypeError(`Failed to construct a record of type "${type}", object does not comply to the constraints of a ${type} record.`);
}
return obj;
}
const RFoo = Record('foo', {
bar: R.Number
});
const foo_ok = RFoo({
bar: 1
});
const foo_fail = RFoo({
bar: '1'
});
The api module should expose 2 things, a function for constructing a new Record, and an object to access the constraint builder.