Skip to content

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

NameTypeDefaultDescription
seednumberrandomSeed()

The initial seed to use. Defaults to a random number.

Returns: Randomizer

ts
function generateMersenne32Randomizer(seed: number = randomSeed()): Randomizer;

Examples

ts
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 });

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

NameTypeDefaultDescription
seednumberrandomSeed()

The initial seed to use. Defaults to a random number.

Returns: Randomizer

ts
function generateMersenne53Randomizer(seed: number = randomSeed()): Randomizer;

Examples

ts
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 });

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

NameTypeDefaultDescription
localesLocaleDefinition[]

The locales to merge.

Returns: LocaleDefinition

ts
function mergeLocales(locales: LocaleDefinition[]): LocaleDefinition;

Examples

ts
import { de_CH, de, en, mergeLocales } from '@faker-js/faker';

const de_CH_with_fallbacks = mergeLocales([ de_CH, de, en ]);

Released under the MIT License.