Faker.js

website·Indexed 38 days ago

https://fakerjs.dev/

A library for generating fake data with extensive support for multiple locales, including Polish, Portuguese, Slovak, Thai, Turkish, Urdu, Ukrainian, Russian, Swedish, and many others.

Tokens
91.3K
Snippets
669
Records
736
Agent score
72%

What's inside Faker

  1. Overview of Faker library capabilities

    Faker is a JavaScript library used to generate realistic fake data. It is commonly used for unit testing, performance testing, building demos, and developing front-end features when a backend is not yet available.
  2. Overview of the Location module

    The faker.location module (which replaced faker.address in v8.0.0) generates random address and location data. All outputs are tied to the current locale. For common street addresses, use streetAddress(), city(), state(), and zipCode(). For geographic coordinates, use latitude(), longitude(), or nearbyGPSCoordinate().
  3. Overview of the Location module

    The faker.location module provides methods to generate random addresses, geographic data, and location-based information. It replaces the faker.address module used prior to version 8.0.0. All generated data is tied to the current locale. For common street addresses, use a combination of streetAddress(), city(), state(), and zipCode().
  4. Overview of the Finance module

    The faker.finance module provides utilities to generate mock data for finance and money-related entries, including random currency amounts, traditional bank account details (account numbers, BIC, IBAN), credit card information (numbers, CVV, issuers), and blockchain addresses (Bitcoin, Ethereum, Litecoin).
  5. Overview of the Company module

    The faker.company module is used to generate company-related entries. For related needs, use faker.commerce for products and commerce, or faker.finance for finance-related entries.
  6. Overview of book data generation in Faker

    The faker.book module provides several methods for generating book-related entries. All values may be localized. For specific needs, use the following mappings:

    • Random title: faker.book.title()
    • Random existing author: faker.book.author()
    • Random non-existing author: faker.person.fullName()
    • Random genre: faker.book.genre()
    • Random series: faker.book.series()
    • Random publisher: faker.book.publisher()
    • Random format: faker.book.format()
    • Random ISBN: faker.commerce.isbn()
  7. Overview of the faker.person module

    The faker.person module (formerly faker.name prior to v8.0.0) is used to generate personal information such as names, job titles, and profile details. It supports locale-specific name patterns and optional sex-based filtering ('male', 'female', or 'generic') for many of its methods.
  8. Generate random book data using the Book module

    The faker.book module provides a set of methods to generate localized book-related strings. For ISBNs, use faker.commerce.isbn(). For non-existing author names, use faker.person.fullName().
  9. Generate random vehicle names and types

    The faker.vehicle module provides methods to generate various components of a vehicle's identity. A full vehicle name is typically a combination of a manufacturer and a model.
  10. Generate random animal types and species using the Animal module

    The faker.animal module provides methods to generate random animal-related strings. All values returned by these methods can be localized. For a general animal type (e.g., 'dog'), use the type() method. For specific breeds or species, use the dedicated methods for that animal group.
  11. Use Distributors to control value distribution in Faker

    A Distributor is a function that determines the distribution of generated values. While standard randomizers are uniformly distributed, a distributor can bias results toward the minimum or maximum of a range. The distributor returns a value between 0 and 1, which is then processed by the calling function. For example, a distributor result of 0.5 passed to faker.number.int({ min: 10, max: 20 }) will result in 15.
    import { Distributor, Randomizer, faker } from '@faker-js/faker';
    
    // Example: Always return the minimum value
    const alwaysMin: Distributor = () => 0;
    faker.number.int({ min: 2, max: 10, distributor: alwaysMin }); // 2
    
    // Example: Standard uniform distribution
    const uniform: Distributor = (randomizer: Randomizer) => randomizer.next();
    faker.number.int({ min: 0, max: 10, distributor: uniform }); // Random value between 0-10
  12. Generate random music data using the Faker Music module

    The faker.music module provides a set of functions to generate random music-related strings. These functions are useful for creating mock data for music applications and all returned data types can be localized.