JSPM

  • Created
  • Published
  • Downloads 8952170
  • Score
    100M100P100Q233899F
  • License MIT

Generate massive amounts of fake contextual data

Package Exports

  • @faker-js/faker
  • @faker-js/faker/locale/af_ZA
  • @faker-js/faker/locale/ar
  • @faker-js/faker/locale/az
  • @faker-js/faker/locale/base
  • @faker-js/faker/locale/bn_BD
  • @faker-js/faker/locale/cs_CZ
  • @faker-js/faker/locale/cy
  • @faker-js/faker/locale/da
  • @faker-js/faker/locale/de
  • @faker-js/faker/locale/de_AT
  • @faker-js/faker/locale/de_CH
  • @faker-js/faker/locale/dv
  • @faker-js/faker/locale/el
  • @faker-js/faker/locale/en
  • @faker-js/faker/locale/en_AU
  • @faker-js/faker/locale/en_AU_ocker
  • @faker-js/faker/locale/en_BORK
  • @faker-js/faker/locale/en_CA
  • @faker-js/faker/locale/en_GB
  • @faker-js/faker/locale/en_GH
  • @faker-js/faker/locale/en_HK
  • @faker-js/faker/locale/en_IE
  • @faker-js/faker/locale/en_IN
  • @faker-js/faker/locale/en_NG
  • @faker-js/faker/locale/en_US
  • @faker-js/faker/locale/en_ZA
  • @faker-js/faker/locale/eo
  • @faker-js/faker/locale/es
  • @faker-js/faker/locale/es_MX
  • @faker-js/faker/locale/fa
  • @faker-js/faker/locale/fi
  • @faker-js/faker/locale/fr
  • @faker-js/faker/locale/fr_BE
  • @faker-js/faker/locale/fr_CA
  • @faker-js/faker/locale/fr_CH
  • @faker-js/faker/locale/fr_LU
  • @faker-js/faker/locale/fr_SN
  • @faker-js/faker/locale/he
  • @faker-js/faker/locale/hr
  • @faker-js/faker/locale/hu
  • @faker-js/faker/locale/hy
  • @faker-js/faker/locale/id_ID
  • @faker-js/faker/locale/it
  • @faker-js/faker/locale/ja
  • @faker-js/faker/locale/ka_GE
  • @faker-js/faker/locale/ko
  • @faker-js/faker/locale/lv
  • @faker-js/faker/locale/mk
  • @faker-js/faker/locale/nb_NO
  • @faker-js/faker/locale/ne
  • @faker-js/faker/locale/nl
  • @faker-js/faker/locale/nl_BE
  • @faker-js/faker/locale/pl
  • @faker-js/faker/locale/pt_BR
  • @faker-js/faker/locale/pt_PT
  • @faker-js/faker/locale/ro
  • @faker-js/faker/locale/ro_MD
  • @faker-js/faker/locale/ru
  • @faker-js/faker/locale/sk
  • @faker-js/faker/locale/sr_RS_latin
  • @faker-js/faker/locale/sv
  • @faker-js/faker/locale/ta_IN
  • @faker-js/faker/locale/th
  • @faker-js/faker/locale/tr
  • @faker-js/faker/locale/uk
  • @faker-js/faker/locale/ur
  • @faker-js/faker/locale/uz_UZ_latin
  • @faker-js/faker/locale/vi
  • @faker-js/faker/locale/yo_NG
  • @faker-js/faker/locale/zh_CN
  • @faker-js/faker/locale/zh_TW
  • @faker-js/faker/locale/zu_ZA
  • @faker-js/faker/package.json

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

Open in StackBlitz

📙 API Documentation

🚀 Features

  • 🧍 Person - Generate Names, Genders, Bios, Job titles, and more.
  • 📍 Location - Generate Addresses, Zip Codes, Street Names, States, and Countries!
  • ⏰ Date - Past, present, future, recent, soon... whenever!
  • 💸 Finance - Create stubbed out Account Details, Transactions, and Crypto Addresses.
  • 👠 Commerce - Generate Prices, Product Names, Adjectives, and Descriptions.
  • 👾 Hacker - “Try to reboot the SQL bus, maybe it will bypass the virtual application!”
  • 🔢 Number and String - Of course, we can also generate random numbers and strings.
  • 🌏 Localization - Pick from over 60 locales to generate realistic looking Names, Addresses, and Phone Numbers.

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

npm install --save-dev @faker-js/faker

🪄 Usage

// 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,
});

💎 Modules

An in-depth overview of the API methods is available in the documentation for v9 (stable) and v9.* (next).

Templates

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?'
  )
);

🌏 Localization

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],
});

⚙️ Setting a randomness seed

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

🤝 Sponsors

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

Sponsors

Backers

✨ 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 generously hosted by Netlify, with search functionality 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

MIT