0.1.0 • Published 5 years ago
yup-faker v0.1.0
yup-faker
Yup schema with fake data generation
Install
npm install yup-faker --save-devUsage
Create a fake person object that conforms to the specified Yup schema. The data is generated using Faker. You do not need to install Faker, it is internal to this package.
The typical, and main, use case of this package is to generate data structures for unit tests. Another use case is generating random sample data in a demo verion of your application.
import * as yup from 'yup';
import { getFakeData } from 'yup-faker';
const personSchema = yup.object({
firstName: yup.string(),
lastName: yup.string(),
gender: yup.mixed().oneOf(['male', 'female', 'other'] as const),
email: yup.string().email(),
birthDate: yup
.date()
.min(new Date(1950, 0, 1))
.max(new Date()),
});
const fakePerson = getFakeData(personSchema);
console.log(JSON.stringify(fakePerson, null, 2));Note:
- The
firstNameandlastNamewill be generated using thefaker.name.firstName()andfaker.name.lastName()functions. - The
genderwill always be one of the three allowed valuesmale,femaleorother. - The
emailfield will be a valid email. - The fake
birthDategenerated will always match the required data range of January 1st 1950 to today.