How to use faker

Comprehensive faker code examples:

How to use faker.br:

0
1
2
3
4
5
6
7
8
9
10
var faker = require('faker');
var faker = require('faker-br');
var name = faker.name.findName();
var telefone = faker.phone.phoneNumber();
var email = faker.internet.email();
var randomcpf = faker.br.cpf();
const { I } = inject();


module.exports = {

How to use faker.time:

20
21
22
23
24
25
26
27
28
29
                description: faker.random.words(),
                assignees: faker.name.firstName(),
                creator: faker.name.findName(),
                startDate: faker.date.recent(),
                dueDate: faker.date.soon(),
                time: faker.time.recent(),
        },
}

// eslint-disable-next-line no-await-in-loop

How to use faker.animal:

How to use faker.fake:

53
54
55
56
57
58
59
60
61
62
var initialize_member = get_members.then(function(members) {
    if (members[socket.id]) {
        return members[socket.id];
    }

    var username = faker.fake("{{name.firstName}} {{name.lastName}}");
    var member = {
        socket: socket.id,
        username: username,
        avatar: "//api.adorable.io/avatars/30/" + username + '.png'

How to use faker.Faker:

93
94
95
96
97
98
99
100
101
102

```javascript
const { Faker } = require('faker')
const { playwright } = require('playwright')

const faker = new Faker()

async function main() {
  // Launch a browser instance
  const browser = await playwright.chromium.launch()

How to use faker.seed:

29
30
31
32
33
34
35
36
37
38

// we want snapshot tests to use the same random data between runs
let seed = 0;
for (let i = 0; i < currentTest.fullTitle().length; ++i)
  seed += currentTest.fullTitle().charCodeAt(i);
faker.seed(seed);

const sourceFilePath = this.currentTest.file.replace("lib", "src").replace(/\.(jsx?|tsx?)$/, "");
const snapPath = sourceFilePath + ".snap";
chaiJestSnapshot.setFilename(snapPath);

How to use faker.tid:

49
50
51
52
53
54
55
56
57
58
deploymentGroup() {
  return _.sample(DEPLOYMENT_GROUPS);
},

yyyymmdd() {
  return faker.tid.formattedDate('YYYY.MM.DD', 'past', true);
},

formattedDate(format, mode, api) {
  if (!api) {

How to use faker.helpers:

34
35
36
37
38
39
40
41
42
43
  'Legal executive',
  'Planner',
]),
org: faker.company.companyName(),
type: faker.helpers.randomize(['Full time', 'Part time']),
relevantToTeaching: faker.helpers.randomize(['Yes', 'No']),
category: 'job',
startDate: startDate,
isStartDateApproximate: faker.helpers.randomize([true, false, false, false]),
endDate: faker.helpers.randomize([endDate, false]),

How to use faker.vehicle:

19
20
21
22
23
24
25
26
27
28
const realitys = []
const customers = []
for(let index =0; index <= ITEMS_AMOUNT; index++) {
    const reality = new reality({
        id: faker.random.uuid(),
        name: faker.vehicle.model(),
        available: true,
        hasSmith: true,
        releaseYear: faker.date.past().getFullYear()
    })

How to use faker.js:

7
8
9
10
11
12
13
14
15
16

faker.js 是用于生成伪造数据的 JavaScript 库。 伪数据在构建和测试我们的应用时很有用。 faker.js 可以为各个领域生成伪造数据,包括地址,商业,公司,日期,财务,图像,随机数或名称。

在本教程中,我们在 Node 应用中使用 faker.js。

## 安装 faker.js

首先,我们安装 faker.js。

```js

How to use faker.hacker:

230
231
232
233
234
235
236
237
238
239
const faker = require('faker');

module.exports = () => ({
  messages: [...Array(3)].map((value, index) => ({
    id: index + 1,
    name: faker.hacker.noun(),
    status: faker.hacker.adjective(),
    description: faker.hacker.phrase(),
  })),
});

How to use faker.finance:

7
8
9
10
11
12
13
14
15
16
id: faker.random.uuid(),
name: faker.company.companyName(),
contact: faker.phone.phoneNumber(),
address: faker.address.streetAddress(),
tin: faker.finance.iban(),
sss: faker.finance.iban(),
philhealth: faker.finance.iban(),
isDeleted: 0,
// TODO: we need to make sure to match company to the user
createdBy: '48e40a9c-c5e9-4d63-9aba-b77cdf4ca67b',

How to use faker.commerce:

84
85
86
87
88
89
90
91
92
93
  passwordAlgorithm: 'sha512',
  passwordHash: '52a0bbed619cccf9cc7e7001d9c7cd4034d031560254899f698189f1441c92933e4231d7594b532247b54b327c518f7967894013568dbce129738362ad4b09e3​​​​​',
  passwordSalt: '8b9fc31b-1a2a-4453-94e2-00ce54be04e6',
  organization: faker.company.companyName(),
  location: faker.address.city(),
  softwareName: faker.commerce.product(),
  description: faker.commerce.productName(),
  contactPerson: `${contactPerson.firstName} ${contactPerson.lastName}`,
  contactPersonEmail: faker.internet.email(contactPerson.firstName, contactPerson.lastName)
})

How to use faker.phone:

4
5
6
7
8
9
10
11
12
13
const numberCompanies = range(0, 5)
const populateCompany = compose(
  map(() => ({
    id: faker.random.uuid(),
    name: faker.company.companyName(),
    contact: faker.phone.phoneNumber(),
    address: faker.address.streetAddress(),
    tin: faker.finance.iban(),
    sss: faker.finance.iban(),
    philhealth: faker.finance.iban(),

How to use faker.image:

215
216
217
218
219
220
221
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
email: 'test@user.com',
title: faker.name.jobTitle(),
// profileImageUrl: 'https://www.gravatar.com/avatar/' + Mongoose.Types.ObjectId().toString() + '?r=PG&d=robohash',
profileImageUrl: faker.image.avatar(),
password: password,

How to use faker.company:

3
4
5
6
7
8
9
10
11
12
module.exports = () => {
  const numberCompanies = range(0, 5)
  const populateCompany = compose(
    map(() => ({
      id: faker.random.uuid(),
      name: faker.company.companyName(),
      contact: faker.phone.phoneNumber(),
      address: faker.address.streetAddress(),
      tin: faker.finance.iban(),
      sss: faker.finance.iban(),

How to use faker.date:

30
31
32
33
34
35
36
37
38
39
// });

// INSERTING DATA TAKE 2
// var person = {
//     email: faker.internet.email(),
//     created_at: faker.date.past()
// };

// var end_result = connection.query('INSERT INTO users SET ?', person, function(err, result) {
//   if (err) throw err;

How to use faker.address:

9
10
11
12
13
14
15
16
17
18
const fs = require('fs');

function populate(gender = 'masculino', memberOrAssist = 'Assistente') {
    const member = {
        name: faker.name.findName(),
        address: faker.address.streetAddress(),
        email: faker.internet.email(),
        status: faker.random.boolean(),
        gender: gender,
        birth: formatISO(faker.date.between(new Date(01, 01, 1940), new Date()), 'yyyy-MM-dd'),

How to use faker.datatype:

4
5
6
7
8
9
10
11
12
13

faker.seed(24849320);
function getRandomValues(nestLevel) {
  return Array(faker.datatype.number(1000) + 1)
  .fill(1)
  .map(e => faker.datatype.number());
}

let values;
function setValues () {

How to use faker.lorem:

14
15
16
17
18
19
20
21
22
23
    phoneProp: 'phone',
},
{
    availability: 0,
    brand: 'apple',
    description: faker.lorem.sentences(3),
    id: '48e51f536c8a',
    image: 'phone_48e51f536c8a.png',
    name: 'iPhone 12x Pro 256GB',
    price: 1379,

How to use faker.internet:

48
49
50
51
52
53
54
55
56
57

for (let id=1; id <= 100; id++) {

    let firstName = faker.name.firstName()
    let lastName = faker.name.lastName()
    let email = faker.internet.email()

    users.push({
        "id": id,
        "first_name": firstName,

How to use faker.name:

211
212
213
214
215
216
217
218
219
220

Log.log('seeding users')
users = [
  {
    firstName: faker.name.firstName(),
    lastName: faker.name.lastName(),
    email: 'test@user.com',
    title: faker.name.jobTitle(),
    // profileImageUrl: 'https://www.gravatar.com/avatar/' + Mongoose.Types.ObjectId().toString() + '?r=PG&d=robohash',
    profileImageUrl: faker.image.avatar(),

How to use faker.random:

2
3
4
5
6
7
8
9
10
11

module.exports = () => {
  const numberCompanies = range(0, 5)
  const populateCompany = compose(
    map(() => ({
      id: faker.random.uuid(),
      name: faker.company.companyName(),
      contact: faker.phone.phoneNumber(),
      address: faker.address.streetAddress(),
      tin: faker.finance.iban(),