@aicats/sdk 1.0.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/LICENSE +21 -0
- package/README.md +140 -0
- package/dist/index.d.mts +110 -0
- package/dist/index.d.ts +110 -0
- package/dist/index.js +160 -0
- package/dist/index.mjs +131 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mario Bertsch
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# 🐱 ai-cats-sdk
|
|
2
|
+
|
|
3
|
+
Official JavaScript/TypeScript SDK for the [ai-cats.net](https://ai-cats.net) API - Get AI-generated cat images!
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @aicats/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { AiCats, Theme, Size } from '@aicats/sdk';
|
|
15
|
+
|
|
16
|
+
// Get a random cat image
|
|
17
|
+
const imageBlob = await AiCats.random();
|
|
18
|
+
|
|
19
|
+
// Get a Halloween-themed cat
|
|
20
|
+
const spookyCat = await AiCats.random({ theme: Theme.Halloween });
|
|
21
|
+
|
|
22
|
+
// Search for cats
|
|
23
|
+
const results = await AiCats.search({ query: 'orange fluffy cat', limit: 10 });
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## API Reference
|
|
27
|
+
|
|
28
|
+
### `AiCats.random(options?)`
|
|
29
|
+
Get a random AI-generated cat image.
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
const blob = await AiCats.random({
|
|
33
|
+
size: Size.Medium, // Image size (default: Large)
|
|
34
|
+
theme: Theme.Xmas // Optional theme
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### `AiCats.getById(id, size?)`
|
|
39
|
+
Get a specific cat image by ID.
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
const blob = await AiCats.getById('abc-123-def', Size.Small);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### `AiCats.getInfo(id)`
|
|
46
|
+
Get detailed information about a cat image.
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
const info = await AiCats.getInfo('abc-123-def');
|
|
50
|
+
console.log(info.prompt); // "A fluffy orange cat..."
|
|
51
|
+
console.log(info.theme); // "Halloween"
|
|
52
|
+
console.log(info.dateCreated); // 1699012345678
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### `AiCats.search(options?)`
|
|
56
|
+
Search for cat images.
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
const results = await AiCats.search({
|
|
60
|
+
query: 'black cat', // Search text
|
|
61
|
+
limit: 20, // Max results (1-100)
|
|
62
|
+
theme: Theme.Halloween,// Filter by theme
|
|
63
|
+
descending: true // Newest first
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
for (const cat of results) {
|
|
67
|
+
console.log(cat.id, cat.url);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### `AiCats.getSimilar(id, options?)`
|
|
72
|
+
Find cats similar to a given cat.
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
const similar = await AiCats.getSimilar('abc-123-def', { limit: 5 });
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### `AiCats.getThemes()`
|
|
79
|
+
Get all available themes.
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
const themes = await AiCats.getThemes();
|
|
83
|
+
// ['Default', 'Spring', 'Summer', 'Halloween', 'Xmas', ...]
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### `AiCats.getCount(theme?)`
|
|
87
|
+
Get the total number of cat images.
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
const total = await AiCats.getCount();
|
|
91
|
+
const halloweenCount = await AiCats.getCount(Theme.Halloween);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Types
|
|
95
|
+
|
|
96
|
+
### Size
|
|
97
|
+
```typescript
|
|
98
|
+
Size.Large // 1024x1024 (default)
|
|
99
|
+
Size.Medium // 512x512
|
|
100
|
+
Size.Small // 256x256
|
|
101
|
+
Size.Thumbnail // 128x128
|
|
102
|
+
Size.Icon // 64x64
|
|
103
|
+
Size.Tiny // 32x32
|
|
104
|
+
Size.Micro // 16x16
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Theme
|
|
108
|
+
```typescript
|
|
109
|
+
Theme.Default
|
|
110
|
+
Theme.Spring
|
|
111
|
+
Theme.Summer
|
|
112
|
+
Theme.Autumn
|
|
113
|
+
Theme.Winter
|
|
114
|
+
Theme.Halloween
|
|
115
|
+
Theme.Xmas
|
|
116
|
+
Theme.NewYear
|
|
117
|
+
Theme.Easter
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Browser Usage
|
|
121
|
+
|
|
122
|
+
```html
|
|
123
|
+
<script type="module">
|
|
124
|
+
import { AiCats } from 'https://unpkg.com/@aicats/sdk/dist/index.mjs';
|
|
125
|
+
|
|
126
|
+
const blob = await AiCats.random();
|
|
127
|
+
const img = document.createElement('img');
|
|
128
|
+
img.src = URL.createObjectURL(blob);
|
|
129
|
+
document.body.appendChild(img);
|
|
130
|
+
</script>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Requirements
|
|
134
|
+
|
|
135
|
+
- **Node.js 18+** (uses native `fetch`)
|
|
136
|
+
- **Modern browsers** (Chrome, Firefox, Safari, Edge)
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
MIT © [Mario Bertsch](https://mariobertsch.com)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A search result containing a cat image ID and URL
|
|
3
|
+
*/
|
|
4
|
+
interface SearchResult {
|
|
5
|
+
/** Unique identifier for the cat image */
|
|
6
|
+
id: string;
|
|
7
|
+
/** Direct URL to the cat image */
|
|
8
|
+
url: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Available themes for AI cat images
|
|
13
|
+
*/
|
|
14
|
+
declare enum Theme {
|
|
15
|
+
/** Standard cat images */
|
|
16
|
+
Default = "Default",
|
|
17
|
+
/** Spring-themed cats with flowers and nature */
|
|
18
|
+
Spring = "Spring",
|
|
19
|
+
/** Summer-themed cats with sun and beach vibes */
|
|
20
|
+
Summer = "Summer",
|
|
21
|
+
/** Autumn-themed cats with fall colors and leaves */
|
|
22
|
+
Autumn = "Autumn",
|
|
23
|
+
/** Winter-themed cats with snow and cozy scenes */
|
|
24
|
+
Winter = "Winter",
|
|
25
|
+
/** Halloween-themed cats with spooky elements */
|
|
26
|
+
Halloween = "Halloween",
|
|
27
|
+
/** Christmas-themed cats with festive decorations */
|
|
28
|
+
Xmas = "Xmas",
|
|
29
|
+
/** New Year's themed cats with celebrations */
|
|
30
|
+
NewYear = "NewYear",
|
|
31
|
+
/** Easter-themed cats with bunnies and eggs */
|
|
32
|
+
Easter = "Easter"
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Detailed information about a cat image
|
|
37
|
+
*/
|
|
38
|
+
interface CatInfo {
|
|
39
|
+
/** Unique identifier for the cat image */
|
|
40
|
+
id: string;
|
|
41
|
+
/** Unix timestamp when the image was created */
|
|
42
|
+
dateCreated: number;
|
|
43
|
+
/** The AI prompt used to generate this cat image */
|
|
44
|
+
prompt: string;
|
|
45
|
+
/** The theme of the cat image */
|
|
46
|
+
theme: Theme;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Available image sizes for AI cat images
|
|
51
|
+
*/
|
|
52
|
+
declare enum Size {
|
|
53
|
+
/** 1024x1024 pixels (default, highest quality) */
|
|
54
|
+
Large = "1024",
|
|
55
|
+
/** 512x512 pixels */
|
|
56
|
+
Medium = "512",
|
|
57
|
+
/** 256x256 pixels */
|
|
58
|
+
Small = "256",
|
|
59
|
+
/** 128x128 pixels */
|
|
60
|
+
Thumbnail = "128",
|
|
61
|
+
/** 64x64 pixels */
|
|
62
|
+
Icon = "64",
|
|
63
|
+
/** 32x32 pixels */
|
|
64
|
+
Tiny = "32",
|
|
65
|
+
/** 16x16 pixels */
|
|
66
|
+
Micro = "16"
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Options for getting a random cat */
|
|
70
|
+
interface RandomCatOptions {
|
|
71
|
+
/** Image size (default: Large) */
|
|
72
|
+
size?: Size;
|
|
73
|
+
/** Theme of the cat image */
|
|
74
|
+
theme?: Theme;
|
|
75
|
+
}
|
|
76
|
+
/** Options for searching cats */
|
|
77
|
+
interface SearchOptions {
|
|
78
|
+
/** Search query (e.g., "orange fluffy cat") */
|
|
79
|
+
query?: string;
|
|
80
|
+
/** Maximum number of results (1-100, default: 10) */
|
|
81
|
+
limit?: number;
|
|
82
|
+
/** Pagination cursor - ID to start from */
|
|
83
|
+
from?: string;
|
|
84
|
+
/** Sort by newest first */
|
|
85
|
+
descending?: boolean;
|
|
86
|
+
/** Filter by theme */
|
|
87
|
+
theme?: Theme;
|
|
88
|
+
/** Image size in results */
|
|
89
|
+
size?: Size;
|
|
90
|
+
}
|
|
91
|
+
/** Options for similar cats */
|
|
92
|
+
interface SimilarOptions {
|
|
93
|
+
/** Maximum number of results (1-100, default: 10) */
|
|
94
|
+
limit?: number;
|
|
95
|
+
/** Image size in results */
|
|
96
|
+
size?: Size;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
declare const AiCats: {
|
|
100
|
+
random: (options?: RandomCatOptions) => Promise<Blob>;
|
|
101
|
+
getById: (id: string, size?: Size) => Promise<Blob>;
|
|
102
|
+
getInfo: (id: string) => Promise<CatInfo>;
|
|
103
|
+
search: (options?: SearchOptions) => Promise<SearchResult[]>;
|
|
104
|
+
getSimilar: (id: string, options?: SimilarOptions) => Promise<SearchResult[]>;
|
|
105
|
+
getSearchCompletion: (options?: SearchOptions) => Promise<string>;
|
|
106
|
+
getThemes: () => Promise<string[]>;
|
|
107
|
+
getCount: (theme?: Theme) => Promise<number>;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export { AiCats, type CatInfo, type RandomCatOptions, type SearchOptions, type SearchResult, type SimilarOptions, Size, Theme };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A search result containing a cat image ID and URL
|
|
3
|
+
*/
|
|
4
|
+
interface SearchResult {
|
|
5
|
+
/** Unique identifier for the cat image */
|
|
6
|
+
id: string;
|
|
7
|
+
/** Direct URL to the cat image */
|
|
8
|
+
url: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Available themes for AI cat images
|
|
13
|
+
*/
|
|
14
|
+
declare enum Theme {
|
|
15
|
+
/** Standard cat images */
|
|
16
|
+
Default = "Default",
|
|
17
|
+
/** Spring-themed cats with flowers and nature */
|
|
18
|
+
Spring = "Spring",
|
|
19
|
+
/** Summer-themed cats with sun and beach vibes */
|
|
20
|
+
Summer = "Summer",
|
|
21
|
+
/** Autumn-themed cats with fall colors and leaves */
|
|
22
|
+
Autumn = "Autumn",
|
|
23
|
+
/** Winter-themed cats with snow and cozy scenes */
|
|
24
|
+
Winter = "Winter",
|
|
25
|
+
/** Halloween-themed cats with spooky elements */
|
|
26
|
+
Halloween = "Halloween",
|
|
27
|
+
/** Christmas-themed cats with festive decorations */
|
|
28
|
+
Xmas = "Xmas",
|
|
29
|
+
/** New Year's themed cats with celebrations */
|
|
30
|
+
NewYear = "NewYear",
|
|
31
|
+
/** Easter-themed cats with bunnies and eggs */
|
|
32
|
+
Easter = "Easter"
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Detailed information about a cat image
|
|
37
|
+
*/
|
|
38
|
+
interface CatInfo {
|
|
39
|
+
/** Unique identifier for the cat image */
|
|
40
|
+
id: string;
|
|
41
|
+
/** Unix timestamp when the image was created */
|
|
42
|
+
dateCreated: number;
|
|
43
|
+
/** The AI prompt used to generate this cat image */
|
|
44
|
+
prompt: string;
|
|
45
|
+
/** The theme of the cat image */
|
|
46
|
+
theme: Theme;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Available image sizes for AI cat images
|
|
51
|
+
*/
|
|
52
|
+
declare enum Size {
|
|
53
|
+
/** 1024x1024 pixels (default, highest quality) */
|
|
54
|
+
Large = "1024",
|
|
55
|
+
/** 512x512 pixels */
|
|
56
|
+
Medium = "512",
|
|
57
|
+
/** 256x256 pixels */
|
|
58
|
+
Small = "256",
|
|
59
|
+
/** 128x128 pixels */
|
|
60
|
+
Thumbnail = "128",
|
|
61
|
+
/** 64x64 pixels */
|
|
62
|
+
Icon = "64",
|
|
63
|
+
/** 32x32 pixels */
|
|
64
|
+
Tiny = "32",
|
|
65
|
+
/** 16x16 pixels */
|
|
66
|
+
Micro = "16"
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Options for getting a random cat */
|
|
70
|
+
interface RandomCatOptions {
|
|
71
|
+
/** Image size (default: Large) */
|
|
72
|
+
size?: Size;
|
|
73
|
+
/** Theme of the cat image */
|
|
74
|
+
theme?: Theme;
|
|
75
|
+
}
|
|
76
|
+
/** Options for searching cats */
|
|
77
|
+
interface SearchOptions {
|
|
78
|
+
/** Search query (e.g., "orange fluffy cat") */
|
|
79
|
+
query?: string;
|
|
80
|
+
/** Maximum number of results (1-100, default: 10) */
|
|
81
|
+
limit?: number;
|
|
82
|
+
/** Pagination cursor - ID to start from */
|
|
83
|
+
from?: string;
|
|
84
|
+
/** Sort by newest first */
|
|
85
|
+
descending?: boolean;
|
|
86
|
+
/** Filter by theme */
|
|
87
|
+
theme?: Theme;
|
|
88
|
+
/** Image size in results */
|
|
89
|
+
size?: Size;
|
|
90
|
+
}
|
|
91
|
+
/** Options for similar cats */
|
|
92
|
+
interface SimilarOptions {
|
|
93
|
+
/** Maximum number of results (1-100, default: 10) */
|
|
94
|
+
limit?: number;
|
|
95
|
+
/** Image size in results */
|
|
96
|
+
size?: Size;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
declare const AiCats: {
|
|
100
|
+
random: (options?: RandomCatOptions) => Promise<Blob>;
|
|
101
|
+
getById: (id: string, size?: Size) => Promise<Blob>;
|
|
102
|
+
getInfo: (id: string) => Promise<CatInfo>;
|
|
103
|
+
search: (options?: SearchOptions) => Promise<SearchResult[]>;
|
|
104
|
+
getSimilar: (id: string, options?: SimilarOptions) => Promise<SearchResult[]>;
|
|
105
|
+
getSearchCompletion: (options?: SearchOptions) => Promise<string>;
|
|
106
|
+
getThemes: () => Promise<string[]>;
|
|
107
|
+
getCount: (theme?: Theme) => Promise<number>;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export { AiCats, type CatInfo, type RandomCatOptions, type SearchOptions, type SearchResult, type SimilarOptions, Size, Theme };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AiCats: () => AiCats,
|
|
24
|
+
Size: () => Size,
|
|
25
|
+
Theme: () => Theme
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
|
|
29
|
+
// src/models/enums/size.enum.ts
|
|
30
|
+
var Size = /* @__PURE__ */ ((Size2) => {
|
|
31
|
+
Size2["Large"] = "1024";
|
|
32
|
+
Size2["Medium"] = "512";
|
|
33
|
+
Size2["Small"] = "256";
|
|
34
|
+
Size2["Thumbnail"] = "128";
|
|
35
|
+
Size2["Icon"] = "64";
|
|
36
|
+
Size2["Tiny"] = "32";
|
|
37
|
+
Size2["Micro"] = "16";
|
|
38
|
+
return Size2;
|
|
39
|
+
})(Size || {});
|
|
40
|
+
|
|
41
|
+
// src/models/enums/theme.enum.ts
|
|
42
|
+
var Theme = /* @__PURE__ */ ((Theme2) => {
|
|
43
|
+
Theme2["Default"] = "Default";
|
|
44
|
+
Theme2["Spring"] = "Spring";
|
|
45
|
+
Theme2["Summer"] = "Summer";
|
|
46
|
+
Theme2["Autumn"] = "Autumn";
|
|
47
|
+
Theme2["Winter"] = "Winter";
|
|
48
|
+
Theme2["Halloween"] = "Halloween";
|
|
49
|
+
Theme2["Xmas"] = "Xmas";
|
|
50
|
+
Theme2["NewYear"] = "NewYear";
|
|
51
|
+
Theme2["Easter"] = "Easter";
|
|
52
|
+
return Theme2;
|
|
53
|
+
})(Theme || {});
|
|
54
|
+
|
|
55
|
+
// src/api/v1.api.ts
|
|
56
|
+
var ApiUrl = "https://api.ai-cats.net/v1";
|
|
57
|
+
async function random(options) {
|
|
58
|
+
const params = new URLSearchParams();
|
|
59
|
+
if (options?.size) params.set("size", options.size);
|
|
60
|
+
if (options?.theme) params.set("theme", options.theme);
|
|
61
|
+
const query = params.toString() ? `?${params}` : "";
|
|
62
|
+
const response = await fetch(`${ApiUrl}/cat${query}`);
|
|
63
|
+
if (!response.ok) {
|
|
64
|
+
throw new Error(`Error fetching cat image: ${response.statusText}`);
|
|
65
|
+
}
|
|
66
|
+
const buffer = await response.arrayBuffer();
|
|
67
|
+
return new Blob([buffer], { type: "image/jpeg" });
|
|
68
|
+
}
|
|
69
|
+
async function getById(id, size = "1024" /* Large */) {
|
|
70
|
+
const response = await fetch(`${ApiUrl}/cat/${id}?size=${size}`);
|
|
71
|
+
if (!response.ok) {
|
|
72
|
+
throw new Error(`Error fetching cat image: ${response.statusText}`);
|
|
73
|
+
}
|
|
74
|
+
const buffer = await response.arrayBuffer();
|
|
75
|
+
return new Blob([buffer], { type: "image/jpeg" });
|
|
76
|
+
}
|
|
77
|
+
async function getInfo(id) {
|
|
78
|
+
const response = await fetch(`${ApiUrl}/cat/info/${id}`);
|
|
79
|
+
if (!response.ok) {
|
|
80
|
+
throw new Error(`Error fetching cat info: ${response.statusText}`);
|
|
81
|
+
}
|
|
82
|
+
return response.json();
|
|
83
|
+
}
|
|
84
|
+
async function search(options = {}) {
|
|
85
|
+
const params = new URLSearchParams();
|
|
86
|
+
if (options.query) params.set("query", options.query);
|
|
87
|
+
if (options.limit) params.set("limit", options.limit.toString());
|
|
88
|
+
if (options.from) params.set("from", options.from);
|
|
89
|
+
if (options.descending) params.set("descending", "true");
|
|
90
|
+
if (options.theme) params.set("theme", options.theme);
|
|
91
|
+
if (options.size) params.set("size", options.size);
|
|
92
|
+
const query = params.toString() ? `?${params}` : "";
|
|
93
|
+
const response = await fetch(`${ApiUrl}/cat/search${query}`);
|
|
94
|
+
if (!response.ok) {
|
|
95
|
+
throw new Error(`Error searching for cats: ${response.statusText}`);
|
|
96
|
+
}
|
|
97
|
+
return response.json();
|
|
98
|
+
}
|
|
99
|
+
async function getSimilar(id, options) {
|
|
100
|
+
const params = new URLSearchParams();
|
|
101
|
+
if (options?.limit) params.set("limit", options.limit.toString());
|
|
102
|
+
if (options?.size) params.set("size", options.size);
|
|
103
|
+
const query = params.toString() ? `?${params}` : "";
|
|
104
|
+
const response = await fetch(`${ApiUrl}/cat/similar/${id}${query}`);
|
|
105
|
+
if (!response.ok) {
|
|
106
|
+
throw new Error(`Error fetching similar cats: ${response.statusText}`);
|
|
107
|
+
}
|
|
108
|
+
return response.json();
|
|
109
|
+
}
|
|
110
|
+
async function getSearchCompletion(options = {}) {
|
|
111
|
+
const params = new URLSearchParams();
|
|
112
|
+
if (options.query) params.set("query", options.query);
|
|
113
|
+
if (options.limit) params.set("limit", options.limit.toString());
|
|
114
|
+
if (options.from) params.set("from", options.from);
|
|
115
|
+
if (options.descending) params.set("descending", "true");
|
|
116
|
+
if (options.theme) params.set("theme", options.theme);
|
|
117
|
+
if (options.size) params.set("size", options.size);
|
|
118
|
+
const query = params.toString() ? `?${params}` : "";
|
|
119
|
+
const response = await fetch(`${ApiUrl}/cat/search-completion${query}`);
|
|
120
|
+
if (!response.ok) {
|
|
121
|
+
throw new Error(`Error fetching completion: ${response.statusText}`);
|
|
122
|
+
}
|
|
123
|
+
const data = await response.json();
|
|
124
|
+
return data.completion;
|
|
125
|
+
}
|
|
126
|
+
async function getThemes() {
|
|
127
|
+
const response = await fetch(`${ApiUrl}/cat/themes`);
|
|
128
|
+
if (!response.ok) {
|
|
129
|
+
throw new Error(`Error fetching themes: ${response.statusText}`);
|
|
130
|
+
}
|
|
131
|
+
const data = await response.json();
|
|
132
|
+
return data.themes;
|
|
133
|
+
}
|
|
134
|
+
async function getCount(theme) {
|
|
135
|
+
const response = await fetch(`${ApiUrl}/cat/count${theme ? `?theme=${theme}` : ""}`);
|
|
136
|
+
if (!response.ok) {
|
|
137
|
+
throw new Error(`Error fetching count: ${response.statusText}`);
|
|
138
|
+
}
|
|
139
|
+
const data = await response.json();
|
|
140
|
+
return data.count;
|
|
141
|
+
}
|
|
142
|
+
var V1Api = {
|
|
143
|
+
random,
|
|
144
|
+
getById,
|
|
145
|
+
getInfo,
|
|
146
|
+
search,
|
|
147
|
+
getSimilar,
|
|
148
|
+
getSearchCompletion,
|
|
149
|
+
getThemes,
|
|
150
|
+
getCount
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// src/index.ts
|
|
154
|
+
var AiCats = V1Api;
|
|
155
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
156
|
+
0 && (module.exports = {
|
|
157
|
+
AiCats,
|
|
158
|
+
Size,
|
|
159
|
+
Theme
|
|
160
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// src/models/enums/size.enum.ts
|
|
2
|
+
var Size = /* @__PURE__ */ ((Size2) => {
|
|
3
|
+
Size2["Large"] = "1024";
|
|
4
|
+
Size2["Medium"] = "512";
|
|
5
|
+
Size2["Small"] = "256";
|
|
6
|
+
Size2["Thumbnail"] = "128";
|
|
7
|
+
Size2["Icon"] = "64";
|
|
8
|
+
Size2["Tiny"] = "32";
|
|
9
|
+
Size2["Micro"] = "16";
|
|
10
|
+
return Size2;
|
|
11
|
+
})(Size || {});
|
|
12
|
+
|
|
13
|
+
// src/models/enums/theme.enum.ts
|
|
14
|
+
var Theme = /* @__PURE__ */ ((Theme2) => {
|
|
15
|
+
Theme2["Default"] = "Default";
|
|
16
|
+
Theme2["Spring"] = "Spring";
|
|
17
|
+
Theme2["Summer"] = "Summer";
|
|
18
|
+
Theme2["Autumn"] = "Autumn";
|
|
19
|
+
Theme2["Winter"] = "Winter";
|
|
20
|
+
Theme2["Halloween"] = "Halloween";
|
|
21
|
+
Theme2["Xmas"] = "Xmas";
|
|
22
|
+
Theme2["NewYear"] = "NewYear";
|
|
23
|
+
Theme2["Easter"] = "Easter";
|
|
24
|
+
return Theme2;
|
|
25
|
+
})(Theme || {});
|
|
26
|
+
|
|
27
|
+
// src/api/v1.api.ts
|
|
28
|
+
var ApiUrl = "https://api.ai-cats.net/v1";
|
|
29
|
+
async function random(options) {
|
|
30
|
+
const params = new URLSearchParams();
|
|
31
|
+
if (options?.size) params.set("size", options.size);
|
|
32
|
+
if (options?.theme) params.set("theme", options.theme);
|
|
33
|
+
const query = params.toString() ? `?${params}` : "";
|
|
34
|
+
const response = await fetch(`${ApiUrl}/cat${query}`);
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
throw new Error(`Error fetching cat image: ${response.statusText}`);
|
|
37
|
+
}
|
|
38
|
+
const buffer = await response.arrayBuffer();
|
|
39
|
+
return new Blob([buffer], { type: "image/jpeg" });
|
|
40
|
+
}
|
|
41
|
+
async function getById(id, size = "1024" /* Large */) {
|
|
42
|
+
const response = await fetch(`${ApiUrl}/cat/${id}?size=${size}`);
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
throw new Error(`Error fetching cat image: ${response.statusText}`);
|
|
45
|
+
}
|
|
46
|
+
const buffer = await response.arrayBuffer();
|
|
47
|
+
return new Blob([buffer], { type: "image/jpeg" });
|
|
48
|
+
}
|
|
49
|
+
async function getInfo(id) {
|
|
50
|
+
const response = await fetch(`${ApiUrl}/cat/info/${id}`);
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
throw new Error(`Error fetching cat info: ${response.statusText}`);
|
|
53
|
+
}
|
|
54
|
+
return response.json();
|
|
55
|
+
}
|
|
56
|
+
async function search(options = {}) {
|
|
57
|
+
const params = new URLSearchParams();
|
|
58
|
+
if (options.query) params.set("query", options.query);
|
|
59
|
+
if (options.limit) params.set("limit", options.limit.toString());
|
|
60
|
+
if (options.from) params.set("from", options.from);
|
|
61
|
+
if (options.descending) params.set("descending", "true");
|
|
62
|
+
if (options.theme) params.set("theme", options.theme);
|
|
63
|
+
if (options.size) params.set("size", options.size);
|
|
64
|
+
const query = params.toString() ? `?${params}` : "";
|
|
65
|
+
const response = await fetch(`${ApiUrl}/cat/search${query}`);
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
throw new Error(`Error searching for cats: ${response.statusText}`);
|
|
68
|
+
}
|
|
69
|
+
return response.json();
|
|
70
|
+
}
|
|
71
|
+
async function getSimilar(id, options) {
|
|
72
|
+
const params = new URLSearchParams();
|
|
73
|
+
if (options?.limit) params.set("limit", options.limit.toString());
|
|
74
|
+
if (options?.size) params.set("size", options.size);
|
|
75
|
+
const query = params.toString() ? `?${params}` : "";
|
|
76
|
+
const response = await fetch(`${ApiUrl}/cat/similar/${id}${query}`);
|
|
77
|
+
if (!response.ok) {
|
|
78
|
+
throw new Error(`Error fetching similar cats: ${response.statusText}`);
|
|
79
|
+
}
|
|
80
|
+
return response.json();
|
|
81
|
+
}
|
|
82
|
+
async function getSearchCompletion(options = {}) {
|
|
83
|
+
const params = new URLSearchParams();
|
|
84
|
+
if (options.query) params.set("query", options.query);
|
|
85
|
+
if (options.limit) params.set("limit", options.limit.toString());
|
|
86
|
+
if (options.from) params.set("from", options.from);
|
|
87
|
+
if (options.descending) params.set("descending", "true");
|
|
88
|
+
if (options.theme) params.set("theme", options.theme);
|
|
89
|
+
if (options.size) params.set("size", options.size);
|
|
90
|
+
const query = params.toString() ? `?${params}` : "";
|
|
91
|
+
const response = await fetch(`${ApiUrl}/cat/search-completion${query}`);
|
|
92
|
+
if (!response.ok) {
|
|
93
|
+
throw new Error(`Error fetching completion: ${response.statusText}`);
|
|
94
|
+
}
|
|
95
|
+
const data = await response.json();
|
|
96
|
+
return data.completion;
|
|
97
|
+
}
|
|
98
|
+
async function getThemes() {
|
|
99
|
+
const response = await fetch(`${ApiUrl}/cat/themes`);
|
|
100
|
+
if (!response.ok) {
|
|
101
|
+
throw new Error(`Error fetching themes: ${response.statusText}`);
|
|
102
|
+
}
|
|
103
|
+
const data = await response.json();
|
|
104
|
+
return data.themes;
|
|
105
|
+
}
|
|
106
|
+
async function getCount(theme) {
|
|
107
|
+
const response = await fetch(`${ApiUrl}/cat/count${theme ? `?theme=${theme}` : ""}`);
|
|
108
|
+
if (!response.ok) {
|
|
109
|
+
throw new Error(`Error fetching count: ${response.statusText}`);
|
|
110
|
+
}
|
|
111
|
+
const data = await response.json();
|
|
112
|
+
return data.count;
|
|
113
|
+
}
|
|
114
|
+
var V1Api = {
|
|
115
|
+
random,
|
|
116
|
+
getById,
|
|
117
|
+
getInfo,
|
|
118
|
+
search,
|
|
119
|
+
getSimilar,
|
|
120
|
+
getSearchCompletion,
|
|
121
|
+
getThemes,
|
|
122
|
+
getCount
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// src/index.ts
|
|
126
|
+
var AiCats = V1Api;
|
|
127
|
+
export {
|
|
128
|
+
AiCats,
|
|
129
|
+
Size,
|
|
130
|
+
Theme
|
|
131
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aicats/sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Official JavaScript SDK for the ai-cats.net API",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=18"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
24
|
+
"public": "npm publish --access public"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/AiCatsAPI/ai-cats-sdk.git"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"ai",
|
|
32
|
+
"cats",
|
|
33
|
+
"api",
|
|
34
|
+
"sdk",
|
|
35
|
+
"ai-cats",
|
|
36
|
+
"images"
|
|
37
|
+
],
|
|
38
|
+
"author": {
|
|
39
|
+
"name": "Mario Bertsch",
|
|
40
|
+
"url": "https://mariobertsch.com"
|
|
41
|
+
},
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/AiCatsAPI/ai-cats-sdk/issues"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://ai-cats.net",
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"prettier": "^3.8.1",
|
|
49
|
+
"tsup": "^8.5.1",
|
|
50
|
+
"typescript": "^5.9.3"
|
|
51
|
+
}
|
|
52
|
+
}
|