Skip to content

generate objects from predicate #229

@DuredhelFinceleb

Description

@DuredhelFinceleb

Hi !

Let's say I have objects representing a DB record and I wrote this to validate them

const myRecordType = ow.object.exactShape({
  id: ow.string,
  axis: ow.string.oneOf(['X', 'Y', 'Z']),
  value: number,
  name: ow.optional.string,
});

How can I use this to generate new empty records?
The idea would be to create a function that returns a correctly initialized object

const newRec = generateNewRecord(myRecordType);
console.dir(newRec);
/*
{
  id: '',
  axis: 'X',
  value: 0,
  name: '',
}
*/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions