booru
Version:
Search (and do other things) on a bunch of different boorus!
146 lines • 5.62 kB
TypeScript
/**
* @packageDocumentation
* @module Boorus
*/
import type InternalSearchParameters from '../structures/InternalSearchParameters';
import type SearchParameters from '../structures/SearchParameters';
import SearchResults from '../structures/SearchResults';
import type Site from '../structures/Site';
import TagListResults from '../structures/TagListResults';
export type BooruCredentials = Record<string, string>;
interface SearchUrlParams {
tags: string[];
limit: number;
page: number;
}
interface TagsURLParams {
limit?: number | undefined;
page?: number | undefined;
}
/**
* A basic, JSON booru
* @example
* ```
* const Booru = require('booru')
* // Aliases are supported
* const e9 = Booru('e9')
*
* // You can then search the site
* const imgs = await e9.search(['cat', 'cute'], {limit: 3})
*
* // And use the images
* imgs.forEach(i => console.log(i.fileUrl))
*
* // Or access other methods on the Booru
* e9.postView(imgs[0].id)
* ```
*/
export declare class Booru {
/** The domain of the booru */
domain: string;
/** The site object representing this booru */
site: Site;
/** The credentials to use for this booru */
credentials?: BooruCredentials | undefined;
/**
* Create a new booru from a site
*
* @private
* @param site The site to use
* @param credentials Credentials for the API
*/
constructor(site: Site, credentials?: BooruCredentials);
protected normalizeTags(tags: string | string[]): string[];
/**
* Search for images on this booru
* @param {String|String[]} tags The tag(s) to search for
* @param {SearchParameters} searchArgs The arguments for the search
* @return {Promise<SearchResults>} The results as an array of Posts
*/
search(tags: string | string[], { limit, random, page, showUnavailable, }?: SearchParameters): Promise<SearchResults>;
/**
* Gets the total number of posts for a specific tag or tag combination
* @param {String|String[]} tags The tag(s) to search for
* @return {Promise<number>} The total number of posts
*/
getPostCount(tags: string | string[]): Promise<number>;
/**
* Gets the url you'd see in your browser from a post id for this booru
*
* @param {String} id The id to get the postView for
* @return {String} The url to the post
*/
postView(id: string | number): string;
/**
* Gets a list of tags from the booru
* @param {Partial<TagsURLParams>} [params] The parameters for the tags list
* @param {number} [params.limit=100] The limit of tags to return
* @param {number} [params.page=1] The page of tags to return
* @return {Promise<any[]>} A promise with the tags as an array
*/
tagList({ limit, page, }?: Partial<TagsURLParams>): Promise<TagListResults>;
/**
* The internal & common searching logic, pls dont use this use .search instead
*
* @protected
* @param {String[]|String} tags The tags to search with
* @param {InternalSearchParameters} searchArgs The arguments for the search
* @return {Promise<Object>}
*/
protected doSearchRequest(tags: string[], { uri, limit, random, page, }?: InternalSearchParameters): Promise<any>;
/**
* The internal & common postCount logic, pls dont use this use .postCount instead
*
* @protected
* @param {String[]|String} tags The tags to search with
* @param {InternalSearchParameters} searchArgs The arguments for the search
* @return {Promise<Object>}
*/
protected doPostCountRequest(tags: string[], { uri, limit }?: InternalSearchParameters): Promise<number>;
private getPostCountNumber;
/**
* Generates a URL to search the booru with, mostly for debugging purposes
* @param opt
* @param {string[]} [opt.tags] The tags to search for
* @param {number} [opt.limit] The limit of results to return
* @param {number} [opt.page] The page of results to return
* @returns A URL to search the booru
*/
getSearchUrl({ tags, limit, page, }?: Partial<SearchUrlParams>): string;
/**
* Generates a URL to search the booru with, mostly for debugging purposes
* @param opt
* @param {string[]} [opt.tags] The tags to search for
* @param {number} [opt.limit] The limit of results to return
* @param {number} [opt.page] The page of results to return
* @returns A URL to search the booru
*/
getPostCountUrl({ tags, limit, }?: Partial<SearchUrlParams>): string;
/**
* Generates a URL to get a list of tags from the booru
* @param opt
* @param {number} [opt.limit] The limit of tags to return
* @param {number} [opt.page] The page of tags to return
* @returns {string} A URL to get the tags list
*/
getTagListUrl({ limit, page, }?: Partial<TagsURLParams>): string;
/**
* Parse the response from the booru
*
* @protected
* @param {Object} result The response of the booru
* @param {InternalSearchParameters} searchArgs The arguments used for the search
* @return {SearchResults} The results of this search
*/
protected parseSearchResult(result: any, { fakeLimit, tags, limit, random, page, showUnavailable, }: InternalSearchParameters): SearchResults;
/**
* Parse the response from the booru for a tag list
*
* @param result
* @param param1
* @returns
*/
protected parseTagListResult(result: any, { limit, page }?: Partial<TagsURLParams>): TagListResults;
}
export default Booru;
//# sourceMappingURL=Booru.d.ts.map