MCPcopy
hub / github.com/faker-js/faker / urlPicsumPhotos

Method urlPicsumPhotos

src/modules/image/index.ts:228–286  ·  view source on GitHub ↗

* Generates a random image url provided via https://picsum.photos. * * @remark This method generates a random string representing an URL from picsum.photos. Faker is not responsible for the content of the image or the service providing it. * * @param options Options for generating a URL

(
    options: {
      /**
       * The width of the image.
       *
       * @default faker.number.int({ min: 1, max: 3999 })
       */
      width?: number;
      /**
       * The height of the image.
       *
       * @default faker.number.int({ min: 1, max: 3999 })
       */
      height?: number;
      /**
       * Whether the image should be grayscale.
       *
       * @default faker.datatype.boolean()
       */
      grayscale?: boolean;
      /**
       * Whether the image should be blurred. `0` disables the blur.
       *
       * @default faker.number.int({ max: 10 })
       */
      blur?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
    } = {}
  )

Source from the content-addressed store, hash-verified

226 * @since 8.0.0
227 */
228 urlPicsumPhotos(
229 options: {
230 /**
231 * The width of the image.
232 *
233 * @default faker.number.int({ min: 1, max: 3999 })
234 */
235 width?: number;
236 /**
237 * The height of the image.
238 *
239 * @default faker.number.int({ min: 1, max: 3999 })
240 */
241 height?: number;
242 /**
243 * Whether the image should be grayscale.
244 *
245 * @default faker.datatype.boolean()
246 */
247 grayscale?: boolean;
248 /**
249 * Whether the image should be blurred. `0` disables the blur.
250 *
251 * @default faker.number.int({ max: 10 })
252 */
253 blur?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
254 } = {}
255 ): string {
256 const {
257 width = this.faker.number.int({ min: 1, max: 3999 }),
258 height = this.faker.number.int({ min: 1, max: 3999 }),
259 grayscale = this.faker.datatype.boolean(),
260 blur = this.faker.number.int({ max: 10 }),
261 } = options;
262
263 let url = `https://picsum.photos/seed/${this.faker.string.alphanumeric({
264 length: { min: 5, max: 10 },
265 })}/${width}/${height}`;
266
267 const hasValidBlur = typeof blur === 'number' && blur >= 1 && blur <= 10;
268
269 if (grayscale || hasValidBlur) {
270 url += '?';
271
272 if (grayscale) {
273 url += `grayscale`;
274 }
275
276 if (grayscale && hasValidBlur) {
277 url += '&';
278 }
279
280 if (hasValidBlur) {
281 url += `blur=${blur}`;
282 }
283 }
284
285 return url;

Callers 3

urlMethod · 0.95
image.spec.tsFile · 0.80
image.spec.tsFile · 0.80

Calls 3

intMethod · 0.80
booleanMethod · 0.80
alphanumericMethod · 0.80

Tested by

no test coverage detected