Utilities
A list of all the utilities available in Faker.js.
generateMersenne32Randomizer
Generates a MersenneTwister19937 randomizer with 32 bits of precision. This is the default randomizer used by faker prior to v9.0.
Available since v8.2.0
Parameters
Name | Type | Default | Description |
---|---|---|---|
seed | number | randomSeed() | The initial seed to use. Defaults to a random number. |
Returns: Randomizer
function generateMersenne32Randomizer(seed: number = randomSeed()): Randomizer;
Examples
import { de, en, generateMersenne32Randomizer, Faker } from '@faker-js/faker';
const randomizer = generateMersenne32Randomizer();
randomizer.seed(42);
// Share the same randomizer between multiple instances
const customFaker1 = new Faker({ locale: de, randomizer });
const customFaker2 = new Faker({ locale: en, randomizer });
Source
generateMersenne53Randomizer
Generates a MersenneTwister19937 randomizer with 53 bits of precision. This is the default randomizer used by faker starting with v9.0.
Available since v9.0.0
Parameters
Name | Type | Default | Description |
---|---|---|---|
seed | number | randomSeed() | The initial seed to use. Defaults to a random number. |
Returns: Randomizer
function generateMersenne53Randomizer(seed: number = randomSeed()): Randomizer;
Examples
import { de, en, generateMersenne53Randomizer, Faker } from '@faker-js/faker';
const randomizer = generateMersenne53Randomizer();
randomizer.seed(42);
// Share the same randomizer between multiple instances
const customFaker1 = new Faker({ locale: de, randomizer });
const customFaker2 = new Faker({ locale: en, randomizer });
Source
mergeLocales
Merges the given locales into one locale. The locales are merged in the order they are given. The first locale that provides an entry for a category will be used for that. Mutating the category entries in the returned locale will also mutate the entries in the respective source locale.
Available since v8.0.0
Parameters
Name | Type | Default | Description |
---|---|---|---|
locales | LocaleDefinition[] | The locales to merge. |
Returns: LocaleDefinition
function mergeLocales(locales: LocaleDefinition[]): LocaleDefinition;
Examples
import { de_CH, de, en, mergeLocales } from '@faker-js/faker';
const de_CH_with_fallbacks = mergeLocales([ de_CH, de, en ]);