Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
cressie176 authored Jan 29, 2024
1 parent 22ad951 commit ea0e23a
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,27 +112,21 @@ By default, Yup By Example will use the [metadata](https://github.com/jquense/yu
| array | of, length, min, max, oneOf |
| object | shape, oneOf |

However for more nuanced validation and to make your data more realistic you can use one of Yup By Example's in built generators or even write your own. You can select and configure a generator by passing parameters to the `example` method, e.g.

```js
example({ generator: 'fn' }, () => {
const randomOctet = () => Math.floor(Math.random() * 256);
const ipAddress = Array.from({ length: 4 }, randomOctet).join('.');
return ipAddress;
})
```
However for more nuanced validation and to make your data more realistic you can use one of Yup By Example's in built generators or even write your own cusotm generator (see below).

### Function Generator (fn)

A generator which uses an inline function to return test data. The function must be supplied as the second argument, e.g.

```js
string().example({ generator: 'fn' }, (params) => {
// Generate and return the test data
example({ generator: 'fn' }, () => {
const randomOctet = () => Math.floor(Math.random() * 256);
const ipAddress = Array.from({ length: 4 }, randomOctet).join('.');
return ipAddress;
})
```

The function will passed an object with the following parameters
The inline function will passed an object with the following parameters

| name | notes |
| ------- | --------------------------------------------- |
Expand Down

0 comments on commit ea0e23a

Please sign in to comment.