blob: 8dd777412828623bc44868da5e1abd03ff22a165 (
plain)
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
|
import { ModuleBase } from '../../internal/module-base';
/**
* Converts the given string to title case.
*
* @param text The text to convert.
*/
function toTitleCase(text: string): string {
return text
.split(' ')
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ');
}
/**
* Module for generating food-related data.
*
* ### Overview
*
* This module provides methods to generate various food-related information, such as items on a menu.
* To generate the name of a dish, use [`dish()`](https://fakerjs.dev/api/food.html#dish) and to generate a long description for a dish use [`description()`](https://fakerjs.dev/api/food.html#description). Note that these will not correspond with each other.
* You can also generate individual components of a dish such as [spices](https://fakerjs.dev/api/food.html#spice), [vegetables](https://fakerjs.dev/api/food.html#vegetable), [meats](https://fakerjs.dev/api/food.html#meat), [fruits](https://fakerjs.dev/api/food.html#fruit), or generic [ingredients](https://fakerjs.dev/api/food.html#ingredient).
*/
export class FoodModule extends ModuleBase {
/**
* Generates a random dish adjective.
*
* @example
* faker.food.adjective() // 'crispy'
*
* @since 9.0.0
*/
adjective(): string {
return this.faker.helpers.arrayElement(
this.faker.definitions.food.adjective
);
}
/**
* Generates a random dish description.
*
* @example
* faker.food.description() // 'An exquisite ostrich roast, infused with the essence of longan, slow-roasted to bring out its natural flavors and served with a side of creamy red cabbage'
*
* @since 9.0.0
*/
description(): string {
return this.faker.helpers.fake(
this.faker.definitions.food.description_pattern
);
}
/**
* Generates a random dish name.
*
* @example
* faker.food.dish() // 'Tagine-Rubbed Venison Salad'
*
* @since 9.0.0
*/
dish(): string {
// A 50/50 mix of specific dishes and dish_patterns
if (this.faker.datatype.boolean()) {
return toTitleCase(
this.faker.helpers.fake(this.faker.definitions.food.dish_pattern)
);
}
return toTitleCase(
this.faker.helpers.arrayElement(this.faker.definitions.food.dish)
);
}
/**
* Generates a random food's ethnic category.
*
* @example
* faker.food.ethnicCategory() // 'Italian'
*
* @since 9.0.0
*/
ethnicCategory(): string {
return this.faker.helpers.arrayElement(
this.faker.definitions.food.ethnic_category
);
}
/**
* Generates a random fruit name.
*
* @example
* faker.food.fruit() // 'lemon'
*
* @since 9.0.0
*/
fruit(): string {
return this.faker.helpers.arrayElement(this.faker.definitions.food.fruit);
}
/**
* Generates a random ingredient name.
*
* @example
* faker.food.ingredient() // 'butter'
*
* @since 9.0.0
*/
ingredient(): string {
return this.faker.helpers.arrayElement(
this.faker.definitions.food.ingredient
);
}
/**
* Generates a random meat
*
* @example
* faker.food.meat() // 'venison'
*
* @since 9.0.0
*/
meat(): string {
return this.faker.helpers.arrayElement(this.faker.definitions.food.meat);
}
/**
* Generates a random spice name.
*
* @example
* faker.food.spice() // 'chilli'
*
* @since 9.0.0
*/
spice(): string {
return this.faker.helpers.arrayElement(this.faker.definitions.food.spice);
}
/**
* Generates a random vegetable name.
*
* @example
* faker.food.vegetable() // 'broccoli'
*
* @since 9.0.0
*/
vegetable(): string {
return this.faker.helpers.arrayElement(
this.faker.definitions.food.vegetable
);
}
}
|