nekosia.js 0.1.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.
@@ -0,0 +1,363 @@
1
+ import { TAGS } from './tags.ts';
2
+
3
+ declare module 'nekosia.js' {
4
+ type HexColor = `#${string}`;
5
+ type AllTagsList = typeof TAGS[number];
6
+
7
+ /**
8
+ * Configuration options for the `fetchImages` function.
9
+ */
10
+ interface FetchImagesOptions {
11
+ /**
12
+ * Session type:
13
+ * - `id` - Session identified by the `id` value (requires the `id` field to be set).
14
+ * - `ip` - Session identified by the user's IP address.
15
+ * @default null
16
+ */
17
+ session?: null | 'id' | 'ip';
18
+
19
+ /**
20
+ * Identifier of the fetched image.
21
+ * @example 66ae26a07886f165901e8a3f
22
+ * @default null
23
+ */
24
+ id?: null | string;
25
+
26
+ /**
27
+ * The number of images to fetch. WARNING! The higher the number, the more data the server will need to process, which will result in a longer response time.
28
+ *
29
+ * Minimum: 1
30
+ *
31
+ * Maximum: 48
32
+ *
33
+ * @default 1
34
+ */
35
+ count?: number;
36
+
37
+ /**
38
+ * Additional tags to include in the image search.
39
+ * This can be a single string with one tag or an array of strings with multiple tags.
40
+ * @example ["cute", "sakura", "cherry-blossom"]
41
+ * @default []
42
+ */
43
+ additionalTags?: AllTagsList | AllTagsList[];
44
+
45
+ /**
46
+ * Tags to exclude during the image search.
47
+ * This can be a single string with one tag or an array of strings with multiple tags.
48
+ * @example ["beret", "hat", "short-hair"]
49
+ * @default []
50
+ */
51
+ blacklistedTags?: AllTagsList | AllTagsList[];
52
+ }
53
+
54
+ /**
55
+ * Details about a specific image.
56
+ */
57
+ interface ImageDetails {
58
+ /**
59
+ * URL leading to the image.
60
+ * @example https://cdn.nekosia.cat/images/maid-uniform/66bc6b7481a59a1cf2c79db5.png
61
+ */
62
+ url: string;
63
+
64
+ /**
65
+ * Image file extension.
66
+ * @example `png` or `jpg`, etc.
67
+ */
68
+ extension: string;
69
+ }
70
+
71
+ /**
72
+ * Metadata about the image.
73
+ */
74
+ interface ImageMetadata {
75
+ /**
76
+ * Image width in pixels.
77
+ * @example 1447
78
+ */
79
+ width: number;
80
+
81
+ /**
82
+ * Image height in pixels.
83
+ * @example 2046
84
+ */
85
+ height: number;
86
+
87
+ /**
88
+ * Image size in bytes.
89
+ * @example 1001991
90
+ */
91
+ size: number;
92
+
93
+ /**
94
+ * Image file extension.
95
+ * @example jpeg
96
+ */
97
+ extension: string;
98
+ }
99
+
100
+ interface ImageColors {
101
+ /**
102
+ * Main dominant color of the image in hexadecimal format.
103
+ * @example #00FF00
104
+ */
105
+ main: HexColor;
106
+
107
+ /**
108
+ * Palette of the 14 most dominant colors in the image, presented in hexadecimal format.
109
+ * @example ["#9D78CD", "#454FC0", "#909AEB", "#F5E3F0", "#94498B", "#BEC1EE", "#CD7D67", "#CC98D5", "#E2AE9E", "#F0B4DB", "#2B1C3E", "#4E8DCB", "#F2DABF", "#5CB6C0"]
110
+ */
111
+ palette: HexColor[];
112
+ }
113
+
114
+ interface ImageAnime {
115
+ /**
116
+ * The title of the anime from which the image originates. `null` if not applicable.
117
+ * @example Satsuriku no Tenshi
118
+ */
119
+ title: string | null;
120
+
121
+ /**
122
+ * The name of the character depicted in the image. `null` if not applicable.
123
+ * @example Rachel Gardner
124
+ */
125
+ character: string | null;
126
+ }
127
+
128
+ interface ImageSource {
129
+ /**
130
+ * URL of the source page where the image originates. `null` if not applicable.
131
+ */
132
+ url: string | null;
133
+
134
+ /**
135
+ * Direct link to the image. `null` if not applicable.
136
+ */
137
+ direct: string | null;
138
+ }
139
+
140
+ interface ArtistDetails {
141
+ /**
142
+ * Artist's username. `null` if not applicable.
143
+ */
144
+ username: string | null;
145
+
146
+ /**
147
+ * Link to the artist's profile. `null` if not applicable.
148
+ */
149
+ profile: string | null;
150
+ }
151
+
152
+ interface ImageAttribution {
153
+ /**
154
+ * Information about the artist.
155
+ */
156
+ artist: ArtistDetails;
157
+
158
+ /**
159
+ * Copyright of the artwork. `null` if not applicable.
160
+ */
161
+ copyright: string | null;
162
+ }
163
+
164
+ /**
165
+ * Response structure for an image fetch request from the API.
166
+ */
167
+ interface ImageResponse {
168
+ /**
169
+ * Indicates whether the operation was successful.
170
+ * @example true
171
+ */
172
+ success: boolean;
173
+
174
+ /**
175
+ * HTTP status code of the response.
176
+ * @example 200
177
+ */
178
+ status: number;
179
+
180
+ /**
181
+ * Session key, if applicable, otherwise `null`.
182
+ */
183
+ key: string | null;
184
+
185
+ /**
186
+ * Number of images included in the response.
187
+ */
188
+ count: number;
189
+
190
+ /**
191
+ * Image identifier.
192
+ */
193
+ id: string;
194
+
195
+ /**
196
+ * Structure containing the dominant colors of the fetched image.
197
+ */
198
+ colors: ImageColors;
199
+
200
+ /**
201
+ * Structure containing details about the original and compressed images.
202
+ */
203
+ image: {
204
+ /**
205
+ * Original uncompressed image. The file includes EXIF data to acknowledge the artist's work.
206
+ */
207
+ original: ImageDetails;
208
+
209
+ /**
210
+ * Compressed image with a smaller size, without quality loss. The file includes EXIF data to acknowledge the artist's work.
211
+ */
212
+ compressed: ImageDetails;
213
+ };
214
+
215
+ /**
216
+ * Metadata about the original and compressed images.
217
+ */
218
+ metadata: {
219
+ original: ImageMetadata;
220
+ compressed: ImageMetadata;
221
+ };
222
+
223
+ /**
224
+ * Category to which the image belongs.
225
+ * @example catgirl
226
+ */
227
+ category: string;
228
+
229
+ /**
230
+ * Tags assigned to the image.
231
+ */
232
+ tags: string[];
233
+
234
+ /**
235
+ * Content rating of the image.
236
+ *
237
+ * `safe` - Image safe to display in any situation.
238
+ *
239
+ * `questionable` - Image may contain content inappropriate for some viewers.
240
+ *
241
+ * `nsfw` - Image contains content intended for adults only (Not Safe For Work).
242
+ *
243
+ * @output 'safe' | 'questionable' | 'nsfw'
244
+ */
245
+ rating: 'safe' | 'questionable' | 'nsfw';
246
+
247
+ /**
248
+ * Information about the anime (not necessarily an anime) to which the image may belong.
249
+ */
250
+ anime: ImageAnime;
251
+
252
+ /**
253
+ * Information about the source of the image.
254
+ */
255
+ source: ImageSource;
256
+
257
+ /**
258
+ * Structure containing information about the artist and associated copyright of the image.
259
+ */
260
+ attribution: ImageAttribution;
261
+ }
262
+
263
+ /**
264
+ * Nekosia API class, containing methods for fetching images.
265
+ * All methods are asynchronous and return a Promise with an `ImageResponse`.
266
+ */
267
+ export class NekosiaAPI {
268
+ /**
269
+ * Fetches images from a selected category by sending a GET request to the API.
270
+ * @param category - The category of images to fetch (e.g., `catgirl`).
271
+ * @param options - Configuration options for the request (optional).
272
+ * @example
273
+ * const { NekosiaAPI } = require('nekosia.js');
274
+ * await NekosiaAPI.fetchImages('catgirl', {
275
+ * count: 1,
276
+ * additionalTags: ['cute', 'sakura', 'cherry-blossom'],
277
+ * blacklistedTags: ['beret']
278
+ * });
279
+ * @returns Promise with an `ImageResponse`.
280
+ */
281
+ fetchImages(category: AllTagsList, options?: FetchImagesOptions): Promise<ImageResponse>;
282
+
283
+ /**
284
+ * Fetches images based solely on the tags provided by the user. The main category does not affect the image selection as it is not provided here.
285
+ * @param options - Configuration options for the request (optional).
286
+ * @example
287
+ * const { NekosiaAPI } = require('nekosia.js');
288
+ * await NekosiaAPI.fetchShadowImages({
289
+ * count: 1,
290
+ * additionalTags: ['catgirl', 'foxgirl'],
291
+ * blacklistedTags: ['dog-girl']
292
+ * });
293
+ * @returns Promise with an `ImageResponse`.
294
+ */
295
+ fetchShadowImages(options?: FetchImagesOptions): Promise<ImageResponse>;
296
+
297
+ /**
298
+ * Fetches an image by its identifier.
299
+ * @param id - The image identifier (e.g., `66ae26a07886f165901e8a3f`).
300
+ * @returns Promise with an `ImageResponse`.
301
+ */
302
+ fetchById(id: string): Promise<ImageResponse>;
303
+ }
304
+
305
+ /**
306
+ * JSON object response from the API regarding the current version of the API and related information.
307
+ */
308
+ interface APIVersion {
309
+ /**
310
+ * HTTP status code of the response.
311
+ * @example 200
312
+ */
313
+ status: number;
314
+
315
+ /**
316
+ * Indicates whether the request was successful.
317
+ * @example true
318
+ */
319
+ success: boolean;
320
+
321
+ /**
322
+ * The current version of the API.
323
+ * @example 1.0.0
324
+ */
325
+ version: string;
326
+
327
+ /**
328
+ * URL to the API documentation.
329
+ * @example https://nekosia.cat/documentation
330
+ */
331
+ documentation: string;
332
+
333
+ /**
334
+ * Contact email.
335
+ * @example contact@nekosia.cat
336
+ */
337
+ contact: string;
338
+
339
+ /**
340
+ * List of available API numbers.
341
+ * @example [1]
342
+ */
343
+ apis: number[];
344
+ }
345
+
346
+ /**
347
+ * Module and API versions.
348
+ */
349
+ export const NekosiaVersion: {
350
+ /**
351
+ * Get the current version of the module.
352
+ * @example "1.1.0"
353
+ * @returns String with the module version.
354
+ */
355
+ module: string;
356
+
357
+ /**
358
+ * Get the current API version and related information.
359
+ * @returns Promise that resolves to an `APIVersion` object.
360
+ */
361
+ api(): Promise<APIVersion>;
362
+ };
363
+ }