Skip to content

Commit

Permalink
docs: update unique values guide with new library (#3166)
Browse files Browse the repository at this point in the history
  • Loading branch information
dPaskhin authored Oct 11, 2024
1 parent d516392 commit d43d68d
Showing 1 changed file with 1 addition and 31 deletions.
32 changes: 1 addition & 31 deletions docs/guide/unique.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,4 @@ faker.helpers.uniqueArray(faker.internet.email, 1000); // will generate 1000 uni

3. Build your own logic to keep track of a set of previously generated values and regenerate values as necessary if a duplicate is generated

4. Use a third party package to enforce uniqueness such as [enforce-unique](https://github.com/MansurAliKoroglu/enforce-unique)

Note you can supply a maximum time (in milliseconds) or maximum number of retries.

```js
import { EnforceUniqueError, UniqueEnforcer } from 'enforce-unique';

const uniqueEnforcerEmail = new UniqueEnforcer();

function createRandomUser() {
const firstName = faker.person.firstName();
const lastName = faker.person.lastName();
const email = uniqueEnforcerEmail.enforce(
() =>
faker.internet.email({
firstName,
lastName,
}),
{
maxTime: 50,
maxRetries: 50,
}
);

return {
firstName,
lastName,
email,
};
}
```
4. Use a third-party package to enforce uniqueness, such as [enforce-unique](https://github.com/MansurAliKoroglu/enforce-unique) or [@dpaskhin/unique](https://github.com/dPaskhin/unique).

0 comments on commit d43d68d

Please sign in to comment.