Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add image_providers jsdocs #612

Merged
merged 3 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 39 additions & 32 deletions src/image_providers/lorempicsum.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import type { Faker } from '..';

/**
* Module to generate links to random images on `https://picsum.photos/`.
*/
// TODO ST-DDT 2022-03-11: Rename to picsum?
export class LoremPicsum {
constructor(private readonly faker: Faker) {}

/**
* Search image from unsplash
* Generates a new picsum image url.
*
* @param width
* @param height
* @param grayscale
* @param blur 1-10
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param grayscale Whether to return a grayscale image. Default to `false`.
* @param blur The optional level of blur to apply. Supports `1` - `10`.
*/
image(
width?: number,
Expand All @@ -21,22 +25,22 @@ export class LoremPicsum {
}

/**
* Search grayscale image from unsplash
* Generates a new picsum image url.
*
* @param width
* @param height
* @param grayscale
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param grayscale Whether to return a grayscale image. Default to `false`.
*/
imageGrayscale(width?: number, height?: number, grayscale?: boolean): string {
return this.imageUrl(width, height, grayscale);
}

/**
* Search blurred image from unsplash
* Generates a new picsum image url.
*
* @param width
* @param height
* @param blur 1-10
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param blur The optional level of blur to apply. Supports `1` - `10`.
*/
imageBlurred(
width?: number,
Expand All @@ -47,13 +51,13 @@ export class LoremPicsum {
}

/**
* Search same random image from unsplash, based on a seed
* Generates a new picsum image url.
*
* @param width
* @param height
* @param grayscale
* @param blur 1-10
* @param seed
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param grayscale Whether to return a grayscale image. Default to `false`.
* @param blur The optional level of blur to apply. Supports `1` - `10`.
* @param seed The optional seed to use.
*/
imageRandomSeeded(
width?: number,
Expand All @@ -62,35 +66,38 @@ export class LoremPicsum {
blur?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10,
seed?: string
): string {
// TODO ST-DDT 2022-03-11: This method does the same as image url, maybe generate a seed, if it is missig?
return this.imageUrl(width, height, grayscale, blur, seed);
}

/**
* avatar
* Returns a random avatar url.
*
* @example
* faker.internet.avatar()
* // 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/315.jpg'
*/
// TODO ST-DDT 2022-03-11: Deprecate this method as it is duplicate as has nothing to do with lorempicsum.
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
avatar(): string {
return this.faker.internet.avatar();
}

/**
* imageUrl
* Generates a new picsum image url.
*
* @param width
* @param height
* @param grayscale
* @param blur 1-10
* @param seed
* @param width The width of the image. Defaults to `640`.
* @param height The height of the image. Defaults to `480`.
* @param grayscale Whether to return a grayscale image. Default to `false`.
* @param blur The optional level of blur to apply. Supports `1` - `10`.
* @param seed The optional seed to use.
*/
imageUrl(
width?: number,
height?: number,
grayscale?: boolean,
width = 640,
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
height = 480,
grayscale = false,
blur?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10,
seed?: string
): string {
width = width || 640;
height = height || 480;

let url = 'https://picsum.photos';

if (seed) {
Expand Down
Loading