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

refactor(image): deprecate urlPlaceholder #3341

Merged
merged 2 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 15 additions & 6 deletions src/modules/image/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ export class ImageModule extends ModuleBase {
* Generates a random image url provided via https://via.placeholder.com/.
*
* @param options Options for generating a URL for an image.
* @param options.width The width of the image. Defaults to a random number between 1 and 3999.
* @param options.height The height of the image. Defaults to a random number between 1 and 3999.
* @param options.width The width of the image. Defaults to a random number between 1 and 3500.
* @param options.height The height of the image. Defaults to a random number between 1 and 3500.
* @param options.backgroundColor The background color of the image. Defaults to a random hex color.
* @param options.textColor The text color of the image. Defaults to a random hex color.
* @param options.format The format of the image. Defaults to a random format.
Expand All @@ -259,19 +259,21 @@ export class ImageModule extends ModuleBase {
* faker.image.urlPlaceholder({ width: 128, height: 128, backgroundColor: '000000', textColor: 'FF0000', format: 'png', text: 'lorem ipsum' }) // 'https://via.placeholder.com/128x128/000000/FF0000.png?text=lorem+ipsum'
*
* @since 8.0.0
*
* @deprecated The service has bad uptime. Use `url()` or another method instead.
*/
urlPlaceholder(
options: {
/**
* The width of the image.
*
* @default faker.number.int({ min: 1, max: 3999 })
* @default faker.number.int({ min: 1, max: 3500 })
*/
width?: number;
/**
* The height of the image.
*
* @default faker.number.int({ min: 1, max: 3999 })
* @default faker.number.int({ min: 1, max: 3500 })
*/
height?: number;
/**
Expand Down Expand Up @@ -300,9 +302,16 @@ export class ImageModule extends ModuleBase {
text?: string;
} = {}
): string {
deprecated({
deprecated: 'faker.image.urlPlaceholder()',
proposed: 'faker.image.url()',
since: '9.4.0',
until: '10.0.0',
});

const {
width = this.faker.number.int({ min: 1, max: 3999 }),
height = this.faker.number.int({ min: 1, max: 3999 }),
width = this.faker.number.int({ min: 1, max: 3500 }),
height = this.faker.number.int({ min: 1, max: 3500 }),
backgroundColor = this.faker.color.rgb({ format: 'hex', prefix: '' }),
textColor = this.faker.color.rgb({ format: 'hex', prefix: '' }),
format = this.faker.helpers.arrayElement([
Expand Down
1 change: 1 addition & 0 deletions test/integration/modules/image.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ describe('image', () => {

describe('urlPlaceholder', () => {
it('should return a random image url from Placeholder', async () => {
// eslint-disable-next-line @typescript-eslint/no-deprecated
const actual = faker.image.urlPlaceholder();
await assertWorkingUrl(actual);
});
Expand Down
42 changes: 21 additions & 21 deletions test/modules/__snapshots__/image.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@ exports[`image > 42 > urlPicsumPhotos > with width 1`] = `"https://picsum.photos

exports[`image > 42 > urlPicsumPhotos > with width and height 1`] = `"https://picsum.photos/seed/B993RBH1Y/128/128?grayscale&blur=10"`;

exports[`image > 42 > urlPlaceholder > noArgs 1`] = `"https://via.placeholder.com/1498x3802/ad331d/df0fc4.gif?text=auctus%20cognomen%20esse"`;
exports[`image > 42 > urlPlaceholder > noArgs 1`] = `"https://via.placeholder.com/1311x3328/ad331d/df0fc4.gif?text=auctus%20cognomen%20esse"`;

exports[`image > 42 > urlPlaceholder > with all options 1`] = `"https://via.placeholder.com/128x128/FF0000/0000FF.png?text=hello"`;

exports[`image > 42 > urlPlaceholder > with backgroundColor 1`] = `"https://via.placeholder.com/1498x3802/FF0000/ad331d.png?text=suggero%20accusator%20volubilis"`;
exports[`image > 42 > urlPlaceholder > with backgroundColor 1`] = `"https://via.placeholder.com/1311x3328/FF0000/ad331d.png?text=suggero%20accusator%20volubilis"`;

exports[`image > 42 > urlPlaceholder > with empty colors and text 1`] = `"https://via.placeholder.com/128x128//.png?text="`;

exports[`image > 42 > urlPlaceholder > with format 1`] = `"https://via.placeholder.com/1498x3802/ad331d/df0fc4.webp?text=attonbitus%20auctus%20cognomen"`;
exports[`image > 42 > urlPlaceholder > with format 1`] = `"https://via.placeholder.com/1311x3328/ad331d/df0fc4.webp?text=attonbitus%20auctus%20cognomen"`;

exports[`image > 42 > urlPlaceholder > with height 1`] = `"https://via.placeholder.com/1498x128/ead331/ddf0fc.jpeg?text=attonbitus%20auctus%20cognomen"`;
exports[`image > 42 > urlPlaceholder > with height 1`] = `"https://via.placeholder.com/1311x128/ead331/ddf0fc.jpeg?text=attonbitus%20auctus%20cognomen"`;

exports[`image > 42 > urlPlaceholder > with text 1`] = `"https://via.placeholder.com/1498x3802/ad331d/df0fc4.gif?text=Hello"`;
exports[`image > 42 > urlPlaceholder > with text 1`] = `"https://via.placeholder.com/1311x3328/ad331d/df0fc4.gif?text=Hello"`;

exports[`image > 42 > urlPlaceholder > with textColor 1`] = `"https://via.placeholder.com/1498x3802/ad331d/0000FF.png?text=suggero%20accusator%20volubilis"`;
exports[`image > 42 > urlPlaceholder > with textColor 1`] = `"https://via.placeholder.com/1311x3328/ad331d/0000FF.png?text=suggero%20accusator%20volubilis"`;

exports[`image > 42 > urlPlaceholder > with width 1`] = `"https://via.placeholder.com/128x1498/ead331/ddf0fc.jpeg?text=attonbitus%20auctus%20cognomen"`;
exports[`image > 42 > urlPlaceholder > with width 1`] = `"https://via.placeholder.com/128x1311/ead331/ddf0fc.jpeg?text=attonbitus%20auctus%20cognomen"`;

exports[`image > 42 > urlPlaceholder > with width and height 1`] = `"https://via.placeholder.com/128x128/8ead33/1ddf0f.webp?text=benevolentia%20attonbitus%20auctus"`;

Expand Down Expand Up @@ -132,23 +132,23 @@ exports[`image > 1211 > urlPicsumPhotos > with width 1`] = `"https://picsum.phot

exports[`image > 1211 > urlPicsumPhotos > with width and height 1`] = `"https://picsum.photos/seed/ZFGLlH/128/128?blur=9"`;

exports[`image > 1211 > urlPlaceholder > noArgs 1`] = `"https://via.placeholder.com/3714x3573/4fefa7/fbaec9.webp?text=unde%20blanditiis%20officia"`;
exports[`image > 1211 > urlPlaceholder > noArgs 1`] = `"https://via.placeholder.com/3250x3128/4fefa7/fbaec9.webp?text=unde%20blanditiis%20officia"`;

exports[`image > 1211 > urlPlaceholder > with all options 1`] = `"https://via.placeholder.com/128x128/FF0000/0000FF.png?text=hello"`;

exports[`image > 1211 > urlPlaceholder > with backgroundColor 1`] = `"https://via.placeholder.com/3714x3573/FF0000/4fefa7.png?text=tonsor%20tenuis%20sollers"`;
exports[`image > 1211 > urlPlaceholder > with backgroundColor 1`] = `"https://via.placeholder.com/3250x3128/FF0000/4fefa7.png?text=tonsor%20tenuis%20sollers"`;

exports[`image > 1211 > urlPlaceholder > with empty colors and text 1`] = `"https://via.placeholder.com/128x128//.png?text="`;

exports[`image > 1211 > urlPlaceholder > with format 1`] = `"https://via.placeholder.com/3714x3573/4fefa7/fbaec9.webp?text=usque%20unde%20blanditiis"`;
exports[`image > 1211 > urlPlaceholder > with format 1`] = `"https://via.placeholder.com/3250x3128/4fefa7/fbaec9.webp?text=usque%20unde%20blanditiis"`;

exports[`image > 1211 > urlPlaceholder > with height 1`] = `"https://via.placeholder.com/3714x128/d4fefa/7fbaec.jpg?text=usque%20unde%20blanditiis"`;
exports[`image > 1211 > urlPlaceholder > with height 1`] = `"https://via.placeholder.com/3250x128/d4fefa/7fbaec.jpg?text=usque%20unde%20blanditiis"`;

exports[`image > 1211 > urlPlaceholder > with text 1`] = `"https://via.placeholder.com/3714x3573/4fefa7/fbaec9.webp?text=Hello"`;
exports[`image > 1211 > urlPlaceholder > with text 1`] = `"https://via.placeholder.com/3250x3128/4fefa7/fbaec9.webp?text=Hello"`;

exports[`image > 1211 > urlPlaceholder > with textColor 1`] = `"https://via.placeholder.com/3714x3573/4fefa7/0000FF.png?text=tonsor%20tenuis%20sollers"`;
exports[`image > 1211 > urlPlaceholder > with textColor 1`] = `"https://via.placeholder.com/3250x3128/4fefa7/0000FF.png?text=tonsor%20tenuis%20sollers"`;

exports[`image > 1211 > urlPlaceholder > with width 1`] = `"https://via.placeholder.com/128x3714/d4fefa/7fbaec.jpg?text=usque%20unde%20blanditiis"`;
exports[`image > 1211 > urlPlaceholder > with width 1`] = `"https://via.placeholder.com/128x3250/d4fefa/7fbaec.jpg?text=usque%20unde%20blanditiis"`;

exports[`image > 1211 > urlPlaceholder > with width and height 1`] = `"https://via.placeholder.com/128x128/ed4fef/a7fbae.webp?text=dapifer%20usque%20unde"`;

Expand Down Expand Up @@ -208,22 +208,22 @@ exports[`image > 1337 > urlPicsumPhotos > with width 1`] = `"https://picsum.phot

exports[`image > 1337 > urlPicsumPhotos > with width and height 1`] = `"https://picsum.photos/seed/sjwgYJ/128/128?grayscale&blur=1"`;

exports[`image > 1337 > urlPlaceholder > noArgs 1`] = `"https://via.placeholder.com/1048x635/6a7b5f/a28d2f.jpg?text=testimonium%20thalassinus%20contra"`;
exports[`image > 1337 > urlPlaceholder > noArgs 1`] = `"https://via.placeholder.com/918x556/6a7b5f/a28d2f.jpg?text=testimonium%20thalassinus%20contra"`;

exports[`image > 1337 > urlPlaceholder > with all options 1`] = `"https://via.placeholder.com/128x128/FF0000/0000FF.png?text=hello"`;

exports[`image > 1337 > urlPlaceholder > with backgroundColor 1`] = `"https://via.placeholder.com/1048x635/FF0000/6a7b5f.png?text=ancilla%20creptio%20quisquam"`;
exports[`image > 1337 > urlPlaceholder > with backgroundColor 1`] = `"https://via.placeholder.com/918x556/FF0000/6a7b5f.png?text=ancilla%20creptio%20quisquam"`;

exports[`image > 1337 > urlPlaceholder > with empty colors and text 1`] = `"https://via.placeholder.com/128x128//.png?text="`;

exports[`image > 1337 > urlPlaceholder > with format 1`] = `"https://via.placeholder.com/1048x635/6a7b5f/a28d2f.webp?text=decipio%20testimonium%20thalassinus"`;
exports[`image > 1337 > urlPlaceholder > with format 1`] = `"https://via.placeholder.com/918x556/6a7b5f/a28d2f.webp?text=decipio%20testimonium%20thalassinus"`;

exports[`image > 1337 > urlPlaceholder > with height 1`] = `"https://via.placeholder.com/1048x128/36a7b5/fa28d2.webp?text=decipio%20testimonium%20thalassinus"`;
exports[`image > 1337 > urlPlaceholder > with height 1`] = `"https://via.placeholder.com/918x128/36a7b5/fa28d2.webp?text=decipio%20testimonium%20thalassinus"`;

exports[`image > 1337 > urlPlaceholder > with text 1`] = `"https://via.placeholder.com/1048x635/6a7b5f/a28d2f.jpg?text=Hello"`;
exports[`image > 1337 > urlPlaceholder > with text 1`] = `"https://via.placeholder.com/918x556/6a7b5f/a28d2f.jpg?text=Hello"`;

exports[`image > 1337 > urlPlaceholder > with textColor 1`] = `"https://via.placeholder.com/1048x635/6a7b5f/0000FF.png?text=ancilla%20creptio%20quisquam"`;
exports[`image > 1337 > urlPlaceholder > with textColor 1`] = `"https://via.placeholder.com/918x556/6a7b5f/0000FF.png?text=ancilla%20creptio%20quisquam"`;

exports[`image > 1337 > urlPlaceholder > with width 1`] = `"https://via.placeholder.com/128x1048/36a7b5/fa28d2.webp?text=decipio%20testimonium%20thalassinus"`;
exports[`image > 1337 > urlPlaceholder > with width 1`] = `"https://via.placeholder.com/128x918/36a7b5/fa28d2.webp?text=decipio%20testimonium%20thalassinus"`;

exports[`image > 1337 > urlPlaceholder > with width and height 1`] = `"https://via.placeholder.com/128x128/536a7b/5fa28d.gif?text=vorago%20decipio%20testimonium"`;
1 change: 1 addition & 0 deletions test/modules/image.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ describe('image', () => {

describe('urlPlaceholder', () => {
it('should return a random image url from Placeholder', () => {
// eslint-disable-next-line @typescript-eslint/no-deprecated
const actual = faker.image.urlPlaceholder();

assertValidUrl(actual);
Expand Down
Loading