Faker

Generate massive amounts of fake data in the browser and node.js

README

Faker

Generate massive amounts of fake (but realistic) data for testing and development.

  
  npm version
  npm downloads
  Continuous Integration
  codecov
  Chat on Discord
  Open Collective
  sponsor
  

⚡️ Try it Online

undefined


🚀 Features


- 💌 Locations - Generate valid looking Addresses, Zip Codes, Street Names, States, and Countries!
- ⏰ Time-based Data - Past, present, future, recent, soon... whenever!
- 🌏 Localization - Set 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.


📦 Install


  1. ``` sh
  2. npm install --save-dev @faker-js/faker
  3. ```

🪄 Usage


  1. ```ts
  2. import { faker } from '@faker-js/faker';
  3. // import { faker } from '@faker-js/faker/locale/de';

  4. export const USERS: User[] = [];

  5. export function createRandomUser(): User {
  6.   return {
  7.     userId: faker.datatype.uuid(),
  8.     username: faker.internet.userName(),
  9.     email: faker.internet.email(),
  10.     avatar: faker.image.avatar(),
  11.     password: faker.internet.password(),
  12.     birthdate: faker.date.birthdate(),
  13.     registeredAt: faker.date.past(),
  14.   };
  15. }

  16. Array.from({ length: 10 }).forEach(() => {
  17.   USERS.push(createRandomUser());
  18. });
  19. ```

💎 Modules


An in-depth overview of the API methods is available in the documentation.
The API covers the following modules:

ModuleExampleOutput
-------------------------------------------------------------------------------------------------------------------------------------------------------
Animal`faker.animal.cat()`Norwegian
Color`faker.color.rgb()`#cdfcdc
Commerce`faker.commerce.product()`Polo
Company`faker.company.companyName()`Zboncak
Database`faker.database.engine()`MyISAM
Datatype`faker.datatype.uuid()`7b16dd12-935e-4acc-8381-b1e457bf0176
Date`faker.date.past()`Sat
Finance`faker.finance.amount()`¥23400
Git`faker.git.commitMessage()`feat:
Hacker`faker.hacker.phrase()`Try
Helpers`faker.helpers.arrayElement(['a',b
Image`faker.image.cats()`https://loremflickr.com/640/480/cats
Internet`faker.internet.domainName()`muddy-neuropathologist.net
Location`faker.location.city()`Lake
Lorem`faker.lorem.paragraph()`Porro
Music`faker.music.genre()`R&B
Person`faker.person.firstName()`Cameron
Phone`faker.phone.phoneNumber()`+1
Random`faker.random.locale()`fr_CA
Science`faker.science.unit()``{
System`faker.system.directoryPath()`/root
Vehicle`faker.vehicle.vehicle()`Lamborghini
Word`faker.word.adjective()`adorable

Templates


Faker contains a generator method faker.helpers.fake for combining faker API methods using a mustache string format.

  1. ```ts
  2. console.log(
  3.   faker.helpers.fake(
  4.     'Hello {{person.prefix}} {{person.lastName}}, how are you today?'
  5.   )
  6. );
  7. ```

🌏 Localization


Faker has support for multiple locales.

The default language locale is set to English.

Setting a new locale is simple:

  1. ```ts
  2. // sets locale to de
  3. faker.locale = 'de';
  4. ```

See our documentation for a list of provided languages

Please note: not every locale provides data for every module. In our pre-made locales, we fallback to English in such a case as this is the most complete and most commonly used language.

⚙️ Setting a randomness seed


If you want consistent results, you can set your own seed:

  1. ```ts
  2. faker.seed(123);

  3. const firstRandom = faker.number.int();

  4. // Setting the seed again resets the sequence.
  5. faker.seed(123);

  6. const secondRandom = faker.number.int();

  7. console.log(firstRandom === secondRandom);
  8. ```

🤝 Sponsors


Faker is an MIT-licensed open source project with its ongoing development made possible entirely by the support of these awesome backers

Sponsors


undefined

Backers


undefined

✨ Contributing


Please make sure to read the Contributing Guide before making a pull request.

📘 Credits


Thanks to all the people who already contributed to Faker!


The fakerjs.dev website is kindly hosted by the Netlify Team. Also the search functionality is powered by algolia.

📝 Changelog


Detailed changes for each release are documented in the release notes.

📜 What happened to the original faker.js?


Read the team update (January 14th, 2022).

🔑 License