..
Viewing
index.md
90 lines (60 loc) • 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90 | # Getting Started
## Overview
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 was originally written in [Perl](https://metacpan.org/dist/Data-Faker) and this is the JavaScript port. Language bindings also exist for [Ruby](https://github.com/faker-ruby/faker), [Java](https://github.com/DiUS/java-faker), and [Python](https://github.com/joke2k/faker).
This documentation only covers the JavaScript implementation of Faker.
## Environments
You can run Faker in the Browser, within Node, or the many other languages supported by Faker. ([Perl](https://metacpan.org/dist/Data-Faker), [Ruby](https://github.com/faker-ruby/faker), [Java](https://github.com/DiUS/java-faker), and [Python](https://github.com/joke2k/faker))
## Installation
Install it as a Dev Dependency using your favorite package manager.
```shell
npm install @faker-js/faker --save-dev
```
or
```shell
yarn add @faker-js/faker --dev
```
or
```shell
pnpm add @faker-js/faker --save-dev
```
## Usage
### Node.js
```js
import faker from '@faker-js/faker';
const randomName = faker.name.findName(); // Rowan Nikolaus
const randomEmail = faker.internet.email(); // [email protected]
const randomCard = faker.helpers.createCard(); // An object representing a random contact card containing many properties
```
### Browser
```html
<script type="text/javascript" src="https://unpkg.com/@faker-js/faker"></script>
<script>
// Caitlyn Kerluke
const randomName = faker.name.findName();
// [email protected]
const randomEmail = faker.internet.email();
// An object representing a random contact card
// containing many properties
const randomCard = faker.helpers.createCard();
</script>
```
:::tip Note
Using the browser is great for experimenting 👍. However, due to all of the strings Faker uses to generate fake data, **Faker is a large package**. It's `> 5 MiB` minified. **Please avoid deploying Faker in your web app.**
:::
### Deno
```js
import { faker } from 'https://cdn.skypack.dev/@faker-js/faker';
const randomName = faker.name.findName(); // Willie Bahringer
const randomEmail = faker.internet.email(); // [email protected]
const randomCard = faker.helpers.createCard(); // random contact card containing many properties
```
:::tip Note
It is highly recommended to use version tags when importing libraries in Deno, e.g: `import { faker } from "https://cdn.skypack.dev/@faker-js/[email protected]"`. Add `?dts` to import with type definitions: `import { faker } from "https://cdn.skypack.dev/@faker-js/[email protected]?dts"`.
:::
## Community
If you have questions or need help, reach out to the community via [Discord](https://chat.fakerjs.dev) and [GitHub Discussions](https://github.com/faker-js/faker/discussions).
|
|