Skip to content

Export the default randomizer #2681

@sbaechler

Description

@sbaechler

Clear and concise description of the problem

Injecting the same randomizer to different Faker instances seems to become a common use case, especially with multilingual datasets.

Hovewer, the default randomizer factory is not exported from the package and therefore cannot easily be used.

Suggested solution

It would be really helpful if the method generateMersenne32Randomizer was exported, maybe using an alias.

The documentation could be updated as follows:

import { en, Faker, Randomizer, zh_TW, generateDefaultRandomizer } from '@faker-js/faker';

const randomizer: Randomizer = generateDefaultRandomizer()

const customFakerEN = new Faker({
  locale: en,
  randomizer,
});

const customFakerZH_TW = new Faker({
  locale: [zh_TW, en],
  randomizer,
});

randomizer.seed(5);
// customFakerEN.seed(5); // Redundant
// customFakerZH_TW.seed(5); // Redundant

const firstName = fakerZH_TW.person.firstName(); // 炫明
const alias = fakerEN.person.firstName(); // John (different from before, because it is now the second call)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions