booru 2.6.0 → 2.6.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/dist/Constants.js +91 -1
- package/dist/Constants.js.map +1 -1
- package/dist/Utils.d.ts +8 -2
- package/dist/Utils.js +185 -1
- package/dist/Utils.js.map +1 -1
- package/dist/boorus/Booru.js +237 -1
- package/dist/boorus/Derpibooru.js +49 -1
- package/dist/boorus/XmlBooru.js +28 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +122 -1
- package/dist/index.js.map +1 -1
- package/dist/sites.json +1 -1
- package/dist/structures/InternalSearchParameters.js +7 -1
- package/dist/structures/Post.js +299 -1
- package/dist/structures/Post.js.map +1 -1
- package/dist/structures/SearchParameters.js +7 -1
- package/dist/structures/SearchResults.js +128 -1
- package/dist/structures/Site.js +51 -1
- package/dist/structures/SiteApi.js +7 -1
- package/dist/structures/SiteInfo.js +7 -1
- package/package.json +15 -15
|
@@ -1 +1,128 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
* @module Structures
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
|
+
if (mod && mod.__esModule) return mod;
|
|
24
|
+
var result = {};
|
|
25
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
26
|
+
__setModuleDefault(result, mod);
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
const Utils = __importStar(require("../Utils"));
|
|
31
|
+
/**
|
|
32
|
+
* Represents a page of search results, works like an array of {@link Post}
|
|
33
|
+
* <p> Usable like an array and allows to easily get the next page
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```
|
|
37
|
+
* const Booru = require('booru')
|
|
38
|
+
* // Safebooru
|
|
39
|
+
* const sb = new Booru('sb')
|
|
40
|
+
*
|
|
41
|
+
* const imgs = await sb.search('cat')
|
|
42
|
+
*
|
|
43
|
+
* // Log the images from the first page, then from the second
|
|
44
|
+
* imgs.forEach(i => console.log(i.postView))
|
|
45
|
+
* const imgs2 = await imgs.nextPage()
|
|
46
|
+
* imgs2.forEach(i => console.log(i.postView))
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
class SearchResults extends Array {
|
|
50
|
+
/** The booru used for this search */
|
|
51
|
+
booru;
|
|
52
|
+
/** The page of this search */
|
|
53
|
+
page;
|
|
54
|
+
/** The tags used for this search */
|
|
55
|
+
tags;
|
|
56
|
+
/** The options used for this search */
|
|
57
|
+
options;
|
|
58
|
+
/** The posts from this search result */
|
|
59
|
+
posts;
|
|
60
|
+
/** @private */
|
|
61
|
+
constructor(posts, tags, options, booru) {
|
|
62
|
+
super(posts.length);
|
|
63
|
+
for (let i = 0; i < posts.length; i++) {
|
|
64
|
+
this[i] = posts[i];
|
|
65
|
+
}
|
|
66
|
+
this.posts = posts;
|
|
67
|
+
this.tags = tags;
|
|
68
|
+
this.options = options;
|
|
69
|
+
this.booru = booru;
|
|
70
|
+
this.page = options ? options.page || 0 : 0;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get the first post in this result set
|
|
74
|
+
* @return {Post}
|
|
75
|
+
*/
|
|
76
|
+
get first() {
|
|
77
|
+
return this[0];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get the last post in this result set
|
|
81
|
+
* @return {Post}
|
|
82
|
+
*/
|
|
83
|
+
get last() {
|
|
84
|
+
return this[this.length - 1];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get the next page
|
|
88
|
+
* <p>Works like <code>sb.search('cat', {page: 1}); sb.search('cat', {page: 2})</code>
|
|
89
|
+
* @return {Promise<SearchResults>}
|
|
90
|
+
*/
|
|
91
|
+
nextPage() {
|
|
92
|
+
const opts = this.options;
|
|
93
|
+
opts.page = this.page + 1;
|
|
94
|
+
return this.booru.search(this.tags, opts);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Create a new SearchResults with just images with the matching tags
|
|
98
|
+
*
|
|
99
|
+
* @param {String[]|String} tags The tags (or tag) to search for
|
|
100
|
+
* @param {Object} options The extra options for the search
|
|
101
|
+
* @param {Boolean} [options.invert=false] If the results should be inverted and
|
|
102
|
+
* return images *not* tagged
|
|
103
|
+
* @return {SearchResults}
|
|
104
|
+
*/
|
|
105
|
+
tagged(tags, { invert = false } = {}) {
|
|
106
|
+
if (!Array.isArray(tags)) {
|
|
107
|
+
tags = [tags];
|
|
108
|
+
}
|
|
109
|
+
const posts = [];
|
|
110
|
+
for (const p of this) {
|
|
111
|
+
const m = Utils.compareArrays(tags, p.tags).length;
|
|
112
|
+
if ((!invert && m > 0) || (invert && m === 0)) {
|
|
113
|
+
posts.push(p);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return new SearchResults(posts, this.tags, this.options, this.booru);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Returns a SearchResults with images *not* tagged with any of the specified tags (or tag)
|
|
120
|
+
* @param {String[]|String} tags The tags (or tag) to blacklist
|
|
121
|
+
* @return {SearchResults} The results without any images with the specified tags
|
|
122
|
+
*/
|
|
123
|
+
blacklist(tags) {
|
|
124
|
+
return this.tagged(tags, { invert: true });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.default = SearchResults;
|
|
128
|
+
//# sourceMappingURL=SearchResults.js.map
|
package/dist/structures/Site.js
CHANGED
|
@@ -1 +1,51 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
* @module Structures
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
/**
|
|
8
|
+
* Represents a site, mostly used for JSDoc
|
|
9
|
+
*/
|
|
10
|
+
class Site {
|
|
11
|
+
/** The domain of the Site (the "google.com" part of "https://google.com/foo") */
|
|
12
|
+
domain;
|
|
13
|
+
/** The type of this site (json/xml/derpi) */
|
|
14
|
+
type;
|
|
15
|
+
/** The aliases of this site */
|
|
16
|
+
aliases;
|
|
17
|
+
/** If this site serves NSFW posts or not */
|
|
18
|
+
nsfw;
|
|
19
|
+
/** An object representing the api of this site */
|
|
20
|
+
api;
|
|
21
|
+
/** The url query param to paginate on the site */
|
|
22
|
+
paginate;
|
|
23
|
+
/**
|
|
24
|
+
* If the site supports `order:random`.
|
|
25
|
+
* If a string, this means a custom random system is used :/
|
|
26
|
+
*/
|
|
27
|
+
random;
|
|
28
|
+
/** The url query param for tags */
|
|
29
|
+
tagQuery;
|
|
30
|
+
/** The character to use to join tags when creating the search url */
|
|
31
|
+
tagJoin;
|
|
32
|
+
/** If this site supports only http:// */
|
|
33
|
+
insecure;
|
|
34
|
+
/** Tags to add to every request, if not included */
|
|
35
|
+
defaultTags;
|
|
36
|
+
constructor(data) {
|
|
37
|
+
this.domain = data.domain;
|
|
38
|
+
this.type = data.type ?? 'json';
|
|
39
|
+
this.aliases = data.aliases ?? [];
|
|
40
|
+
this.nsfw = data.nsfw;
|
|
41
|
+
this.api = data.api ?? {};
|
|
42
|
+
this.paginate = data.paginate ?? 'page';
|
|
43
|
+
this.random = data.random ?? false;
|
|
44
|
+
this.tagQuery = data.tagQuery ?? 'tags';
|
|
45
|
+
this.tagJoin = data.tagJoin ?? '+';
|
|
46
|
+
this.insecure = data.insecure ?? false;
|
|
47
|
+
this.defaultTags = data.defaultTags ?? [];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.default = Site;
|
|
51
|
+
//# sourceMappingURL=Site.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "booru",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.3",
|
|
4
4
|
"description": "Search (and do other things) on a bunch of different boorus!",
|
|
5
5
|
"author": "AtoraSuunva (https://github.com/AtoraSuunva/)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,27 +43,27 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"fast-xml-parser": "^4.0.9",
|
|
46
|
-
"undici": "^5.
|
|
46
|
+
"undici": "^5.10.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@babel/core": "^7.
|
|
49
|
+
"@babel/core": "^7.19.0",
|
|
50
50
|
"@babel/polyfill": "^7.12.1",
|
|
51
|
-
"@babel/preset-env": "^7.
|
|
51
|
+
"@babel/preset-env": "^7.19.0",
|
|
52
52
|
"@babel/preset-typescript": "^7.18.6",
|
|
53
|
-
"@swc/core": "^1.
|
|
54
|
-
"@types/jest": "^
|
|
55
|
-
"@types/node": "^18.
|
|
56
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
57
|
-
"@typescript-eslint/parser": "^5.
|
|
58
|
-
"eslint": "^8.
|
|
53
|
+
"@swc/core": "^1.3.0",
|
|
54
|
+
"@types/jest": "^29.0.1",
|
|
55
|
+
"@types/node": "^18.7.16",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^5.36.2",
|
|
57
|
+
"@typescript-eslint/parser": "^5.36.2",
|
|
58
|
+
"eslint": "^8.23.0",
|
|
59
59
|
"eslint-config-prettier": "^8.5.0",
|
|
60
60
|
"eslint-plugin-import": "^2.26.0",
|
|
61
|
-
"eslint-plugin-jsdoc": "^39.3.
|
|
62
|
-
"jest": "^
|
|
61
|
+
"eslint-plugin-jsdoc": "^39.3.6",
|
|
62
|
+
"jest": "^29.0.3",
|
|
63
63
|
"prettier": "^2.7.1",
|
|
64
|
-
"terser": "^5.
|
|
65
|
-
"ts-node": "^10.
|
|
66
|
-
"typescript": "^4.
|
|
64
|
+
"terser": "^5.15.0",
|
|
65
|
+
"ts-node": "^10.9.1",
|
|
66
|
+
"typescript": "^4.8.3"
|
|
67
67
|
},
|
|
68
68
|
"files": [
|
|
69
69
|
"dist/"
|