aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorShinigami <[email protected]>2024-02-14 20:36:10 +0100
committerGitHub <[email protected]>2024-02-14 19:36:10 +0000
commit44d698e14f48a32259fd52a39d1e3028f84f3c06 (patch)
tree60848928995797018024907cd3daa0aefdd61065 /src/modules
parentc96176b359c98c60f3519579dc6fff855e4c3c20 (diff)
downloadfaker-44d698e14f48a32259fd52a39d1e3028f84f3c06.tar.xz
faker-44d698e14f48a32259fd52a39d1e3028f84f3c06.zip
refactor(image)!: remove v8 deprecated providers (#2634)
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/image/index.ts33
-rw-r--r--src/modules/image/providers/lorempicsum.ts169
-rw-r--r--src/modules/image/providers/placeholder.ts129
-rw-r--r--src/modules/image/providers/unsplash.ts221
4 files changed, 0 insertions, 552 deletions
diff --git a/src/modules/image/index.ts b/src/modules/image/index.ts
index 1a26065d..46bc06e4 100644
--- a/src/modules/image/index.ts
+++ b/src/modules/image/index.ts
@@ -1,10 +1,6 @@
-import type { Faker } from '../..';
import { deprecated } from '../../internal/deprecated';
import { ModuleBase } from '../../internal/module-base';
import type { MethodsOf } from '../../utils/types';
-import { LoremPicsum } from './providers/lorempicsum';
-import { Placeholder } from './providers/placeholder';
-import { Unsplash } from './providers/unsplash';
/**
* Module to generate images.
@@ -21,35 +17,6 @@ import { Unsplash } from './providers/unsplash';
*/
export class ImageModule extends ModuleBase {
/**
- * @deprecated Use `faker.image` instead.
- */
- // eslint-disable-next-line deprecation/deprecation
- readonly unsplash: Unsplash;
-
- /**
- * @deprecated Use `faker.image` instead.
- */
- // eslint-disable-next-line deprecation/deprecation
- readonly lorempicsum: LoremPicsum;
-
- /**
- * @deprecated Use `faker.image.urlPlaceholder` instead.
- */
- // eslint-disable-next-line deprecation/deprecation
- readonly placeholder: Placeholder;
-
- constructor(faker: Faker) {
- super(faker);
-
- // eslint-disable-next-line deprecation/deprecation
- this.unsplash = new Unsplash(this.faker);
- // eslint-disable-next-line deprecation/deprecation
- this.lorempicsum = new LoremPicsum(this.faker);
- // eslint-disable-next-line deprecation/deprecation
- this.placeholder = new Placeholder(this.faker);
- }
-
- /**
* Generates a random avatar image url.
*
* @example
diff --git a/src/modules/image/providers/lorempicsum.ts b/src/modules/image/providers/lorempicsum.ts
deleted file mode 100644
index 6e19b6e1..00000000
--- a/src/modules/image/providers/lorempicsum.ts
+++ /dev/null
@@ -1,169 +0,0 @@
-/* eslint-disable deprecation/deprecation */
-import type { Faker } from '../../..';
-import { deprecated } from '../../../internal/deprecated';
-
-/**
- * Module to generate links to random images on https://picsum.photos.
- *
- * The images generated from this module are fetched from an external service outside the control of Faker and could occasionally contain URLs which are broken or point to unexpected, disturbing, or offensive images. The service may also be subject to usage limits.
- *
- * @deprecated Use `faker.image.urlPicsumPhotos` instead.
- */
-export class LoremPicsum {
- constructor(private readonly faker: Faker) {}
-
- /**
- * Generates a new picsum photos image url.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @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`.
- *
- * @deprecated Use `faker.image.urlPicsumPhotos` instead.
- */
- image(
- width?: number,
- height?: number,
- grayscale?: boolean,
- blur?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
- ): string {
- deprecated({
- deprecated: 'faker.lorempicsum.image',
- proposed: 'faker.image.urlPicsumPhotos',
- since: '8.0',
- until: '9.0',
- });
- return this.imageUrl(width, height, grayscale, blur);
- }
-
- /**
- * Generates a new picsum photos image url.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @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`.
- *
- * @deprecated Use `faker.image.urlPicsumPhotos` instead.
- */
- imageGrayscale(width?: number, height?: number, grayscale?: boolean): string {
- deprecated({
- deprecated: 'faker.lorempicsum.imageGrayscale',
- proposed: 'faker.image.urlPicsumPhotos',
- since: '8.0',
- until: '9.0',
- });
- return this.imageUrl(width, height, grayscale);
- }
-
- /**
- * Generates a new picsum photos image url.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @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`.
- *
- * @deprecated Use `faker.image.urlPicsumPhotos` instead.
- */
- imageBlurred(
- width?: number,
- height?: number,
- blur?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
- ): string {
- deprecated({
- deprecated: 'faker.lorempicsum.imageBlurred',
- proposed: 'faker.image.urlPicsumPhotos',
- since: '8.0',
- until: '9.0',
- });
- return this.imageUrl(width, height, undefined, blur);
- }
-
- /**
- * Generates a new picsum photos image url.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @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.
- *
- * @deprecated Use `faker.image.urlPicsumPhotos` instead.
- */
- imageRandomSeeded(
- width?: number,
- height?: number,
- grayscale?: boolean,
- blur?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10,
- seed?: string
- ): string {
- deprecated({
- deprecated: 'faker.lorempicsum.imageRandomSeeded',
- proposed: 'faker.image.urlPicsumPhotos',
- since: '8.0',
- until: '9.0',
- });
- // TODO @ST-DDT 2022-03-11: This method does the same as image url, maybe generate a seed, if it is missing?
- return this.imageUrl(width, height, grayscale, blur, seed);
- }
-
- /**
- * Generates a new picsum photos image url.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @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.
- *
- * @deprecated Use `faker.image.urlPicsumPhotos` instead.
- */
- imageUrl(
- width?: number,
- height?: number,
- grayscale?: boolean,
- blur?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10,
- seed?: string
- ): string {
- deprecated({
- deprecated: 'faker.lorempicsum.imageUrl',
- proposed: 'faker.image.urlPicsumPhotos',
- since: '8.0',
- until: '9.0',
- });
- width = width || 640;
- height = height || 480;
-
- let url = 'https://picsum.photos';
-
- if (seed) {
- url += `/seed/${seed}`;
- }
-
- url += `/${width}/${height}`;
-
- if (grayscale && blur) {
- return `${url}?grayscale&blur=${blur}`;
- }
-
- if (grayscale) {
- return `${url}?grayscale`;
- }
-
- if (blur) {
- return `${url}?blur=${blur}`;
- }
-
- return url;
- }
-}
diff --git a/src/modules/image/providers/placeholder.ts b/src/modules/image/providers/placeholder.ts
deleted file mode 100644
index c7514f23..00000000
--- a/src/modules/image/providers/placeholder.ts
+++ /dev/null
@@ -1,129 +0,0 @@
-/* eslint-disable deprecation/deprecation */
-import type { Faker } from '../../..';
-import { deprecated } from '../../../internal/deprecated';
-
-/**
- * Module to generate links to images on `https://via.placeholder.com/`.
- *
- * The images generated from this module are fetched from an external service outside the control of Faker and could occasionally contain URLs which are broken or point to unexpected, disturbing, or offensive images. The service may also be subject to usage limits.
- *
- * @deprecated Use `faker.image.urlPlaceholder` instead.
- */
-export class Placeholder {
- constructor(private readonly faker: Faker) {
- // Bind `this` so namespaced is working correctly
- for (const name of Object.getOwnPropertyNames(
- Placeholder.prototype
- ) as Array<keyof Placeholder | 'constructor'>) {
- if (name === 'constructor' || typeof this[name] !== 'function') {
- continue;
- }
-
- this[name] = this[name].bind(this);
- }
- }
-
- /**
- * Generates a new placeholder image url.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @param width The width of the image (in pixels). Defaults to `640`.
- * @param height The height of the image (in pixels). Defaults to `width`.
- * @param text The text of the image.
- * @param format The file format of the image. Supports `png`, `jpeg`, `png`, `gif`, `webp`.
- * @param backgroundColor The background color of the placeholder. Supports HEX CODE format.
- * @param textColor The text color of the placeholder. Requires `backgroundColor`. Supports HEX CODE format.
- *
- * @example
- * faker.image.placeholder.imageUrl() // https://via.placeholder.com/640x640
- * faker.image.placeholder.imageUrl(200) // https://via.placeholder.com/200x200
- * faker.image.placeholder.imageUrl(200, 100) // https://via.placeholder.com/200x100
- * faker.image.placeholder.imageUrl(200, 100, 'Fish') // https://via.placeholder.com/200x100?text=Fish
- * faker.image.placeholder.imageUrl(200, 100, 'Fish', 'webp') // https://via.placeholder.com/200x100.webp?text=Fish
- * faker.image.placeholder.imageUrl(200, 100, 'Fish', 'webp') // https://via.placeholder.com/200x100.webp?text=Fish
- * faker.image.placeholder.imageUrl(200, 100, 'Fish', 'webp', '000000', 'ffffff) // https://via.placeholder.com/200x100/000000/FFFFFF.webp?text=Fish
- *
- * @deprecated Use `faker.image.urlPlaceholder` instead.
- */
- imageUrl(
- width?: number,
- height?: number,
- text?: string,
- format?: 'png' | 'jpeg' | 'jpg' | 'gif' | 'webp',
- backgroundColor?: string,
- textColor?: string
- ): string {
- deprecated({
- deprecated: 'faker.placeholder.imageUrl',
- proposed: 'faker.image.urlPlaceholder',
- since: '8.0',
- until: '9.0',
- });
- width = width || 640;
- height = height || width;
-
- let url = 'https://via.placeholder.com';
- url += `/${width}x${height}`;
-
- if (backgroundColor != null) {
- url += `/${backgroundColor.replace('#', '').toUpperCase()}`;
-
- if (textColor != null) {
- url += `/${textColor.replace('#', '').toUpperCase()}`;
- }
- }
-
- if (format != null) {
- url += `.${format}`;
- }
-
- if (text != null) {
- const urlParam = new URLSearchParams({ text });
- url += `?${urlParam.toString()}`;
- }
-
- return url;
- }
-
- /**
- * Generate a new placeholder image with random colors and text.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @param width The width of the image (in pixels). Defaults to `640`.
- * @param height The height of the image (in pixels). Defaults to `width`.
- * @param format The file format of the image. Supports `png` `jpeg` `png` `gif` `webp`.
- *
- * @example
- * faker.image.placeholder.randomUrl() // https://via.placeholder.com/640x640/000000/ffffff?text=lorum
- * faker.image.placeholder.randomUrl(150) // https://via.placeholder.com/150x150/000000/ffffff?text=lorum
- * faker.image.placeholder.randomUrl(150, 200) // https://via.placeholder.com/150x200/000000/ffffff?text=lorum
- * faker.image.placeholder.randomUrl(150, 200, 'png') // https://via.placeholder.com/150x200/000000/ffffff.png?text=lorum
- *
- * @deprecated Use `faker.image.urlPlaceholder` instead.
- */
- randomUrl(
- width?: number,
- height?: number,
- format?: 'png' | 'jpeg' | 'jpg' | 'gif' | 'webp'
- ): string {
- deprecated({
- deprecated: 'faker.placeholder.randomUrl',
- proposed: 'faker.image.urlPlaceholder',
- since: '8.0',
- until: '9.0',
- });
- return this.imageUrl(
- width,
- height,
- this.faker.lorem.word(),
- format,
- this.faker.color.rgb({
- casing: 'upper',
- prefix: '',
- }),
- this.faker.color.rgb({ casing: 'upper', prefix: '' })
- );
- }
-}
diff --git a/src/modules/image/providers/unsplash.ts b/src/modules/image/providers/unsplash.ts
deleted file mode 100644
index a2b4ee0e..00000000
--- a/src/modules/image/providers/unsplash.ts
+++ /dev/null
@@ -1,221 +0,0 @@
-/* eslint-disable deprecation/deprecation */
-import type { Faker } from '../../..';
-import { deprecated } from '../../../internal/deprecated';
-
-/**
- * Module to generate links to random images on `https://source.unsplash.com/`.
- *
- * The images generated from this module are fetched from an external service outside the control of Faker and could occasionally contain URLs which are broken or point to unexpected, disturbing, or offensive images. The service may also be subject to usage limits.
- *
- * @deprecated Use `faker.image` instead.
- */
-export class Unsplash {
- constructor(private readonly faker: Faker) {}
-
- /**
- * Generates a new unsplash image url for a random supported category.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @param width The width of the image. Defaults to `640`.
- * @param height The height of the image. Defaults to `480`.
- * @param keyword The image keywords to use.
- *
- * @deprecated Use `faker.image` instead.
- */
- image(width?: number, height?: number, keyword?: string): string {
- deprecated({
- deprecated: 'faker.unsplash.image',
- proposed: 'faker.image.url',
- since: '8.0',
- until: '9.0',
- });
- return this.imageUrl(width, height, undefined, keyword);
- }
-
- /**
- * Generates a new unsplash image url.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @param width The width of the image. Defaults to `640`.
- * @param height The height of the image. Defaults to `480`.
- * @param category The category of the image to generate.
- * @param keyword The image keywords to use.
- *
- * @deprecated Use `faker.image` instead.
- */
- imageUrl(
- width?: number,
- height?: number,
- category?: string,
- keyword?: string
- ): string {
- deprecated({
- deprecated: 'faker.unsplash.imageUrl',
- proposed: 'faker.image.url',
- since: '8.0',
- until: '9.0',
- });
- width = width || 640;
- height = height || 480;
-
- let url = 'https://source.unsplash.com';
-
- if (category != null) {
- url += `/category/${category}`;
- }
-
- url += `/${width}x${height}`;
-
- if (keyword != null) {
- const keywordFormat = /^([A-Za-z0-9].+,[A-Za-z0-9]+)$|^([A-Za-z0-9]+)$/;
- if (keywordFormat.test(keyword)) {
- url += `?${keyword}`;
- }
- }
-
- return url;
- }
-
- /**
- * Generates a new unsplash image url using the "food" category.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @param width The width of the image. Defaults to `640`.
- * @param height The height of the image. Defaults to `480`.
- * @param keyword The image keywords to use.
- *
- * @deprecated Use `faker.image` instead.
- */
- food(width?: number, height?: number, keyword?: string): string {
- deprecated({
- deprecated: 'faker.unsplash.food',
- proposed: 'faker.image.url',
- since: '8.0',
- until: '9.0',
- });
- return this.faker.image.unsplash.imageUrl(width, height, 'food', keyword);
- }
-
- /**
- * Generates a new unsplash image url using the "people" category.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @param width The width of the image. Defaults to `640`.
- * @param height The height of the image. Defaults to `480`.
- * @param keyword The image keywords to use.
- *
- * @deprecated Use `faker.image` instead.
- */
- people(width?: number, height?: number, keyword?: string): string {
- deprecated({
- deprecated: 'faker.unsplash.people',
- proposed: 'faker.image.url',
- since: '8.0',
- until: '9.0',
- });
- return this.faker.image.unsplash.imageUrl(width, height, 'people', keyword);
- }
-
- /**
- * Generates a new unsplash image url using the "nature" category.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @param width The width of the image. Defaults to `640`.
- * @param height The height of the image. Defaults to `480`.
- * @param keyword The image keywords to use.
- *
- * @deprecated Use `faker.image` instead.
- */
- nature(width?: number, height?: number, keyword?: string): string {
- deprecated({
- deprecated: 'faker.unsplash.nature',
- proposed: 'faker.image.url',
- since: '8.0',
- until: '9.0',
- });
- return this.faker.image.unsplash.imageUrl(width, height, 'nature', keyword);
- }
-
- /**
- * Generates a new unsplash image url using the "technology" category.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @param width The width of the image. Defaults to `640`.
- * @param height The height of the image. Defaults to `480`.
- * @param keyword The image keywords to use.
- *
- * @deprecated Use `faker.image` instead.
- */
- technology(width?: number, height?: number, keyword?: string): string {
- deprecated({
- deprecated: 'faker.unsplash.technology',
- proposed: 'faker.image.url',
- since: '8.0',
- until: '9.0',
- });
- return this.faker.image.unsplash.imageUrl(
- width,
- height,
- 'technology',
- keyword
- );
- }
-
- /**
- * Generates a new unsplash image url using the "objects" category.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @param width The width of the image. Defaults to `640`.
- * @param height The height of the image. Defaults to `480`.
- * @param keyword The image keywords to use.
- *
- * @deprecated Use `faker.image` instead.
- */
- objects(width?: number, height?: number, keyword?: string): string {
- deprecated({
- deprecated: 'faker.unsplash.objects',
- proposed: 'faker.image.url',
- since: '8.0',
- until: '9.0',
- });
- return this.faker.image.unsplash.imageUrl(
- width,
- height,
- 'objects',
- keyword
- );
- }
-
- /**
- * Generates a new unsplash image url using the "buildings" category.
- *
- * These images are fetched from an external service outside the control of Faker and could occasionally contain URLs which point to unexpected, disturbing, or offensive images. Usage limits may contribute to this behavior.
- *
- * @param width The width of the image. Defaults to `640`.
- * @param height The height of the image. Defaults to `480`.
- * @param keyword The image keywords to use.
- *
- * @deprecated Use `faker.image` instead.
- */
- buildings(width?: number, height?: number, keyword?: string): string {
- deprecated({
- deprecated: 'faker.unsplash.buildings',
- proposed: 'faker.image.url',
- since: '8.0',
- until: '9.0',
- });
- return this.faker.image.unsplash.imageUrl(
- width,
- height,
- 'buildings',
- keyword
- );
- }
-}