faker-js / faker

Generate massive amounts of fake data in the browser and node.js
https://fakerjs.dev
Other
12.46k stars 897 forks source link

Allow Faker to Take Initial Seed on Construction #3008

Open xDivisionByZerox opened 2 months ago

xDivisionByZerox commented 2 months ago

Clear and concise description of the problem

As a developer I want to be able to directly provide a seed when creating a new faker instance. Currently I have to write a separate line mutation the faker instance to configure it the way I want. I feel like it would be good DX to directly create a desired faker instance without having to call additional configuration methods.

Suggested solution

Add initialSeed property to the faker constructor, which will set the seed of the internal randomizer instance on creation.

const faker = new Faker({ locale: [base] });
faker.seed(123);

// alternative
const faker = new Faker({ locale: [base], initialSeed: 123 });

Alternative

Make Faker#seed chainable and return a reference to the current instance. That way I can at leas write it in a shorter way.

// now
const faker = new Faker({ locale: [base] });
faker.seed(123);

// alternative
const faker = new Faker({ locale: [base] }).seed(123);

Additional context

Same could be argued for setDefaultRefDate which could be present as a parameter in Fakers constructor.

github-actions[bot] commented 2 months ago

Thank you for your feature proposal.

We marked it as "waiting for user interest" for now to gather some feedback from our community: