packageDocumentation module import { RequestInit } from 'node-fetch' ; import siteJson from './sites.json' ; import Site from './structures/Site' ; import SiteInfo from './structures/SiteInfo' ; export interface SMap < V > { [ key ] : V ; } type gelTags = { 'rating:e' : 'rating:explicit' ; 'rating:q' : 'rating:questionable' ; 'rating:s' : 'rating:safe' ; [ key ] : string ; } ; const expandedTags = { 'rating:e' : 'rating:explicit' , 'rating:q' : 'rating:questionable' , 'rating:s' : 'rating:safe' , } ; /**
 * A map of site url/ SiteInfo export const sites = siteJson as unknown as SMap < SiteInfo > ; type { Error } export class BooruError extends Error { constructor ( message ) { super ( message instanceof Error ? message . message : message ) ; if ( message instanceof Error ) { this . stack = message . stack ; } else { Error . captureStackTrace ( this , BooruError ) ; } this . name = 'BooruError' ; } } private export const USER_AGENT = `booru (https://github.com/AtoraSuunva/booru)` ; private param { String [ ] } tags function expandTags ( tags ) { return tags . map ( ( v ) => { const ex = expandedTags [ v . toLowerCase ( ) ] ; return encodeURIComponent ( ex ? ex : v ) ; } ) ; } private param { string } domain param { Site } site param { string [ ] } tags param { number } limit param { number } page export function searchURI ( site , tags = [ ] , limit = 100 , page ) { return ( `http${ site . insecure ? '' : 's' }://` + `${ site . domain }${ site . api . search }` + `${ site . tagQuery }=${ expandTags ( tags ) . join ( '+' ) }` + `&limit=${ limit }` + `&${ site . paginate }=${ page }` ) ; } private export const defaultOptions = { headers : { Accept : 'application/json, application/xml;q=0.9, */*;q=0.8' , 'User-Agent' : USER_AGENT , } , } ;