packageDocumentation module import Booru from '../boorus/Booru' ; import Post from '../structures/Post' ; import * as Utils from '../Utils' ; import SearchParameters from './SearchParameters' ; /**
 * Represents a page of search results, works like an array of  Post * <p> Usable like an array and allows to easily get the next page
 *
 *  example export default class SearchResults extends Array < Post > { /** The booru used for this search */ public booru : Booru ; /** The page of this search */ public page : number ; /** The tags used for this search */ public readonly tags : string [ ] ; /** The options used for this search */ public readonly options : SearchParameters ; /** The posts from this search result */ public readonly posts : Post [ ] ; private constructor ( posts , tags , options , booru ) { super ( posts . length ) ; for ( let i = 0 ; i < posts . length ; i ++ ) { this [ i ] = posts [ i ] ; } this . posts = posts ; this . tags = tags ; this . options = options ; this . booru = booru ; this . page = options ? options . page || 0 : 0 ; } return { Post } get first ( ) : Post { return this [ 0 ] ; } return { Post } get last ( ) : Post { return this [ this . length - 1 ] ; } return { Promise < SearchResults > } public nextPage ( ) { const opts = this . options ; opts . page = this . page + 1 ; return this . booru . search ( this . tags , opts ) ; } param { String [ ] | String } tags param options param { Boolean } options . invert return { SearchResults } public tagged ( tags , { invert = false } = { } ) { if ( ! Array . isArray ( tags ) ) { tags = [ tags ] ; } const posts = [ ] ; for ( const p of this ) { const m = Utils . compareArrays ( tags , p . tags ) . length ; if ( ( ! invert && m > 0 ) || ( invert && m === 0 ) ) { posts . push ( p ) ; } } return new SearchResults ( posts , this . tags , this . options , this . booru ) ; } param { String [ ] | String } tags return { SearchResults } public blacklist ( tags ) { return this . tagged ( tags , { invert : true } ) ; } }