feat: support custom randomizer#2284
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## next #2284 +/- ##
==========================================
- Coverage 99.61% 99.58% -0.03%
==========================================
Files 2820 2820
Lines 253880 253975 +95
Branches 1101 1102 +1
==========================================
+ Hits 252891 252923 +32
- Misses 962 1024 +62
- Partials 27 28 +1
|
|
We have to decide whether we want to merge this in v8.x or v9. |
|
Blocked by #2361 as it may require changes to the Mersenne interface. |
As mentioned in the team meeting. The exposed API is dependent on the decisions we make for those issues. |
Ah ok I see, you want to wait half a week until we all decide and write down that we agree with the |
|
Should we add an example of how you go from a prebuilt localised Faker instance (say fakerEN_GB) to a version with a custom randomizer? That may not be that intuitive as I think you'd have to drop the prebuilt instance and use manual fallback locales in order to access the Faker constructor. |
|
Could you please write it in pseudocode? I'm not sure what you are asking for. |
// if you are currently using a prebuilt version of Faker
import {fakerEN_GB as faker} from '@faker-js/faker';
console.log(faker.location.city())
// you will need to manually construct a new Faker instance with the correct fallback languages
// and then you can set a custom randomizer function
import { Faker, en, en_GB, base } from '@faker-js/faker';
const faker2 = new Faker({
locale: [en_GB, en, base],
randomizer: yourCustomRandomizerFunction
})
console.log(faker2.location.city()) |
|
I think adding the Faker constructor with some ommissions should be plenty. Maybe we should add a link to the constructor though. Const faker2 = new Faker({
locale: ...,
randomizer: newRandomizer(),
});And |
|
It's more guiding people that they cannot simply do something like fakerEN_GB.randomizer = ... |
|
Here the updated screenshots for the documentation: |
|
From the updated documentation you sent, the API looks great. I'm looking forward to connect it 🥰 Thanks a lot for it 👍 |
|
I want to thank you all for this awesome feature. It unlocks a better integration of Faker within fast-check as detailed in this article. If you read it and have some remarks, please let me know, I'll be happy to discuss and fix them. |








Adds the ability to Faker to use a custom prng.
Intended use case for clone and derive:
(Regardless of whether we will actually have either of them)
Intended use case cross compatibility with other libraries other than faker:
Note: Currently faker's internal PRNG isn't exported.