Git Product home page Git Product logo

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
v9 (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

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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

faker's Issues

`random.word()` can return undesirable non-alpha characters

Describe the bug

The pool of strings from which random.words() pulls values includes strings that have parentheses, e.g. Cocos (Keeling) Islands and Killer Whale (Orca). This can result in (Keeling) and (Orca) being returned.

There's a larger problem here of non-alphabetic characters being returned in words. Obviously some non-alpha characters are desired in words, e.g. -, but some are not. We should decide on the set of acceptable characters that word() can return and regex the others out.

Reproduction

Mock faker.fake with the above mentioned values and you can see the bad returns.

Additional Info

Use word methods in `random.word()`

Clear and concise description of the problem

As a developer, I want random.word() to draw from the entire pool of appropriate words.

Suggested solution

Add the word methods (word.noun, word.verb, etc.) to the pool from which random.word() pulls.

faker/lib/random.js

Lines 150 to 182 in 9506122

var wordMethods = [
'commerce.department',
'commerce.productName',
'commerce.productAdjective',
'commerce.productMaterial',
'commerce.product',
'commerce.color',
'company.catchPhraseAdjective',
'company.catchPhraseDescriptor',
'company.catchPhraseNoun',
'company.bsAdjective',
'company.bsBuzz',
'company.bsNoun',
'address.streetSuffix',
'address.county',
'address.country',
'address.state',
'finance.accountName',
'finance.transactionType',
'finance.currencyName',
'hacker.noun',
'hacker.verb',
'hacker.adjective',
'hacker.ingverb',
'hacker.abbreviation',
'name.jobDescriptor',
'name.jobArea',
'name.jobType',
];

Alternative

These words might be transitively included via some other method, I'm not sure.

Additional context

No response

Publish old versions of `faker` as `@faker-js/faker`

I've pulled all of these tar balls from the registry and added them to the v6.0.0-alpha.0 release. I've also verified the checksums of the files I pulled against the registry and additionally uploaded them to the release.

I performed the check by doing:

curl https://registry.npmjs.org/faker | jq  '.versions["VERSION"].dist.shasum'

and comparing against the versions I pulled from NPM. Others can verify these against the checksums I put in the 6.0.0-alpha.0 release.

Version Registry URL Tarball Registry Checksum Github Mirror Tarball Github Checksum
5.5.3 5.5.3 c57974ee484431b25205c2c8dc09fda861e51e0e 5.5.3 c57974ee484431b25205c2c8dc09fda861e51e0e
5.5.2 5.5.2 d6f99923fb757b26733a6d2396ddb448ac5bb446 5.5.2 d6f99923fb757b26733a6d2396ddb448ac5bb446
5.5.1 5.5.1 30e4e8ba15c8c08d0494ba935f247d8e2469675d 5.5.1 30e4e8ba15c8c08d0494ba935f247d8e2469675d
5.5.0 5.5.0 17922f6252cd44c732943c89c2f0f0c7e189ffe3 5.5.0 17922f6252cd44c732943c89c2f0f0c7e189ffe3
5.4.0 5.4.0 f18e55993c6887918182b003d163df14daeb3011 5.4.0 f18e55993c6887918182b003d163df14daeb3011
5.3.1 5.3.1 67f8f5c170b97a76b875389e0e8b9155da7b4853 5.3.1 67f8f5c170b97a76b875389e0e8b9155da7b4853
5.3.0 5.3.0 fd98c2d86d134776d837b342d3a431ac06eb078c 5.3.0 fd98c2d86d134776d837b342d3a431ac06eb078c
5.2.0 5.2.0 5ee7ca475737eda8cf59c0cbaae5f5068e668dd9 5.2.0 5ee7ca475737eda8cf59c0cbaae5f5068e668dd9
5.1.0 5.1.0 e10fa1dec4502551aee0eb771617a7e7b94692e8 5.1.0 e10fa1dec4502551aee0eb771617a7e7b94692e8
5.0.0 5.0.0 ceaf8120e37994007d6fb0e73479bef0406bfe74 5.0.0 ceaf8120e37994007d6fb0e73479bef0406bfe74
4.1.0 4.1.0 1e45bbbecc6774b3c195fad2835109c6d748cc3f 4.1.0 1e45bbbecc6774b3c195fad2835109c6d748cc3f
4.0.0 4.0.0 fecb0a7a5fc950bc93377688498c67145dc135c8 4.0.0 fecb0a7a5fc950bc93377688498c67145dc135c8
3.1.0 3.1.0 0f908faf4e6ec02524e54a57e432c5c013e08c9f 3.1.0 0f908faf4e6ec02524e54a57e432c5c013e08c9f
3.0.1 3.0.1 c36278cd423f3c5375bc270466a223485c0e7bb2 3.0.1 c36278cd423f3c5375bc270466a223485c0e7bb2
3.0.0 3.0.0 ee9f7a3f40c15f68b9402088aa8f18a0ce4da00e 3.0.0 ee9f7a3f40c15f68b9402088aa8f18a0ce4da00e
2.1.5 2.1.5 e07f8bff5e1262e67fd5193fca0785f4ca681150 2.1.5 e07f8bff5e1262e67fd5193fca0785f4ca681150
2.1.4 2.1.4 c6e665cc42332e874cc03da5f697a35ff5bfb65b 2.1.4 c6e665cc42332e874cc03da5f697a35ff5bfb65b
2.1.3 2.1.3 f294edd7d79b41b40f49986643e7107758534305 2.1.3 f294edd7d79b41b40f49986643e7107758534305
2.1.2 2.1.2 78b607f68d92b745d9c80b35066cfd4a1b66f1e5 2.1.2 78b607f68d92b745d9c80b35066cfd4a1b66f1e5
2.1.1 2.1.1 ae2cc245a34635e2e9af4477b997c5f7db4a4b1d 2.1.1 ae2cc245a34635e2e9af4477b997c5f7db4a4b1d
2.1.0 2.1.0 ea5eb0719dd38771bef800f39043fe632d88a8c5 2.1.0 ea5eb0719dd38771bef800f39043fe632d88a8c5
2.0.3 2.0.3 a4da598e9649f89d8f2b2be6f9169d1ad7eb251e 2.0.3 a4da598e9649f89d8f2b2be6f9169d1ad7eb251e
2.0.2 N/A
2.0.1 2.0.1 b7eaba5a1d17eda37389332dbbef9de7e96a1812 2.0.1 b7eaba5a1d17eda37389332dbbef9de7e96a1812
2.0.0 N/A N/A
1.1.0 1.1.0 230738ebd37edad9de4a421de12922bd8206a872 1.1.0 230738ebd37edad9de4a421de12922bd8206a872
1.0.1 1.0.1 da38a8e6366621a042c21d51bb647cf034596eea 1.0.1 da38a8e6366621a042c21d51bb647cf034596eea
1.0.0 1.0.0 c8516d64fc0f0f07acc4215202e5ad3908d52578 1.0.0 c8516d64fc0f0f07acc4215202e5ad3908d52578

Merge `@luciferreeves/blaver` to this repo

Hello,

A few days ago, I received an issue on @luciferreeves/blaver to merge the project with this repo and maintain this project instead. Now, I'm not going to try and read the tea leaves and figure out what the future looks like. The question for me was, "Do I maintain the repo alone or move to a more community based approach?" I thought the answer was obvious and that I can maintain blaver, but now I'm convinced of the opposite.

I pondered over the question for a few days and I thought, its much easier to contribute to a public repository rather than a repo that I handle myself. I would continue to improve faker.js but I think it's much better if I do this here.

So, I would like to retire/archive the repo and update the readme of the project once I have a confirmation here and I would deprecate the package on NPM, and link to release of faker-js/faker.

I also registered a domain (blaver.dev), which I can point to fakerjs.dev, if you guys want that. Let me know what you think.

Willing to help..

It looks like you are attempting to turn this into a community-controlled package, which is a great idea given recent events. Since I've been using it at my day job I'd be willing to pitch in and help. FWIW I'm already mentioned in the README, as I wrote the Perl Data::Faker package that it's based on...

types: random.arrayElement (and probably others) should support ReadonlyArray

Describe the bug

the new types in 6.0.0-alpha.3 (thanks!) don't handle cases where the DT types allowed ReadonlyArray, e.g. random.arrayElement.

Reproduction

import faker from '@faker-js/faker'

const items = ['one', 'two', 'three'] as const

const pick = faker.random.arrayElement(items)

also note, that the other way around would be fine:

https://www.typescriptlang.org/play?#code/CYUwxgNghgTiAEAzArgOzAFwJYHtX1higE8BRCEAWxFQwB4AVAPgAosMqBnALngEEYRYoyYBKXgwBQksHk4Z4cKMDwRiAofAC88ANoByPCH0AaePowB3HKfMYAFnGMBdAp3izU86YRLkqNBgsSiqoahokotIA9NHwALSJ0qCQsAgo6Nh4iiDKquqCfhTUtCJsHJQ88ABKuaHhhcLM4vBSMnIKvsTaeoaoxmYW1rYWjiAu0iH5EWTFgSxdokA

Additional Info

No response

Commit package lock file

faker.js's history is one of the best examples why it's useful to commit the package lock file.
This stabilizes also CI

Update .github/FUNDING.yml

This currently mirrors the original settings from https://github.com/marak/Faker.js/ which means that github is displaying Marak as the sponsorable individual on this repo's page:
image
and on issue pages:
image

Since this fork is trying to provide a version of the tool with a new set of maintainers you probably want to update this. See https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/displaying-a-sponsor-button-in-your-repository for details.

docs(demo): Create a demo website

Clear and concise description of the problem

Currently, in the README the Demo is still marked as Coming soon.

Suggested solution

We could build a small demo website that allows users to:

  1. See the different generators and their options
  2. Play with the different options and see the result live
  3. Allow the result of the generator to be one-click copied in the clipboard
  4. Generates the relevant code and allow it to be one-click copied for quick usage in their own code

We could use a Vite/React or Vite/Svelte website as we have @Shinigami92 in our team. 😃

As Faker is also usable in Node.js, should we have a demo CLI tool? Or a faker-cli? Not sure it's related to this issue though.

Alternative

No response

Additional context

No response

Discord Community Server

Create and link a Discord community server.

(If you need a moderator for the start and initial setup, I can help)

Change or remove FUNDING.yml?

Currently the FUNDING.yml points to Marak (previous author whom is now banned from github).

Maybe this should be updated or removed?

build: add src to .npmignore

Describe the bug

I was releasing 6.0.0-alpha.3 and I noticed that the src folder is in the distributable package.

Reproduction

Run npm pack and review the subsequent tarball.

Additional Info

No response

chore: determine the purpose and usage of various test helpers

test/support/chai.js 
test/support/function-helpers.js 
test/support/luhnCheck.js 
test/support/sinon-1.5.2.js 
test/support/walk_dir.js 

Are a few files in the codebase that I haven't reviewed, but I think are worth investigating whether they can be replaced with::

  1. A more modern tool
  2. A dev dep

Notify all existing contributors to Marak/faker.js of new repo

Dear fellow contributors, we're targeting this repo as the long-term home of Faker.js. We're refing you as contributors so that you can update your codebases, projects, etc that may use Faker. We're hoping to provide a stable place for the future of Faker.

We plan on releasing the tarballs of the faker npm package as @faker-js/faker at the same exact content and version as was previously released for faker.

Expect this to happen in the next few days.

cc:

@FotoVerite
@BryanDonovan
@UmairJibran
@fariborzemami
@jsoref
@tylerreichle
@Moosh-be
@cliffpyles
@Stichoza
@prinx
@jayliu50
@josefsalyer
@lucasjellema
@van100j
@mrstebo
@robscotts4rb
@mandulaj
@jreina
@lbuerste
@vivekseth
@glyad
@portse
@chinclubi
@MoonWalker0
@sbmart
@titonobre
@Aleyasen
@richardbutler
@hkal
@AlmazN
@LoLFactor
@DimitarChristoff
@ducin
@ad-walker
@strobelt
@andrewmcoupe
@aweary

Will this continue as source of the Faker library? #1

@Geertvdc asked in https://github.com/withshepherd/faker.js/issues/1#issue-1094203363:

I noticed this morning that the original faker repo and npm package were all removed or emptied (https://github.com/Marak/Faker.js). Looking for a fork or alternative I bumped into this.

Will you continue building / supporting faker.js? Do you need any help? Could you elaborate on the plans? Did you know Marak?

I think Faker.js by Marak was a well used library and it would be a shame if it would go away. I would love helping out in getting this back up if you need any help.

Continuing conversation here

Update MIT license holder

I know almost nothing about legalities, but it looks like Marak Squires still holds the copyright rights to the forked code, according to the MIT-LICENSE.txt

faker/MIT-LICENSE.txt

Lines 1 to 3 in 9506122

faker.js - Copyright (c) 2020
Marak Squires
http://github.com/marak/faker.js/

The original repo was not deleted for unknown reasons

Describe the bug

The original repo was not deleted for unknown reasons.
That was also an attempt to show private companies that open source developers also need support. Doing this is probably not what the community wants. It also is kind disrespectful with the creators of faker, as it does not help them at all.

Reproduction

something

Additional Info

No response

Fix the site description and meta tags for fakerjs.dev

Describe the bug

When you link https://fakerjs.dev in chats like Discord or on Twitter, it won't render any rich preview or site description.

Reproduction

Screen Shot 2022-01-13 at 3 19 22 AM

Additional Info

The rich preview currently has no creative to show. This is okay. Please use a placeholder image (any placeholder image). Maybe an abstract geometric background :-)

address.streetAddress() doesn't use locale.address.street_address template

Describe the bug

In fact, most of the locale.address.* properties seems to be unused. Am I missing something, is this being used somewhere else, or should I open a PR and propose a fix?

Reproduction

faker.setLocale('nb_NO');
// should print "#{street_name} #{building_number}" - i.e. "Some street 123", not "123 Some street"
console.log(faker.address.streetAddress()); 

Additional Info

No response

Document as own website

Serve a documentation as own website.

We could e.g. use VitePress for that.
Happy to help if decision was made what to use for that website.
For now it would be enough to use gh-pages.

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.