Skip to content

入门

¥Getting Started

概述

¥Overview

Faker 是一个流行的库,可以生成虚假(但合理)的数据,可用于以下用途:

¥Faker is a popular library that generates fake (but reasonable) data that can be used for things such as:

  • 单元测试

    ¥Unit Testing

  • 性能测试

    ¥Performance Testing

  • 构建演示

    ¥Building Demos

  • 在没有完整后端的情况下工作

    ¥Working without a completed backend

Faker 最初是用 Perl 编写的,这是 JavaScript 端口。Faker 也可用作 RubyJavaPython 的库。

¥Faker was originally written in Perl and this is the JavaScript port. Faker is also available as a library for Ruby, Java, and Python.

本文档仅涵盖 Faker 的 JavaScript 实现。

¥This documentation only covers the JavaScript implementation of Faker.

环境

¥Environments

你可以在浏览器或 Node.js 中运行 Faker。Faker v9.0 需要 Node.js 版本 18 或更高版本。ESM 和 CommonJS 导入均可用。

¥You can run Faker in the browser, or in Node.js. Faker v9.0 requires Node.js version 18 or above. Both ESM and CommonJS imports are available.

安装

¥Installation

使用你最喜欢的包管理器将其安装为开发依赖。

¥Install it as a Dev Dependency using your favorite package manager.

shell
npm install @faker-js/faker --save-dev
shell
pnpm add @faker-js/faker --save-dev
shell
yarn add @faker-js/faker --dev

Faker 模块

¥Faker Modules

Faker 有三种类型的模块:

¥Faker has three types of modules:

  • 基本数据类型的模块:datatypedatenumberstring

    ¥Modules for basic datatypes: datatype, date, number and string

  • 特定主题的模块,例如 animalfood 等等

    ¥Topic specific modules, such as animal, food and many more

  • 最后,helpers 模块,具有各种实用方法可用于你自己的数据(或由其他 Faker 方法生成的数据)

    ¥Lastly, the helpers module, with various utility methods to use with your own data (or data generated by other Faker methods)

有关模块的完整列表,请转到我们的 Api 搜索 页面。

¥For a full list of modules, go to our Api Search page.

如果你想了解如何使用 Faker,请转到我们的 使用指南 页面。

¥If you would like to know how to use Faker, go to our Usage Guide page.

社区

¥Community

如果你有疑问或需要帮助,请通过 DiscordGitHub 讨论 联系社区。

¥If you have questions or need help, reach out to the community via Discord and GitHub Discussions.

你可以在 Awesome Faker 上看到与 Faker 社区相关的精彩内容。

¥You can see awesome things related to the Faker community at Awesome Faker.

Faker v9.8 中文网 - 粤ICP备13048890号.