Socket
Socket
Sign inDemoInstall

@faker-js/faker

Package Overview
Dependencies
0
Maintainers
4
Versions
63
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @faker-js/faker

Generate massive amounts of fake contextual data


Version published
Maintainers
4
Install size
9.69 MB
Created

Package description

What is @faker-js/faker?

The @faker-js/faker package is a powerful tool for generating massive amounts of fake (but realistic) data for various purposes such as testing, bootstrapping databases, and creating rich prototypes. It can create data for names, addresses, phone numbers, and much more.

What are @faker-js/faker's main functionalities?

Basic random data generation

Generate random names, addresses, and other basic personal information.

const { faker } = require('@faker-js/faker');
console.log(faker.name.findName()); // Generates a random name

Localization

Support for localized data, allowing generation of data that is locale-specific.

const { faker } = require('@faker-js/faker');
faker.locale = 'de';
console.log(faker.name.findName()); // Generates a random name with German locale

Random numbers

Create random numbers, including options for specifying ranges and precision.

const { faker } = require('@faker-js/faker');
console.log(faker.datatype.number()); // Generates a random number

Date and time

Generate random dates and times, with the ability to specify past or future dates.

const { faker } = require('@faker-js/faker');
console.log(faker.date.future()); // Generates a random future date

Internet-related data

Create fake internet data such as email addresses, domain names, and URLs.

const { faker } = require('@faker-js/faker');
console.log(faker.internet.email()); // Generates a random email address

Commerce data

Generate commerce-related data like product names, prices, and categories.

const { faker } = require('@faker-js/faker');
console.log(faker.commerce.productName()); // Generates a random product name

Images

Create URLs for random placeholder images.

const { faker } = require('@faker-js/faker');
console.log(faker.image.imageUrl()); // Generates a random image URL

Other packages similar to @faker-js/faker

Changelog

Source

8.4.1 (2024-02-06)

  • JSDocs improvements

Readme

Source

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

⚠️ 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.

VersionWebsite
v8.* (next)https://next.fakerjs.dev/
v8 (stable)https://fakerjs.dev/
v7 (old)https://v7.fakerjs.dev/

🚀 Features

  • 💌 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.

📦 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(): User {
  return {
    userId: faker.string.uuid(),
    username: faker.internet.userName(),
    email: faker.internet.email(),
    avatar: faker.image.avatar(),
    password: faker.internet.password(),
    birthdate: faker.date.birthdate(),
    registeredAt: faker.date.past(),
  };
}

export const USERS: User[] = faker.helpers.multiple(createRandomUser, {
  count: 5,
});

💎 Modules

An in-depth overview of the API methods is available in the documentation for v8 (stable) and v8.* (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 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

MIT

Keywords

FAQs

Last updated on 08 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc