Skip to content

Commit

Permalink
fix: 🐞 change random image service
Browse files Browse the repository at this point in the history
This changes the URL returned by randImg() from placeimg.com to
picsum.photos.

BREAKING CHANGE: 🧨 "category" option will not work anymore
  • Loading branch information
maper89 committed Apr 4, 2023
1 parent 81b572f commit dbcaf14
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions packages/falso/src/lib/img.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import { fake, FakeOptions } from './core/core';
interface ImgOptions extends FakeOptions {
width?: number;
height?: number;
category?: Category;
grayscale?: boolean;
}

type Category = 'animals' | 'arch' | 'nature' | 'people' | 'tech';

/**
* Generate a random img.
*
Expand All @@ -21,18 +19,30 @@ type Category = 'animals' | 'arch' | 'nature' | 'people' | 'tech';
*
* randImg({ length: 10 })
*
* @example
*
* randImg({ width: 300 }) // default is "height" or 500 (if not set either)
*
* @example
*
* randImg({ height: 200 }) // default is "width" or 500 (if not set either)
*
* @example
*
* randImg({ grayscale: true }) // return a grayscale image (default is false)
*
*/
export function randImg<Options extends ImgOptions = never>(options?: Options) {
const [width, height, category] = [
options?.width ?? 500,
options?.height ?? 500,
options?.category ?? '',
const [width, height, grayscale] = [
options?.width ?? options?.height ?? 500,
options?.height ?? options?.width ?? 500,
options?.grayscale ?? false,
];

return fake(
() =>
`https://placeimg.com/${width}/${height}${
category ? `/${category}` : category
`https://picsum.photos/${width}/${height}${
grayscale ? '?grayscale' : ''
}`,
options
);
Expand Down

0 comments on commit dbcaf14

Please sign in to comment.