Skip to content

Commit 82eb2f8

Browse files
committed
refactor: use assertLocaleData in src
1 parent 4c6cfd5 commit 82eb2f8

21 files changed

Lines changed: 553 additions & 136 deletions

File tree

src/modules/airline/index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ export class AirlineModule extends ModuleBase {
8989
*/
9090
airport(): Airport {
9191
return this.faker.helpers.arrayElement(
92-
this.faker.definitions.airline.airport
92+
assertLocaleData(
93+
this.faker.fakerCore.locale.airline?.airport,
94+
'airline.airport'
95+
)
9396
);
9497
}
9598

@@ -103,7 +106,10 @@ export class AirlineModule extends ModuleBase {
103106
*/
104107
airline(): Airline {
105108
return this.faker.helpers.arrayElement(
106-
this.faker.definitions.airline.airline
109+
assertLocaleData(
110+
this.faker.fakerCore.locale.airline?.airline,
111+
'airline.airline'
112+
)
107113
);
108114
}
109115

@@ -117,7 +123,10 @@ export class AirlineModule extends ModuleBase {
117123
*/
118124
airplane(): Airplane {
119125
return this.faker.helpers.arrayElement(
120-
this.faker.definitions.airline.airplane
126+
assertLocaleData(
127+
this.faker.fakerCore.locale.airline?.airplane,
128+
'airline.airplane'
129+
)
121130
);
122131
}
123132

src/modules/animal/index.ts

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ export class AnimalModule extends ModuleBase {
2222
* @since 5.5.0
2323
*/
2424
dog(): string {
25-
return this.faker.helpers.arrayElement(this.faker.definitions.animal.dog);
25+
return this.faker.helpers.arrayElement(
26+
assertLocaleData(this.faker.fakerCore.locale.animal?.dog, 'animal.dog')
27+
);
2628
}
2729

2830
/**
@@ -34,7 +36,9 @@ export class AnimalModule extends ModuleBase {
3436
* @since 5.5.0
3537
*/
3638
cat(): string {
37-
return this.faker.helpers.arrayElement(this.faker.definitions.animal.cat);
39+
return this.faker.helpers.arrayElement(
40+
assertLocaleData(this.faker.fakerCore.locale.animal?.cat, 'animal.cat')
41+
);
3842
}
3943

4044
/**
@@ -46,7 +50,12 @@ export class AnimalModule extends ModuleBase {
4650
* @since 5.5.0
4751
*/
4852
snake(): string {
49-
return this.faker.helpers.arrayElement(this.faker.definitions.animal.snake);
53+
return this.faker.helpers.arrayElement(
54+
assertLocaleData(
55+
this.faker.fakerCore.locale.animal?.snake,
56+
'animal.snake'
57+
)
58+
);
5059
}
5160

5261
/**
@@ -58,7 +67,9 @@ export class AnimalModule extends ModuleBase {
5867
* @since 5.5.0
5968
*/
6069
bear(): string {
61-
return this.faker.helpers.arrayElement(this.faker.definitions.animal.bear);
70+
return this.faker.helpers.arrayElement(
71+
assertLocaleData(this.faker.fakerCore.locale.animal?.bear, 'animal.bear')
72+
);
6273
}
6374

6475
/**
@@ -70,7 +81,9 @@ export class AnimalModule extends ModuleBase {
7081
* @since 5.5.0
7182
*/
7283
lion(): string {
73-
return this.faker.helpers.arrayElement(this.faker.definitions.animal.lion);
84+
return this.faker.helpers.arrayElement(
85+
assertLocaleData(this.faker.fakerCore.locale.animal?.lion, 'animal.lion')
86+
);
7487
}
7588

7689
/**
@@ -83,7 +96,10 @@ export class AnimalModule extends ModuleBase {
8396
*/
8497
cetacean(): string {
8598
return this.faker.helpers.arrayElement(
86-
this.faker.definitions.animal.cetacean
99+
assertLocaleData(
100+
this.faker.fakerCore.locale.animal?.cetacean,
101+
'animal.cetacean'
102+
)
87103
);
88104
}
89105

@@ -96,7 +112,12 @@ export class AnimalModule extends ModuleBase {
96112
* @since 5.5.0
97113
*/
98114
horse(): string {
99-
return this.faker.helpers.arrayElement(this.faker.definitions.animal.horse);
115+
return this.faker.helpers.arrayElement(
116+
assertLocaleData(
117+
this.faker.fakerCore.locale.animal?.horse,
118+
'animal.horse'
119+
)
120+
);
100121
}
101122

102123
/**
@@ -108,7 +129,9 @@ export class AnimalModule extends ModuleBase {
108129
* @since 5.5.0
109130
*/
110131
bird(): string {
111-
return this.faker.helpers.arrayElement(this.faker.definitions.animal.bird);
132+
return this.faker.helpers.arrayElement(
133+
assertLocaleData(this.faker.fakerCore.locale.animal?.bird, 'animal.bird')
134+
);
112135
}
113136

114137
/**
@@ -120,7 +143,9 @@ export class AnimalModule extends ModuleBase {
120143
* @since 5.5.0
121144
*/
122145
cow(): string {
123-
return this.faker.helpers.arrayElement(this.faker.definitions.animal.cow);
146+
return this.faker.helpers.arrayElement(
147+
assertLocaleData(this.faker.fakerCore.locale.animal?.cow, 'animal.cow')
148+
);
124149
}
125150

126151
/**
@@ -132,7 +157,9 @@ export class AnimalModule extends ModuleBase {
132157
* @since 5.5.0
133158
*/
134159
fish(): string {
135-
return this.faker.helpers.arrayElement(this.faker.definitions.animal.fish);
160+
return this.faker.helpers.arrayElement(
161+
assertLocaleData(this.faker.fakerCore.locale.animal?.fish, 'animal.fish')
162+
);
136163
}
137164

138165
/**
@@ -145,7 +172,10 @@ export class AnimalModule extends ModuleBase {
145172
*/
146173
crocodilia(): string {
147174
return this.faker.helpers.arrayElement(
148-
this.faker.definitions.animal.crocodilia
175+
assertLocaleData(
176+
this.faker.fakerCore.locale.animal?.crocodilia,
177+
'animal.crocodilia'
178+
)
149179
);
150180
}
151181

@@ -159,7 +189,10 @@ export class AnimalModule extends ModuleBase {
159189
*/
160190
insect(): string {
161191
return this.faker.helpers.arrayElement(
162-
this.faker.definitions.animal.insect
192+
assertLocaleData(
193+
this.faker.fakerCore.locale.animal?.insect,
194+
'animal.insect'
195+
)
163196
);
164197
}
165198

@@ -173,7 +206,10 @@ export class AnimalModule extends ModuleBase {
173206
*/
174207
rabbit(): string {
175208
return this.faker.helpers.arrayElement(
176-
this.faker.definitions.animal.rabbit
209+
assertLocaleData(
210+
this.faker.fakerCore.locale.animal?.rabbit,
211+
'animal.rabbit'
212+
)
177213
);
178214
}
179215

@@ -187,7 +223,10 @@ export class AnimalModule extends ModuleBase {
187223
*/
188224
rodent(): string {
189225
return this.faker.helpers.arrayElement(
190-
this.faker.definitions.animal.rodent
226+
assertLocaleData(
227+
this.faker.fakerCore.locale.animal?.rodent,
228+
'animal.rodent'
229+
)
191230
);
192231
}
193232

@@ -200,7 +239,9 @@ export class AnimalModule extends ModuleBase {
200239
* @since 5.5.0
201240
*/
202241
type(): string {
203-
return this.faker.helpers.arrayElement(this.faker.definitions.animal.type);
242+
return this.faker.helpers.arrayElement(
243+
assertLocaleData(this.faker.fakerCore.locale.animal?.type, 'animal.type')
244+
);
204245
}
205246

206247
/**
@@ -213,7 +254,10 @@ export class AnimalModule extends ModuleBase {
213254
*/
214255
petName(): string {
215256
return this.faker.helpers.arrayElement(
216-
this.faker.definitions.animal.pet_name
257+
assertLocaleData(
258+
this.faker.fakerCore.locale.animal?.pet_name,
259+
'animal.pet_name'
260+
)
217261
);
218262
}
219263
}

src/modules/book/index.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ export class BookModule extends ModuleBase {
2727
* @since 9.1.0
2828
*/
2929
author(): string {
30-
return this.faker.helpers.arrayElement(this.faker.definitions.book.author);
30+
return this.faker.helpers.arrayElement(
31+
assertLocaleData(this.faker.fakerCore.locale.book?.author, 'book.author')
32+
);
3133
}
3234

3335
/**
@@ -39,7 +41,9 @@ export class BookModule extends ModuleBase {
3941
* @since 9.1.0
4042
*/
4143
format(): string {
42-
return this.faker.helpers.arrayElement(this.faker.definitions.book.format);
44+
return this.faker.helpers.arrayElement(
45+
assertLocaleData(this.faker.fakerCore.locale.book?.format, 'book.format')
46+
);
4347
}
4448

4549
/**
@@ -51,7 +55,9 @@ export class BookModule extends ModuleBase {
5155
* @since 9.1.0
5256
*/
5357
genre(): string {
54-
return this.faker.helpers.arrayElement(this.faker.definitions.book.genre);
58+
return this.faker.helpers.arrayElement(
59+
assertLocaleData(this.faker.fakerCore.locale.book?.genre, 'book.genre')
60+
);
5561
}
5662

5763
/**
@@ -64,7 +70,10 @@ export class BookModule extends ModuleBase {
6470
*/
6571
publisher(): string {
6672
return this.faker.helpers.arrayElement(
67-
this.faker.definitions.book.publisher
73+
assertLocaleData(
74+
this.faker.fakerCore.locale.book?.publisher,
75+
'book.publisher'
76+
)
6877
);
6978
}
7079

@@ -77,7 +86,9 @@ export class BookModule extends ModuleBase {
7786
* @since 9.1.0
7887
*/
7988
series(): string {
80-
return this.faker.helpers.arrayElement(this.faker.definitions.book.series);
89+
return this.faker.helpers.arrayElement(
90+
assertLocaleData(this.faker.fakerCore.locale.book?.series, 'book.series')
91+
);
8192
}
8293

8394
/**
@@ -89,6 +100,8 @@ export class BookModule extends ModuleBase {
89100
* @since 9.1.0
90101
*/
91102
title(): string {
92-
return this.faker.helpers.arrayElement(this.faker.definitions.book.title);
103+
return this.faker.helpers.arrayElement(
104+
assertLocaleData(this.faker.fakerCore.locale.book?.title, 'book.title')
105+
);
93106
}
94107
}

src/modules/color/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ export class ColorModule extends ModuleBase {
218218
* @since 7.0.0
219219
*/
220220
human(): string {
221-
return this.faker.helpers.arrayElement(this.faker.definitions.color.human);
221+
return this.faker.helpers.arrayElement(
222+
assertLocaleData(this.faker.fakerCore.locale.color?.human, 'color.human')
223+
);
222224
}
223225

224226
/**
@@ -231,7 +233,9 @@ export class ColorModule extends ModuleBase {
231233
* @since 7.0.0
232234
*/
233235
space(): string {
234-
return this.faker.helpers.arrayElement(this.faker.definitions.color.space);
236+
return this.faker.helpers.arrayElement(
237+
assertLocaleData(this.faker.fakerCore.locale.color?.space, 'color.space')
238+
);
235239
}
236240

237241
/**

src/modules/commerce/index.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ export class CommerceModule extends ModuleBase {
100100
*/
101101
department(): string {
102102
return this.faker.helpers.arrayElement(
103-
this.faker.definitions.commerce.department
103+
assertLocaleData(
104+
this.faker.fakerCore.locale.commerce?.department,
105+
'commerce.department'
106+
)
104107
);
105108
}
106109

@@ -113,7 +116,10 @@ export class CommerceModule extends ModuleBase {
113116
* @since 3.0.0
114117
*/
115118
productName(): string {
116-
const patterns = this.faker.definitions.commerce.product_name.pattern;
119+
const patterns = assertLocaleData(
120+
this.faker.fakerCore.locale.commerce?.product_name,
121+
'commerce.product_name'
122+
).pattern;
117123
return this.faker.helpers.fake(patterns);
118124
}
119125

@@ -223,7 +229,10 @@ export class CommerceModule extends ModuleBase {
223229
*/
224230
productAdjective(): string {
225231
return this.faker.helpers.arrayElement(
226-
this.faker.definitions.commerce.product_name.adjective
232+
assertLocaleData(
233+
this.faker.fakerCore.locale.commerce?.product_name,
234+
'commerce.product_name'
235+
).adjective
227236
);
228237
}
229238

@@ -237,7 +246,10 @@ export class CommerceModule extends ModuleBase {
237246
*/
238247
productMaterial(): string {
239248
return this.faker.helpers.arrayElement(
240-
this.faker.definitions.commerce.product_name.material
249+
assertLocaleData(
250+
this.faker.fakerCore.locale.commerce?.product_name,
251+
'commerce.product_name'
252+
).material
241253
);
242254
}
243255

@@ -251,7 +263,10 @@ export class CommerceModule extends ModuleBase {
251263
*/
252264
product(): string {
253265
return this.faker.helpers.arrayElement(
254-
this.faker.definitions.commerce.product_name.product
266+
assertLocaleData(
267+
this.faker.fakerCore.locale.commerce?.product_name,
268+
'commerce.product_name'
269+
).product
255270
);
256271
}
257272

@@ -265,7 +280,10 @@ export class CommerceModule extends ModuleBase {
265280
*/
266281
productDescription(): string {
267282
return this.faker.helpers.fake(
268-
this.faker.definitions.commerce.product_description
283+
assertLocaleData(
284+
this.faker.fakerCore.locale.commerce?.product_description,
285+
'commerce.product_description'
286+
)
269287
);
270288
}
271289

0 commit comments

Comments
 (0)