nekosia.js 0.2.1 โ 0.2.3
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 +1 -1
- package/index.js +15 -15
- package/package.json +37 -35
- package/services/https.js +1 -1
- package/test/api.test.js +6 -6
- package/test/integration.test.js +2 -2
- package/types/tags.ts +1 -1
package/README.md
CHANGED
|
@@ -141,4 +141,4 @@ If you have any questions or issues, create a new [Issue](https://github.com/Nek
|
|
|
141
141
|
|
|
142
142
|
|
|
143
143
|
## ๐ ยป MIT License
|
|
144
|
-
Copyright 2024 ยฉ by [
|
|
144
|
+
Copyright 2024-2025 ยฉ by [Nekosia](https://nekosia.cat). All rights reserved.
|
package/index.js
CHANGED
|
@@ -5,28 +5,29 @@ const API_URL = `${BASE_URL}/api/v1`;
|
|
|
5
5
|
class NekosiaAPI {
|
|
6
6
|
buildQueryParams(options = {}) {
|
|
7
7
|
return Object.entries(options)
|
|
8
|
-
.filter(([, value]) =>
|
|
8
|
+
.filter(([, value]) =>
|
|
9
|
+
value != null &&
|
|
10
|
+
value !== '' &&
|
|
11
|
+
(!Array.isArray(value) || value.length > 0)
|
|
12
|
+
)
|
|
13
|
+
.map(([key, value]) => {
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
return `${encodeURIComponent(key)}=${value.map(v => encodeURIComponent(v)).join('%2C')}`;
|
|
16
|
+
}
|
|
9
17
|
if (typeof value === 'string' && value.includes(',')) {
|
|
10
|
-
throw new Error('
|
|
18
|
+
throw new Error('String values must not contain commas. Use an array instead.');
|
|
11
19
|
}
|
|
12
|
-
|
|
13
|
-
return value != null && value !== '' && (!Array.isArray(value) || value.length > 0);
|
|
20
|
+
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
14
21
|
})
|
|
15
|
-
.map(([key, value]) => `${encodeURIComponent(key)}=${value}`)
|
|
16
22
|
.join('&');
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
async makeHttpRequest(endpoint) {
|
|
20
|
-
|
|
21
|
-
return https.get(endpoint);
|
|
22
|
-
} catch (err) {
|
|
23
|
-
console.error(`HTTP request failed for endpoint ${endpoint}: ${err.message}`);
|
|
24
|
-
throw err;
|
|
25
|
-
}
|
|
26
|
+
return https.get(endpoint);
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
async fetchCategoryImages(category, options = {}) {
|
|
29
|
-
if (!category) {
|
|
30
|
+
if (typeof category !== 'string' || !category.trim()) {
|
|
30
31
|
throw new Error('Image category is required. For example: fetchCategoryImages(\'catgirl\')');
|
|
31
32
|
}
|
|
32
33
|
|
|
@@ -39,7 +40,7 @@ class NekosiaAPI {
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
const query = this.buildQueryParams(options);
|
|
42
|
-
return this.makeHttpRequest(`${API_URL}/images/${category}${query ? `?${query}` : ''}`);
|
|
43
|
+
return this.makeHttpRequest(`${API_URL}/images/${encodeURIComponent(category)}${query ? `?${query}` : ''}`);
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
async fetchImages(options = {}) {
|
|
@@ -65,8 +66,7 @@ class NekosiaAPI {
|
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
async fetchById(id) {
|
|
68
|
-
if (!id) throw new Error('`id` parameter is required');
|
|
69
|
-
|
|
69
|
+
if (typeof id !== 'string' || !id.trim()) throw new Error('`id` parameter is required');
|
|
70
70
|
return this.makeHttpRequest(`${API_URL}/getImageById/${id}`);
|
|
71
71
|
}
|
|
72
72
|
}
|
package/package.json
CHANGED
|
@@ -1,44 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nekosia.js",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "A simple wrapper for the Nekosia API that
|
|
3
|
+
"version": "0.2.3",
|
|
4
|
+
"description": "A simple wrapper for the Nekosia API that provides easy access to random anime images. Enrich your projects with a touch of anime magic and feline charm, meow~! Discover why switching to Nekosia is the purrfect choice! ๐",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"anime api",
|
|
7
|
-
"anime art",
|
|
8
|
-
"anime catgirls",
|
|
9
|
-
"anime characters",
|
|
10
|
-
"anime gifs",
|
|
11
|
-
"anime images",
|
|
12
|
-
"anime library",
|
|
13
|
-
"anime nekos",
|
|
14
|
-
"anime wallpaper",
|
|
15
6
|
"anime",
|
|
16
7
|
"anime-api",
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
8
|
+
"anime-wrapper",
|
|
9
|
+
"anime-images",
|
|
10
|
+
"anime-wallpaper",
|
|
11
|
+
"anime-girls",
|
|
12
|
+
"anime-catgirls",
|
|
13
|
+
"anime-nekos",
|
|
14
|
+
"neko",
|
|
15
|
+
"nekos",
|
|
16
|
+
"neko-girls",
|
|
21
17
|
"catgirl",
|
|
22
18
|
"catgirls",
|
|
23
|
-
"
|
|
24
|
-
"cute nekos",
|
|
25
|
-
"feline",
|
|
26
|
-
"girl",
|
|
27
|
-
"girls",
|
|
28
|
-
"image api",
|
|
29
|
-
"javascript",
|
|
30
|
-
"js library",
|
|
19
|
+
"waifu",
|
|
31
20
|
"kawaii",
|
|
32
|
-
"manga",
|
|
33
21
|
"moe",
|
|
34
|
-
"
|
|
35
|
-
"neko",
|
|
36
|
-
"nekos",
|
|
37
|
-
"nekosia api",
|
|
38
|
-
"nekosia",
|
|
22
|
+
"manga",
|
|
39
23
|
"otaku",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
24
|
+
"sfw",
|
|
25
|
+
"sfw-anime",
|
|
26
|
+
"random-anime",
|
|
27
|
+
"image-api",
|
|
28
|
+
"api-wrapper",
|
|
29
|
+
"booru",
|
|
30
|
+
"booru-api",
|
|
31
|
+
"nekosia",
|
|
32
|
+
"nekosia-api",
|
|
33
|
+
"nekosia-wrapper",
|
|
34
|
+
"nekos.life",
|
|
35
|
+
"nekos.fun",
|
|
36
|
+
"discord-bot",
|
|
37
|
+
"javascript",
|
|
38
|
+
"typescript"
|
|
42
39
|
],
|
|
43
40
|
"homepage": "https://nekosia.cat",
|
|
44
41
|
"bugs": {
|
|
@@ -49,16 +46,21 @@
|
|
|
49
46
|
"url": "git+https://github.com/Nekosia-API/nekosia.js.git"
|
|
50
47
|
},
|
|
51
48
|
"license": "MIT",
|
|
52
|
-
"author": "Sefinek <contact@
|
|
49
|
+
"author": "Sefinek <contact@nekosia.cat> (https://nekosia.cat)",
|
|
50
|
+
"type": "commonjs",
|
|
53
51
|
"main": "index.js",
|
|
54
52
|
"types": "types/index.d.ts",
|
|
53
|
+
"directories": {
|
|
54
|
+
"example": "examples",
|
|
55
|
+
"test": "test"
|
|
56
|
+
},
|
|
55
57
|
"scripts": {
|
|
56
58
|
"test": "jest",
|
|
57
59
|
"up": "ncu -u && npm install && npm update && npm audit fix"
|
|
58
60
|
},
|
|
59
61
|
"devDependencies": {
|
|
60
|
-
"@eslint/js": "^9.
|
|
61
|
-
"globals": "^16.
|
|
62
|
-
"jest": "^
|
|
62
|
+
"@eslint/js": "^9.29.0",
|
|
63
|
+
"globals": "^16.2.0",
|
|
64
|
+
"jest": "^30.0.2"
|
|
63
65
|
}
|
|
64
66
|
}
|
package/services/https.js
CHANGED
package/test/api.test.js
CHANGED
|
@@ -31,21 +31,21 @@ describe('nekosia.js tests', () => {
|
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
it('should fetch maximum allowed number of images (
|
|
35
|
-
const res = await NekosiaAPI.fetchCategoryImages('catgirl', { count:
|
|
34
|
+
it('should fetch maximum allowed number of images (20)', async () => {
|
|
35
|
+
const res = await NekosiaAPI.fetchCategoryImages('catgirl', { count: 20 });
|
|
36
36
|
|
|
37
37
|
expect(res.success).toBe(true);
|
|
38
38
|
expect(res.status).toBe(200);
|
|
39
39
|
expect(Array.isArray(res.images)).toBe(true);
|
|
40
|
-
expect(res.images.length).toBe(
|
|
40
|
+
expect(res.images.length).toBe(20);
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
it('should return error if count exceeds the maximum (
|
|
44
|
-
const res = await NekosiaAPI.fetchCategoryImages('catgirl', { count:
|
|
43
|
+
it('should return error if count exceeds the maximum (999)', async () => {
|
|
44
|
+
const res = await NekosiaAPI.fetchCategoryImages('catgirl', { count: 999 });
|
|
45
45
|
|
|
46
46
|
expect(res.success).toBe(false);
|
|
47
47
|
expect(res.status).toBe(400);
|
|
48
|
-
expect(res.message).toMatch(/Count must be between 1 and
|
|
48
|
+
expect(res.message).toMatch(/Count must be between 1 and/i);
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
it('should return error for invalid count value', async () => {
|
package/test/integration.test.js
CHANGED
|
@@ -12,7 +12,7 @@ describe('NekosiaAPI', () => {
|
|
|
12
12
|
it('should correctly build query params', () => {
|
|
13
13
|
const options = { count: 3, additionalTags: ['tag1', 'tag2', 'tag3', 'tag4'], emptyValue: '', nullValue: null };
|
|
14
14
|
const result = NekosiaAPI.buildQueryParams(options);
|
|
15
|
-
expect(result).toBe('count=3&additionalTags=tag1
|
|
15
|
+
expect(result).toBe('count=3&additionalTags=tag1%2Ctag2%2Ctag3%2Ctag4');
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
it('should return empty string for empty options', () => {
|
|
@@ -99,7 +99,7 @@ describe('NekosiaAPI', () => {
|
|
|
99
99
|
const mockResponse = { data: { results: [] } };
|
|
100
100
|
https.get.mockResolvedValue(mockResponse);
|
|
101
101
|
|
|
102
|
-
const expectedEndpoint = 'https://api.nekosia.cat/api/v1/images/nothing?count=1&additionalTags=dark
|
|
102
|
+
const expectedEndpoint = 'https://api.nekosia.cat/api/v1/images/nothing?count=1&additionalTags=dark%2Cshadow';
|
|
103
103
|
const res = await NekosiaAPI.fetchImages({ count: 1, tags: ['dark', 'shadow'] });
|
|
104
104
|
|
|
105
105
|
expect(res).toEqual(mockResponse);
|
package/types/tags.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export const TAGS =
|
|
2
|
-
['absolute-territory','after-the-rain','afternoon-tea','akazukin','alice-in-wonderland','alice-mana','alllisso','alluring-face','alona','alone','amamine','amamineko-cafe','amashiro-natsuki','angel','angry-face','animal-ears','apex','apple','apple-caramel','apple-pie','apron-dress','aqua','aquarium','aria-tsukushi','arknights','
|
|
2
|
+
['absolute-territory','after-the-rain','afternoon-tea','akazukin','alice-in-wonderland','alice-mana','alllisso','alluring-face','alona','alone','amamine','amamineko-cafe','amashiro-natsuki','angel','angry-face','animal-ears','apex','apple','apple-caramel','apple-pie','apron-dress','aqua','aquarium','aria-tsukushi','arknights','armed-girls','armpits','assault-rifle','autumn','autumn-leaves','axillary-costume','azki','azkiart','azur-lane','babydoll','back-alley','back-of-thigh','background','balloon','balloons','bandages','bandaid','bare-feet','barefoot','basketball','basketball-uniform','beach','beast-girl','beautiful','beautiful-legs','beautiful-reimu','bed','bed-hair','bedroom','belly-glimpse','bellybutton','bench','beret','bewitching-thighs','birthday','black-and-white','black-dress','black-hair','black-knee-high-socks','black-ribbon','black-sailor-uniform','black-shoes','black-skirt','black-thigh-high-socks','black-thigh-highs','black-tights','blazer','blonde','blonde-hair','bloomers','blue-archive','blue-eyes','blue-hair','blue-ribbon','blue-ribbon-ribbon','blue-shoes','blue-skirt','blue-sky','blushing','bocchi-chan','bonnet','book','boots','botamochi','bottomless','boy-cut','braid','breasts','brown-eyes','brown-hair','brown-skirt','bubble-tea','bunny-ears','bunny-girl','butterfly','by-the-window','cable-knitting','cafe','cake','camisole','camisole-dress','canal','candy-apple','car','cardigan','cardigan-uniform','casual-wear','cat','cat-and-girl','cat-ears','cat-ears-hat','cat-ears-headband','cat-ears-headphones','cat-ears-hoodie','cat-ears-maid','cat-mouth','cat-paws','cat-pose','cat-tail','catboy','catgirl','cats','cheeks','cherry','cherry-blossom','cherry-petals','chess','chibi','chihuahua','chin-resting','china-dress','chinese-lolita','chinese-style','chino','chino-kafuu','chitosezaka-suzu','chocolate','chocolate-cake','chocolate-mint','choker','christmas','chuuni','city','classroom','cloak','closed-eyes','clouds','cocoa-hoto','coffee','coffee-shop','collar','comic-treasure','confused','cookie','corset','cosmos','crossed-legs','crying','curtsy','cutaway-shoulder','cute','cute-cat','cuteness-is-justice','cyte','detexted','dog','dog-and-girl','dog-ears','dog-girl','doll','donut','doujin','drawers','drawmei','dress','dress-shirt','dvdart','elaina','elementary-school-student','elevator','epic-seven','eye-mask','eyepatch','fair-skin','fairy-eye','fairy-tale','fantasy','fantasy-girl','feather-ears','feet','feet-in-water','felicia-lulufleur','firefly','fireworks','fishnets','flare-skirt','flat-chest','floral-playing-cards','flower','flower-field','flowers','flowers-and-girls','food','footwear','forest','fox-ears','fox-mask','fox-shrine-maiden','foxgirl','frills','frostleaf','fubuki-shiragami','fubuki-shiragami-fanart','furina','fuwamoco','fuyoyo','fuzzy','game','game-pad','gamer','gamer-girl','garter','garterbelt','gawr-gura','gawrgura','genshin-impact','gensokyo-in-spring','getting-dressed','ghost','gijinka','girl','girls','glasses','gloves','gothic-lolita','green-eyes','green-hair','green-ribbon','guildcq','guitar','gun','gym-uniform','hair-tie-in-mouth','hairdressing','hairpin','hairstyle-change','hajime-todoroki','hakui-koyori','half-pants','half-pigtails','half-up-hairstyle','halloween','halo','hamico','han-costume','hanami','hands-forming-a-heart','happy','harness','haruhi-suzumiya','hatsune-miku','hayate-hisakawa','hazakura-chikori','headband','headboard-angle','headdress','headphone','headphones','headset','heart','heart-eyes','heartbreak','hearts','hedgehog','heels','herta','heterochromia','hibiki','hibiscus','high-angle','high-school-girl','high-waisted-skirt','hiiro','hikaru','hizamaru','holding-hands-with-fingers-interlocked','holding-ice-in-mouth','hololive','hololive-en','hololive-english','hololiveen','holox','hong','honkaistarrail','hood','hoodie','hoshi','hoshino','hoshizora-no-memoria','hot-spring','hu-tao','hutao','hydrangea','ice-cream','ichigo','ichigori-ena','idol','illumination','in-the-train','incredibly-cute','indie-vtuber','indoor-shoes','inner-color','inugami-korone','itigori-ena','jagged-sclera','japanese-maid','japanese-style','japanese-style-maid','japanese-umbrella','jellyfish','jk','jumper-skirt','jumpy','just-woke-up','kabashima-hana','kamiko-kana','kamioka-chiroru','kamisato-ayaka','kamiyama-shiki','kanade-otonose','kancolle','kanon-mashiro','kantai-collection','karin','katana','katcolle','kazari-rua','kazueru','kazusa-kyoyama','kimono','kimono-dress','kindergarten-pupil','kingdom','kirakira-monstars','kiryuu-kikyou','kitchen','klee','knee-high-socks','knitted-vest','koharu','koiko-irori','koito-amuno','korie-riko','koyori-hakui','koyori-sketch','kuda-izuna','kuro-namako','kuroneko','kyaru','kyouyama-kazusa','lancat','lanmewko','laplus-darkness','large-breasts','large-food','leaning-forward','left-foot-shield','legato','leggings','legs-in-water','lemon','leo','letter','lily-of-the-valley','lime','lingerie','little-devil','loafers','lolipop-complete','lolita','lollipop','long-black-hair','long-blonde-hair','long-brown-hair','long-hair','long-pink-hair','long-red-hair','long-silver-hair','long-white-gloves','long-white-hair','loungewear','love-letter','lying-down','lying-on-one-side','macaron','mad','magical-girl','maid','maid-uniform','makeup','mari-iochi','marie','marine-look','maruro','mascot','mayoi-shigure','melonpan','middle-school-student','midori-matsukaze','mihoshi-mei','miike-chan','mika','mika-misono','mikeneko','miko','minato-aqua','mini-hakama','miniskirt','miniskirt-miko','mint','mirror','miufarfalle','mizukiart','mococo','mococo-abyssgard','moon','murasaki-shion','muryo','myoya','nachoneko','nagi-hisakawa','nahida','nail-polish','nana-kagura','nanashi-mumei','nap','natori-sana','navy-sailor-blouse','necktie','negligee','nekoha-shizuku','nekomata-okayu','new-year','newsboy-cap','night','night-sky','nijisanji','nikke','nine-tailed','nintendo-switch','nintendoswitch','noire','nolan','nonaka-yuu','nurse','off-shoulder','okomeillust','omochi-box','omochi-monaka','one-eye-covered','one-piece','ookami-mio','orange-eyes','orange-hair','otokonoko','overalls','overly-long-sleeves','painting','pajamas','pancake','panda-ears','parasol','park','patting','peace-sign','pekora-usada-fanart','personification-of-drinks','petticoat','photo-editing','pigtails','pillow','pinching-garments','pink','pink-eyes','pink-hair','pink-ribbon','pink-shoes','pink-skirt','pink-twintails','plaid-pattern','plaid-skirt','platform','playing-cards','plump-thighs','plushie','pocky','pointy-ears','ponytail','porch','present','princess-connect','project-sekai','prone-position','pu-ht','purple-ears','purple-eyes','purple-hair','purple-ribbon','purple-skirt','queen-of-hearts','railroad-crossing','railway','rain','rainy-season','ramune','randoseru','rawr','red-and-blue','red-eyes','red-felt-cloth','red-hair','red-lacquered-umbrella','red-pigtails','red-ribbon','red-skirt','reflected-glare','regloss','reimu-hakurei','reisa-uzawa','remilia-scarlet','reverse-sitting','rhodes','ribbed-fabric','ribbon','ringo-chan','roar','rocket-launcher','rucaco','rukako','ruki-roki','rumi','runa-shinomiya','rurudo','rurudo-lion','rushia-uruha','sad','saiba-midori','saiba-momoi','sailor-dress','sailor-one-piece','sailor-uniform','sakamata-chloe','sakura','sakura-miko','sakuraba-moeka','sakurada-hane','sakuradahane','sakurai-hana','santa','sassy-loli','scared','scarf','scenery','school-girl','school-sweater','school-uniform','school-uniform-cardigan','school-uniform-hoodie','schoolgirl','scornful-eyes','sea','see-through','selfie','setokane','shano-hiyori','shanoa-asmr','shiba-inu','shigure','shiori','shirakawa-yumea','shirasu-azusa','shiroko','shiroko-terror','shiromichan','shooting-star','shopping','short-boots','short-hair','short-pants','short-white-hair','shouu-kun','showgirl','shrunken-girl','shy','silver-hair','silver-long-hair','singer','sisters','sitting','skirt','skirt-lift','sleeping','sleepwear','sleepy','sleepy-face','sleeveless','sleeveless-dress','sleeveless-parka','small-fangs','smartphone','smile','smug-face','sneakers','snow','snowman','snowy-landscape','socks','sofa','sole','somna','sorasaki-hina','sousei','spiral-eyes','splashes','spring','squirrel','standing-picture','starlight-stage','starry-sky','starry-sky-dress','steamed-bun-with-meat-filling','straight-fringe','strap-shoes','straw-hat','strawberries','strawberry','streaked-hair','striped-thigh-high-socks','summer','summer-dress','summer-kimono','summer-pockets','sunaookami-shiroko','sunflowers','sunohara-kokona','sunset','supine','suspender-skirt','suzuho-hotaru','sweat','sweater','sweets','swimwear','swing','sword','tail','tail-from-under-skirt','tail-holding','tail-with-ribbon','taiwan','takanashi','takanashi-hoshino','tea','tea-time','tears','teary-eyed','teddy-bear','telephone','the-person-behind','the-soles-of-feet-in-socks','thick-eyebrows','thigh-high-socks','thighhighs','thighs','three-colored-dumpling','tiered-dress','tiger','tight','tired','tobu-railway','toes','tongue-out','touhou','touhou-project','tropical-fish','twins','twintails','uise-iu','umbrella','underwater','uniform','upwards-gaze','usada-pekora','usagigo','valentine','vampire','vdonburi','vocaloid','vrchat','vtuber','w-sitting','wa-lolita','waitress','wallpaper','wallpapers','water-surface','watermelon','weapon','wedding-dress','wet','what-is-this-cuteness','white-cat','white-day','white-dress','white-hair','white-high-socks','white-knee-high-socks','white-long-hair','white-ribbon','white-sailor-uniform','white-skirt','white-socks','white-thigh-high-socks','white-tiger','white-tights','white-twintails','wings','wink','winter','witch','wolf','wolf-ears','wolf-girl','yandere','yaoyao','yawn','yellow-eyes','yellow-hair','yellow-ribbon','yoko','young-boy','young-girl','yuika-shiina','yuimisu','yukata','yukihana-lamy','yukinoshita-peo','yutori-natsu','yuuki-sakuna'] as const;
|
|
3
3
|
|
|
4
4
|
// GET https://api.nekosia.cat/api/v1/tags
|