-
-
Notifications
You must be signed in to change notification settings - Fork 880
/
vehicle.ts
170 lines (157 loc) · 3.99 KB
/
vehicle.ts
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
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);
}
// TODO @Shinigami92 2022-01-13: Find better strategy
// @ts-expect-error
this.vehicle.schema = {
description: 'Generates a random vehicle.',
sampleResults: ['BMW Explorer', 'Ford Camry', 'Lamborghini Ranchero'],
};
// @ts-expect-error
this.manufacturer.schema = {
description: 'Generates a manufacturer name.',
sampleResults: ['Ford', 'Jeep', 'Tesla'],
};
// @ts-expect-error
this.model.schema = {
description: 'Generates a vehicle model.',
sampleResults: ['Explorer', 'Camry', 'Ranchero'],
};
// @ts-expect-error
this.type.schema = {
description: 'Generates a vehicle type.',
sampleResults: ['Coupe', 'Convertable', 'Sedan', 'SUV'],
};
// @ts-expect-error
this.fuel.schema = {
description: 'Generates a fuel type.',
sampleResults: ['Electric', 'Gasoline', 'Diesel'],
};
// @ts-expect-error
this.vin.schema = {
description: 'Generates a valid VIN number.',
sampleResults: ['YV1MH682762184654', '3C7WRMBJ2EG208836'],
};
// @ts-expect-error
this.color.schema = {
description: 'Generates a color',
sampleResults: ['red', 'white', 'black'],
};
// @ts-expect-error
this.vrm.schema = {
description: 'Generates a vehicle vrm',
sampleResults: ['MF56UPA', 'GL19AAQ', 'SF20TTA'],
};
// @ts-expect-error
this.bicycle.schema = {
description: 'Generates a type of bicycle',
sampleResults: [
'Adventure Road Bicycle',
'City Bicycle',
'Recumbent Bicycle',
],
};
}
/**
* vehicle
*
* @method faker.vehicle.vehicle
*/
vehicle(): string {
return fake('{{vehicle.manufacturer}} {{vehicle.model}}');
}
/**
* manufacturer
*
* @method faker.vehicle.manufacturer
*/
manufacturer(): string {
return this.faker.random.arrayElement(
this.faker.definitions.vehicle.manufacturer
);
}
/**
* model
*
* @method faker.vehicle.model
*/
model(): string {
return this.faker.random.arrayElement(this.faker.definitions.vehicle.model);
}
/**
* type
*
* @method faker.vehicle.type
*/
type(): string {
return this.faker.random.arrayElement(this.faker.definitions.vehicle.type);
}
/**
* fuel
*
* @method faker.vehicle.fuel
*/
fuel(): string {
return this.faker.random.arrayElement(this.faker.definitions.vehicle.fuel);
}
/**
* vin
*
* @method faker.vehicle.vin
*/
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();
}
/**
* color
*
* @method faker.vehicle.color
*/
color(): string {
return fake('{{commerce.color}}');
}
/**
* vrm
*
* @method faker.vehicle.vrm
*/
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();
}
/**
* bicycle
*
* @method faker.vehicle.bicycle
*/
bicycle(): string {
return this.faker.random.arrayElement(
this.faker.definitions.vehicle.bicycle_type
);
}
}