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.
@@ -1 +1,128 @@
1
- "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(t,e,r,s){void 0===s&&(s=r);var i=Object.getOwnPropertyDescriptor(e,r);i&&!("get"in i?!e.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,s,i)}:function(t,e,r,s){void 0===s&&(s=r),t[s]=e[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),__importStar=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)"default"!==r&&Object.prototype.hasOwnProperty.call(t,r)&&__createBinding(e,t,r);return __setModuleDefault(e,t),e};Object.defineProperty(exports,"__esModule",{value:!0});const Utils=__importStar(require("../Utils"));class SearchResults extends Array{booru;page;tags;options;posts;constructor(t,e,r,s){super(t.length);for(let e=0;e<t.length;e++)this[e]=t[e];this.posts=t,this.tags=e,this.options=r,this.booru=s,this.page=r&&r.page||0}get first(){return this[0]}get last(){return this[this.length-1]}nextPage(){const t=this.options;return t.page=this.page+1,this.booru.search(this.tags,t)}tagged(t,{invert:e=!1}={}){Array.isArray(t)||(t=[t]);const r=[];for(const s of this){const i=Utils.compareArrays(t,s.tags).length;(!e&&i>0||e&&0===i)&&r.push(s)}return new SearchResults(r,this.tags,this.options,this.booru)}blacklist(t){return this.tagged(t,{invert:!0})}}exports.default=SearchResults;
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
@@ -1 +1,51 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});class Site{domain;type;aliases;nsfw;api;paginate;random;tagQuery;tagJoin;insecure;defaultTags;constructor(a){this.domain=a.domain,this.type=a.type??"json",this.aliases=a.aliases??[],this.nsfw=a.nsfw,this.api=a.api??{},this.paginate=a.paginate??"page",this.random=a.random??!1,this.tagQuery=a.tagQuery??"tags",this.tagJoin=a.tagJoin??"+",this.insecure=a.insecure??!1,this.defaultTags=a.defaultTags??[]}}exports.default=Site;
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
@@ -1 +1,7 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});
1
+ "use strict";
2
+ /**
3
+ * @packageDocumentation
4
+ * @module Structures
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=SiteApi.js.map
@@ -1 +1,7 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});
1
+ "use strict";
2
+ /**
3
+ * @packageDocumentation
4
+ * @module Structures
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ //# sourceMappingURL=SiteInfo.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "booru",
3
- "version": "2.6.0",
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.7.0"
46
+ "undici": "^5.10.0"
47
47
  },
48
48
  "devDependencies": {
49
- "@babel/core": "^7.18.6",
49
+ "@babel/core": "^7.19.0",
50
50
  "@babel/polyfill": "^7.12.1",
51
- "@babel/preset-env": "^7.18.6",
51
+ "@babel/preset-env": "^7.19.0",
52
52
  "@babel/preset-typescript": "^7.18.6",
53
- "@swc/core": "^1.2.212",
54
- "@types/jest": "^28.1.5",
55
- "@types/node": "^18.0.3",
56
- "@typescript-eslint/eslint-plugin": "^5.30.6",
57
- "@typescript-eslint/parser": "^5.30.6",
58
- "eslint": "^8.19.0",
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.3",
62
- "jest": "^28.1.2",
61
+ "eslint-plugin-jsdoc": "^39.3.6",
62
+ "jest": "^29.0.3",
63
63
  "prettier": "^2.7.1",
64
- "terser": "^5.14.1",
65
- "ts-node": "^10.8.2",
66
- "typescript": "^4.7.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/"