UNPKG

5.24 kBJavaScriptView Raw
1/**
2 *
3 * @namespace lorempixel
4 * @memberof faker.image
5 */
6var Lorempixel = function (faker) {
7
8 var self = this;
9
10 /**
11 * image
12 *
13 * @param {number} width
14 * @param {number} height
15 * @param {boolean} randomize
16 * @method faker.image.lorempixel.image
17 */
18 self.image = function (width, height, randomize) {
19 var categories = ["abstract", "animals", "business", "cats", "city", "food", "nightlife", "fashion", "people", "nature", "sports", "technics", "transport"];
20 return self[faker.random.arrayElement(categories)](width, height, randomize);
21 };
22 /**
23 * avatar
24 *
25 * @method faker.image.lorempixel.avatar
26 */
27 self.avatar = function () {
28 return faker.internet.avatar();
29 };
30 /**
31 * imageUrl
32 *
33 * @param {number} width
34 * @param {number} height
35 * @param {string} category
36 * @param {boolean} randomize
37 * @method faker.image.lorempixel.imageUrl
38 */
39 self.imageUrl = function (width, height, category, randomize) {
40 var width = width || 640;
41 var height = height || 480;
42
43 var url ='https://lorempixel.com/' + width + '/' + height;
44 if (typeof category !== 'undefined') {
45 url += '/' + category;
46 }
47
48 if (randomize) {
49 url += '?' + faker.datatype.number()
50 }
51
52 return url;
53 };
54 /**
55 * abstract
56 *
57 * @param {number} width
58 * @param {number} height
59 * @param {boolean} randomize
60 * @method faker.image.lorempixel.abstract
61 */
62 self.abstract = function (width, height, randomize) {
63 return faker.image.lorempixel.imageUrl(width, height, 'abstract', randomize);
64 };
65 /**
66 * animals
67 *
68 * @param {number} width
69 * @param {number} height
70 * @param {boolean} randomize
71 * @method faker.image.lorempixel.animals
72 */
73 self.animals = function (width, height, randomize) {
74 return faker.image.lorempixel.imageUrl(width, height, 'animals', randomize);
75 };
76 /**
77 * business
78 *
79 * @param {number} width
80 * @param {number} height
81 * @param {boolean} randomize
82 * @method faker.image.lorempixel.business
83 */
84 self.business = function (width, height, randomize) {
85 return faker.image.lorempixel.imageUrl(width, height, 'business', randomize);
86 };
87 /**
88 * cats
89 *
90 * @param {number} width
91 * @param {number} height
92 * @param {boolean} randomize
93 * @method faker.image.lorempixel.cats
94 */
95 self.cats = function (width, height, randomize) {
96 return faker.image.lorempixel.imageUrl(width, height, 'cats', randomize);
97 };
98 /**
99 * city
100 *
101 * @param {number} width
102 * @param {number} height
103 * @param {boolean} randomize
104 * @method faker.image.lorempixel.city
105 */
106 self.city = function (width, height, randomize) {
107 return faker.image.lorempixel.imageUrl(width, height, 'city', randomize);
108 };
109 /**
110 * food
111 *
112 * @param {number} width
113 * @param {number} height
114 * @param {boolean} randomize
115 * @method faker.image.lorempixel.food
116 */
117 self.food = function (width, height, randomize) {
118 return faker.image.lorempixel.imageUrl(width, height, 'food', randomize);
119 };
120 /**
121 * nightlife
122 *
123 * @param {number} width
124 * @param {number} height
125 * @param {boolean} randomize
126 * @method faker.image.lorempixel.nightlife
127 */
128 self.nightlife = function (width, height, randomize) {
129 return faker.image.lorempixel.imageUrl(width, height, 'nightlife', randomize);
130 };
131 /**
132 * fashion
133 *
134 * @param {number} width
135 * @param {number} height
136 * @param {boolean} randomize
137 * @method faker.image.lorempixel.fashion
138 */
139 self.fashion = function (width, height, randomize) {
140 return faker.image.lorempixel.imageUrl(width, height, 'fashion', randomize);
141 };
142 /**
143 * people
144 *
145 * @param {number} width
146 * @param {number} height
147 * @param {boolean} randomize
148 * @method faker.image.lorempixel.people
149 */
150 self.people = function (width, height, randomize) {
151 return faker.image.lorempixel.imageUrl(width, height, 'people', randomize);
152 };
153 /**
154 * nature
155 *
156 * @param {number} width
157 * @param {number} height
158 * @param {boolean} randomize
159 * @method faker.image.lorempixel.nature
160 */
161 self.nature = function (width, height, randomize) {
162 return faker.image.lorempixel.imageUrl(width, height, 'nature', randomize);
163 };
164 /**
165 * sports
166 *
167 * @param {number} width
168 * @param {number} height
169 * @param {boolean} randomize
170 * @method faker.image.lorempixel.sports
171 */
172 self.sports = function (width, height, randomize) {
173 return faker.image.lorempixel.imageUrl(width, height, 'sports', randomize);
174 };
175 /**
176 * technics
177 *
178 * @param {number} width
179 * @param {number} height
180 * @param {boolean} randomize
181 * @method faker.image.lorempixel.technics
182 */
183 self.technics = function (width, height, randomize) {
184 return faker.image.lorempixel.imageUrl(width, height, 'technics', randomize);
185 };
186 /**
187 * transport
188 *
189 * @param {number} width
190 * @param {number} height
191 * @param {boolean} randomize
192 * @method faker.image.lorempixel.transport
193 */
194 self.transport = function (width, height, randomize) {
195 return faker.image.lorempixel.imageUrl(width, height, 'transport', randomize);
196 }
197}
198
199module["exports"] = Lorempixel;