..
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128 | import type { Faker } from '.';
import type { Fake } from './fake';
let fake: Fake['fake'];
export class Vehicle {
constructor(private readonly faker: Faker) {
fake = faker.fake;
// Bind `this` so namespaced is working correctly
for (const name of Object.getOwnPropertyNames(Vehicle.prototype)) {
if (name === 'constructor' || typeof this[name] !== 'function') {
continue;
}
this[name] = this[name].bind(this);
}
}
/**
* Returns a random vehicle.
*
* @example
* faker.vehicle.vehicle() // 'BMW Explorer'
*/
vehicle(): string {
return fake('{{vehicle.manufacturer}} {{vehicle.model}}');
}
/**
* Returns a manufacturer name.
*
* @example
* faker.vehicle.manufacturer() // 'Ford'
*/
manufacturer(): string {
return this.faker.random.arrayElement(
this.faker.definitions.vehicle.manufacturer
);
}
/**
* Returns a vehicle model.
*
* @example
* faker.vehicle.model() // 'Explorer'
*/
model(): string {
return this.faker.random.arrayElement(this.faker.definitions.vehicle.model);
}
/**
* Returns a vehicle type.
*
* @example
* faker.vehicle.type() // 'Coupe'
*/
type(): string {
return this.faker.random.arrayElement(this.faker.definitions.vehicle.type);
}
/**
* Returns a fuel type.
*
* @example
* faker.vehicle.fuel() // 'Electric'
*/
fuel(): string {
return this.faker.random.arrayElement(this.faker.definitions.vehicle.fuel);
}
/**
* Returns a vehicle identification number (VIN).
*
* @example
* faker.vehicle.vin() // 'YV1MH682762184654'
*/
vin(): string {
const bannedChars = ['o', 'i', 'q'];
return (
this.faker.random.alphaNumeric(10, { bannedChars: bannedChars }) +
this.faker.random.alpha({
count: 1,
upcase: true,
bannedChars: bannedChars,
}) +
this.faker.random.alphaNumeric(1, { bannedChars: bannedChars }) +
this.faker.datatype.number({ min: 10000, max: 100000 })
) // return five digit #
.toUpperCase();
}
/**
* Returns a vehicle color.
*
* @example
* faker.vehicle.color() // 'red'
*/
color(): string {
return fake('{{commerce.color}}');
}
/**
* Returns a vehicle registration number (Vehicle Registration Mark - VRM)
*
* @example
* faker.vehicle.vrm() // 'MF56UPA'
*/
vrm(): string {
return (
this.faker.random.alpha({ count: 2, upcase: true }) +
this.faker.datatype.number({ min: 0, max: 9 }) +
this.faker.datatype.number({ min: 0, max: 9 }) +
this.faker.random.alpha({ count: 3, upcase: true })
).toUpperCase();
}
/**
* Returns a type of bicycle.
*
* @example
* faker.vehicle.bicycle() // 'Adventure Road Bicycle'
*/
bicycle(): string {
return this.faker.random.arrayElement(
this.faker.definitions.vehicle.bicycle_type
);
}
}
|
|