β οΈ You are reading the docs for the next branch β οΈ
Please proceed to the Getting Started Guide for the stable release of Faker.
For detailed API documentation, please select the version of the documentation you are looking for.
Version | Website |
---|---|
v9 (next) | https://next.fakerjs.dev/ |
v9 (stable) | https://fakerjs.dev/ |
v8 (old) | https://v8.fakerjs.dev/ |
- π Locations - Generate valid looking Addresses, Zip Codes, Street Names, States, and Countries!
- β° Time-based Data - Past, present, future, recent, soon... whenever!
- π Localization - Pick a locale to generate realistic looking Names, Addresses, and Phone Numbers.
- πΈ Finance - Create stubbed out Account Details, Transactions, and Crypto Addresses.
- π Products - Generate Prices, Product Names, Adjectives, and Descriptions.
- πΎ Hacker Jargon - βTry to reboot the SQL bus, maybe it will bypass the virtual application!β
- π§ Names - Generate virtual humans with a complete online and offline identity.
- π’ Numbers - Of course, we can also generate random numbers and strings.
Note: Faker tries to generate realistic data and not obvious fake data. The generated names, addresses, emails, phone numbers, and/or other data might be coincidentally valid information. Please do not send any of your messages/calls to them from your test setup.
npm install --save-dev @faker-js/faker
// ESM
import { faker } from '@faker-js/faker';
// CJS
const { faker } = require('@faker-js/faker');
export function createRandomUser() {
return {
userId: faker.string.uuid(),
username: faker.internet.username(), // before version 9.1.0, use userName()
email: faker.internet.email(),
avatar: faker.image.avatar(),
password: faker.internet.password(),
birthdate: faker.date.birthdate(),
registeredAt: faker.date.past(),
};
}
export const users = faker.helpers.multiple(createRandomUser, {
count: 5,
});
An in-depth overview of the API methods is available in the documentation for v9 (stable) and v9.* (next).
Faker contains a generator method faker.helpers.fake
for combining faker API methods using a mustache string format.
console.log(
faker.helpers.fake(
'Hello {{person.prefix}} {{person.lastName}}, how are you today?'
)
);
Faker has support for multiple locales.
The main faker
instance uses the English locale.
But you can also import instances using other locales.
// ESM
import { fakerDE as faker } from '@faker-js/faker';
// CJS
const { fakerDE: faker } = require('@faker-js/faker');
See our documentation for a list of provided languages.
Please note: Not every locale provides data for every module. In our pre-made faker instances, we fall back to English in such a case as this is the most complete and most commonly used language. If you don't want that or prefer a different fallback, you can also build your own instances.
import { de, de_CH, Faker } from '@faker-js/faker';
export const faker = new Faker({
locale: [de_CH, de],
});
If you want consistent results, you can set your own seed:
faker.seed(123);
const firstRandom = faker.number.int();
// Setting the seed again resets the sequence.
faker.seed(123);
const secondRandom = faker.number.int();
console.log(firstRandom === secondRandom);
Faker is an MIT-licensed open source project with its ongoing development made possible entirely by the support of these awesome backers
Please make sure to read the Contributing Guide before making a pull request.
Thanks to all the people who already contributed to Faker!
The fakerjs.dev website is generously hosted by Netlify, with search functionality powered by Algolia.
Detailed changes for each release are documented in the release notes.
Read the team update (January 14th, 2022).