UNPKG

booru

Version:

Search (and do other things) on a bunch of different boorus!

102 lines 3.5 kB
/** * @packageDocumentation * @module Utils */ import { type AnySite } from './Constants'; /** * Check if `site` is a supported site (and check if it's an alias and return the sites's true name) * * @param {String} domain The site to resolveSite * @return {String?} null if site is not supported, the site otherwise */ export declare function resolveSite(domain: string): AnySite | null; /** * Parses posts xml to json, which can be used with js * * @private * @param {String} xml The xml to convert to json * @return {Object[]} A Promise with an array of objects created from the xml */ export declare function jsonifyPosts(xml: string): object[]; /** * Parses tags xml to json, which can be used with js * * @private * @param {String} xml The xml to convert to json * @return {Object[]} A Promise with an array of objects created from the xml */ export declare function jsonifyTags(xml: string): object[]; /** * Try to parse JSON, and then return an empty array if data is an empty string, or the parsed JSON * * Blame rule34.xxx for returning literally an empty response with HTTP 200 for this * @param data The data to try and parse * @returns Either the parsed data, or an empty array */ export declare function tryParseJSON(data: string): Record<string, unknown>[]; /** * Yay fisher-bates * Taken from http://stackoverflow.com/a/2450976 * * @private * @param {Array} array Array of something * @return {Array} Shuffled array of something */ export declare function shuffle<T>(array: T[]): T[]; /** * Generate a random int between [min, max] * * @private * @param {Number} min The minimum (inclusive) * @param {Number} max The maximum (inclusive) */ export declare function randInt(min: number, max: number): number; /** * Performs some basic search validation * * @private * @param {String} site The site to resolve * @param {Number|String} limit The limit for the amount of images to fetch */ export declare function validateSearchParams(site: string, limit: number | string): { site: string; limit: number; }; /** * Finds the matching strings between two arrays * * @private * @param {String[]} arr1 The first array * @param {String[]} arr2 The second array * @return {String[]} The shared strings between the arrays */ export declare function compareArrays(arr1: string[], arr2: string[]): string[]; type URIEncodable = string | number | boolean; type QueryValue = URIEncodable | URIEncodable[]; interface QuerystringOptions { arrayJoin?: string; } interface EncodeURIQueryValueOptions { arrayJoin?: string; } /** * Turns an object into a query string, correctly encoding uri components * * @example * const options = { page: 10, limit: 100 } * const query = querystring(options) // 'page=10&limit=100' * console.log(`https://example.com?${query}`) * * @param query An object with key/value pairs that will be turned into a string * @returns A string that can be appended to a url (after `?`) */ export declare function querystring(query: Record<string, QueryValue>, { arrayJoin }?: QuerystringOptions): string; /** * Encodes a single value or an array of values to be usable in as a URI component, * joining array elements with '+' * @param value The value to encode * @returns An encoded value that can be passed to a querystring */ export declare function encodeURIQueryValue(value: QueryValue, { arrayJoin }?: EncodeURIQueryValueOptions): string; export {}; //# sourceMappingURL=Utils.d.ts.map