* Generates a random image url. * * @remark This method generates a random string representing an URL from an external provider. Faker is not responsible for the content of the image or the service providing it. * * @param options Options for generating a URL for an image. * @param op
(
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;
} = {}
)
| 117 | * @since 8.0.0 |
| 118 | */ |
| 119 | url( |
| 120 | options: { |
| 121 | /** |
| 122 | * The width of the image. |
| 123 | * |
| 124 | * @default faker.number.int({ min: 1, max: 3999 }) |
| 125 | */ |
| 126 | width?: number; |
| 127 | /** |
| 128 | * The height of the image. |
| 129 | * |
| 130 | * @default faker.number.int({ min: 1, max: 3999 }) |
| 131 | */ |
| 132 | height?: number; |
| 133 | } = {} |
| 134 | ): string { |
| 135 | const { |
| 136 | width = this.faker.number.int({ min: 1, max: 3999 }), |
| 137 | height = this.faker.number.int({ min: 1, max: 3999 }), |
| 138 | } = options; |
| 139 | |
| 140 | const urlMethod = this.faker.helpers.arrayElement([ |
| 141 | ({ width, height }: { width?: number; height?: number }) => |
| 142 | this.urlPicsumPhotos({ width, height, grayscale: false, blur: 0 }), |
| 143 | // Other providers may be added back here in future versions. |
| 144 | ]); |
| 145 | |
| 146 | return urlMethod({ width, height }); |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Generates a random image url provided via https://loremflickr.com. |
no test coverage detected