imgflip.com 3.5.6 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # imgflip.com [![npm version](https://img.shields.io/npm/v/imgflip.com.svg)](https://www.npmjs.com/package/imgflip.com)
2
2
 
3
- An [imgflip.com](https://imgflip.com) API client. For a documentation on the API see https://api.imgflip.com/.
3
+ An [imgflip.com](https://imgflip.com) API client. For a documentation on the API see [the imgflip API reference](https://imgflip.com/api).
4
4
 
5
5
  ### Installation
6
6
 
@@ -0,0 +1,6 @@
1
+ export declare const Endpoint: {
2
+ CAPTION_IMAGE: string;
3
+ captionImage(): string;
4
+ GET_MEMES: string;
5
+ getMemes(): string;
6
+ };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Endpoint = void 0;
4
+ exports.Endpoint = {
5
+ CAPTION_IMAGE: 'caption_image',
6
+ captionImage() {
7
+ return `/${exports.Endpoint.CAPTION_IMAGE}`;
8
+ },
9
+ GET_MEMES: 'get_memes',
10
+ getMemes() {
11
+ return `/${exports.Endpoint.GET_MEMES}`;
12
+ },
13
+ };
@@ -0,0 +1,14 @@
1
+ import type { API } from './interfaces';
2
+ export declare class Imgflip {
3
+ private static readonly BASE_URL;
4
+ readonly api: API;
5
+ private readonly apiClient;
6
+ constructor(apiUrl?: string);
7
+ /**
8
+ * Set a new API URL.
9
+ * @param newURL The new API url
10
+ */
11
+ setApiUrl(newURL: string): void;
12
+ private readonly captionImage;
13
+ private readonly getMemes;
14
+ }
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.Imgflip = void 0;
46
+ const api_client_1 = require("@ffflorian/api-client");
47
+ const qs = __importStar(require("qs"));
48
+ const Endpoints_1 = require("./Endpoints");
49
+ class Imgflip {
50
+ constructor(apiUrl) {
51
+ this.captionImage = (params) => __awaiter(this, void 0, void 0, function* () {
52
+ const endpoint = Endpoints_1.Endpoint.captionImage();
53
+ const config = {
54
+ data: qs.stringify(params, { arrayFormat: 'indices' }),
55
+ headers: {
56
+ 'Content-Type': 'application/x-www-form-urlencoded',
57
+ },
58
+ method: 'POST',
59
+ };
60
+ const response = yield this.apiClient.request(endpoint, config);
61
+ return response.json();
62
+ });
63
+ this.getMemes = (options) => __awaiter(this, void 0, void 0, function* () {
64
+ const endpoint = Endpoints_1.Endpoint.getMemes();
65
+ const { data } = yield this.apiClient.get(endpoint, {
66
+ params: options
67
+ ? Object.assign(Object.assign({}, options), { type: Array.isArray(options.type) ? options.type.join(',') : options.type }) : undefined,
68
+ });
69
+ return data;
70
+ });
71
+ this.apiClient = new api_client_1.APIClient(apiUrl || Imgflip.BASE_URL);
72
+ this.api = {
73
+ captionImage: this.captionImage,
74
+ getMemes: this.getMemes,
75
+ };
76
+ }
77
+ /**
78
+ * Set a new API URL.
79
+ * @param newURL The new API url
80
+ */
81
+ setApiUrl(newURL) {
82
+ this.apiClient.setBaseURL(newURL);
83
+ }
84
+ }
85
+ exports.Imgflip = Imgflip;
86
+ Imgflip.BASE_URL = 'https://api.imgflip.com';
@@ -0,0 +1,2 @@
1
+ export * from './Imgflip';
2
+ export * from './interfaces';
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Imgflip"), exports);
18
+ __exportStar(require("./interfaces"), exports);
@@ -0,0 +1,105 @@
1
+ export interface API {
2
+ /**
3
+ * Add a caption to an Imgflip meme template.
4
+ * Images created with this API will be publicly accessible by anyone
5
+ * through the url in the response - there is no "private" option.
6
+ * This does not mean these memes will be posted publicly though,
7
+ * one still needs to know the exact URL to find the image.
8
+ * If the image hangs around on Imgflip servers for a while and
9
+ * gets very few views (direct image views and image page views both
10
+ * count), it will be auto-deleted to save space.
11
+ */
12
+ captionImage(options: ImageCaptionOptions): Promise<Response<Image>>;
13
+ /**
14
+ * Gets an array of popular memes that may be captioned with this API.
15
+ * The size of this array and the order of memes may change at any time.
16
+ */
17
+ getMemes(options?: GetMemesOptions): Promise<Response<Memes>>;
18
+ }
19
+ /**
20
+ * `x`, `y`, `width`, and `height` are for the bounding box of the text box. `x` and
21
+ * `y` are the coordinates of the top left corner. If you specify bounding
22
+ * coordinates, be sure to specify all four (`x`, `y`, `width`, `height`), otherwise
23
+ * your text may not show up correctly. If you do not specify bounding box
24
+ * coordinates, the same automatic default coordinates from
25
+ * https://imgflip.com/memegenerator will be used, which is very useful for memes
26
+ * with special text box positioning other than the simple top/bottom.
27
+ */
28
+ export interface Box {
29
+ color?: string;
30
+ height?: number;
31
+ outline_color?: string;
32
+ text: string;
33
+ width?: number;
34
+ x?: number;
35
+ y?: number;
36
+ }
37
+ export type GetMemesOptions = {
38
+ /**
39
+ * The type of meme templates to return.
40
+ * Valid values are `gif` or `image`.
41
+ */
42
+ type?: MemeType | MemeType[];
43
+ };
44
+ export interface Image {
45
+ page_url: string;
46
+ url: string;
47
+ }
48
+ export type ImageCaptionOptions = ImageCaptionWithBoxes | ImageCaptionWithTexts;
49
+ export interface ImageCaptionWithBoxes extends ImageCaptionBase {
50
+ /**
51
+ * For creating memes with more than two text boxes, or for further
52
+ * customization. If boxes is specified, text will not be automatically
53
+ * converted to uppercase, so you'll have to handle capitalization yourself
54
+ * if you want the standard uppercase meme text. You may specify up to 20
55
+ * text boxes. You may leave the first box completely empty, so that the
56
+ * second box will automatically be used for the bottom text.
57
+ */
58
+ boxes: Box[];
59
+ }
60
+ export interface ImageCaptionWithTexts extends ImageCaptionBase {
61
+ /** Top text for the meme */
62
+ text0: string;
63
+ /** Bottom text for the meme */
64
+ text1: string;
65
+ }
66
+ export interface Meme {
67
+ box_count: number;
68
+ height: number;
69
+ id: string;
70
+ name: string;
71
+ url: string;
72
+ width: number;
73
+ }
74
+ export interface Memes {
75
+ memes: Meme[];
76
+ }
77
+ export type MemeType = 'gif' | 'image';
78
+ export type Response<T> = {
79
+ data: T;
80
+ success: true;
81
+ } | {
82
+ error_message: string;
83
+ success: false;
84
+ };
85
+ interface ImageCaptionBase {
86
+ /** The font family to use for the text. Defaults to `impact`. */
87
+ font?: string;
88
+ /** Maximum font size in pixels. Defaults to `50px`. */
89
+ max_font_size?: number | string;
90
+ /** Remove the imgflip.com watermark (premium feature). */
91
+ no_watermark?: 0 | 1 | boolean;
92
+ /** password for the imgflip account */
93
+ password: string;
94
+ /**
95
+ * A template ID as returned by the `get_memes` response. Any ID that was
96
+ * ever returned from the `get_memes` response should work for this parameter.
97
+ * For custom template uploads, the template ID can be found in the
98
+ * memegenerator URL, e.g.
99
+ * https://imgflip.com/memegenerator/14859329/Charlie-Sheen-DERP.
100
+ */
101
+ template_id: number | string;
102
+ /** username of a valid imgflip account. This is used to track where API requests are coming from. */
103
+ username: string;
104
+ }
105
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,16 +1,18 @@
1
1
  {
2
2
  "author": "Florian Imdahl <git@ffflorian.de>",
3
3
  "dependencies": {
4
- "@ffflorian/api-client": "2.5.0",
5
- "qs": "6.15.0"
4
+ "@ffflorian/api-client": "2.5.1",
5
+ "qs": "6.15.1"
6
6
  },
7
7
  "description": "A imgflip.com API client",
8
8
  "devDependencies": {
9
9
  "@types/node": "~24",
10
10
  "@types/qs": "6.15.0",
11
+ "nock": "14.0.12",
11
12
  "rimraf": "6.1.3",
12
- "typedoc": "0.28.18",
13
- "typescript": "6.0.2"
13
+ "typedoc": "0.28.19",
14
+ "typescript": "6.0.2",
15
+ "vitest": "4.1.4"
14
16
  },
15
17
  "engines": {
16
18
  "node": ">= 21"
@@ -31,11 +33,12 @@
31
33
  "readme": "https://github.com/ffflorian/api-clients#readme",
32
34
  "repository": "https://github.com/ffflorian/api-clients.git",
33
35
  "scripts": {
36
+ "build": "yarn build:ts",
34
37
  "build:ts": "tsc -p tsconfig.build.json",
35
38
  "build:docs": "typedoc --tsconfig tsconfig.build.json --options ../../typedoc.json --out ../../docs/packages/imgflip.com src/index.ts",
36
39
  "clean": "rimraf dist",
37
- "dist": "yarn clean && yarn build:ts",
38
- "test": "exit 0"
40
+ "dist": "yarn clean && yarn build",
41
+ "test": "vitest run"
39
42
  },
40
- "version": "3.5.6"
43
+ "version": "3.6.0"
41
44
  }