faker README

The project's README from github.com/faker-js/faker. As one markdown file: README.md.

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
v11 (next) https://next.fakerjs.dev/
v10 (stable) https://fakerjs.dev/
v9 (old) https://v9.fakerjs.dev/

🚀 Features

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(),
    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 v10 (stable) and v11 (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. If you are using faker.date methods, there are additional considerations. See Reproducible Results.

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

faker (faker-js/faker)

Searching Database…

15.5K ·GitHub
这是做什么用的?Faker 是一个 JavaScript/TypeScript 库,可以生成大量逼真的假数据——姓名、地址、日期、财务记录等——用于测试和开发,在浏览器和 Node.js 中都能用。
它是需要导入到自己代码里的库,还是在线服务?是一个库:你从 npm 安装它,然后在 JavaScript 或 TypeScript 代码中直接调用它的生成方法。如果你不想安装任何东西,也可以用 StackBlitz 在线试玩。
怎么把它加到项目里?从 npm 安装 @faker-js/faker 包(通常作为开发依赖),然后导入 faker 实例。文档在 fakerjs.dev 上;v10 是当前的稳定版本,v11 是下一个版本。
我的环境需要满足什么条件才能运行它?需要 Node.js ^22.13.0、^23.5.0 或 >=24,并搭配 npm 10 或更新版本。这个包没有任何运行时依赖,不会给你的依赖树增加其他东西。
它生成的数据一定能看出是假的吗?不一定——Faker 有意生成看起来很真实的数据,所以生成的姓名、地址、邮箱和电话号码可能碰巧属于真实的人。README 提醒不要用你的测试环境给这些人发消息或打电话。
我可以免费在商业项目中使用它吗?可以——Faker 是采用 MIT 许可证的开源项目,其持续开发由赞助者和支持者资助。
它能生成哪些类型的数据?个人信息(姓名、性别、个人简介、职位)、位置信息(地址、邮政编码、街道名、州、国家)、日期(过去、现在、未来、最近、即将到来)、财务信息(账户信息、交易记录、加密货币地址)、电商信息(价格、产品名、形容词、描述)、'hacker' 风格的俏皮话,还有随机数字和字符串。
它能生成其他语言的数据吗?可以——支持 70 多种语言区域。主实例使用英语;要生成其他语言的数据,需要导入对应语言区域的实例。并不是每种语言区域都覆盖所有模块,预置实例在缺少数据时会回退到英语,不过你可以自己构建实例并指定不同的回退语言。
每次运行能得到相同的'随机'数据吗?可以——设置你自己的随机种子后,结果就是稳定且可复现的。README 提到,给 faker.date 系列方法设置种子时还有一些额外注意事项。
原来的 faker.js 后来怎么样了?README 中链接了一篇 2022 年 1 月 14 日的团队更新说明来解释这件事。该项目如今由 faker-js 组织继续维护,文档、发行说明和变更日志都在 fakerjs.dev 上。
Creator
faker-js
Size
32.7 MB
Stars
15.5K
Age
4y
Commits · 90 Days