Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export the default randomizer #2681

Closed
sbaechler opened this issue Feb 23, 2024 · 1 comment · Fixed by #2357
Closed

Export the default randomizer #2681

sbaechler opened this issue Feb 23, 2024 · 1 comment · Fixed by #2357
Labels
c: feature Request for new feature p: 1-normal Nothing urgent
Milestone

Comments

@sbaechler
Copy link

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)
@ST-DDT
Copy link
Member

ST-DDT commented Feb 23, 2024

Exposing the generateMersenne32Randomizer is planned for v9.

faker/src/index.ts

Lines 78 to 81 in 41b00cb

export {
generateMersenne32Randomizer,
generateMersenne53Randomizer,
} from './internal/mersenne';

@ST-DDT ST-DDT added this to the v9.0 milestone Feb 23, 2024
@ST-DDT ST-DDT linked a pull request Feb 23, 2024 that will close this issue
3 tasks
@ST-DDT ST-DDT added c: feature Request for new feature p: 1-normal Nothing urgent labels Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: feature Request for new feature p: 1-normal Nothing urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants