GithubHelp home page GithubHelp logo

flower-f / faker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from faker-js/faker

0.0 0.0 0.0 25.38 MB

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

Home Page: https://fakerjs.dev

License: Other

JavaScript 0.09% TypeScript 99.91%

faker's Introduction

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.

Version Website
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 - 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

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

The above code indicates a basic usage of Faker. The point of interest is the import statements at the top. The first import indicates how one can import the entirety of Faker, which includes every locale, while the commented-out import showcases how to import only a single locale. In most situations, importing a single locale is preferable for performance because some testing frameworks reload imports for every test file, which causes startup latencies to add up quickly. Thus, limiting the import to a single locale can speed up startup times.

💎 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 { Faker, de, de_CH } 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

faker's People

Contributors

bryandonovan avatar cliffpyles avatar damienwebdev avatar fariborzemami avatar fotoverite avatar fzn0x avatar glyad avatar hankucz avatar import-brain avatar jayliu50 avatar jessicasachs avatar josefsalyer avatar jreina avatar jsoref avatar lucasjellema avatar mandulaj avatar marak avatar matthewmayer avatar moosh-be avatar pkuczynski avatar prinx avatar renovate[bot] avatar robscotts4rb avatar shinigami92 avatar st-ddt avatar stichoza avatar tylerreichle avatar umairjibran avatar van100j avatar xdivisionbyzerox avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.