UNPKG

@musicorum/lastfm

Version:

Fully typed [Last.fm](https://last.fm) api client library written and made for Typescript!

39 lines (38 loc) 1.61 kB
import { PaginatedResponseAttributes } from './types/packages/common'; export type RequesterFn<R> = (page: number) => Promise<R[]>; /** * Paginated results for a resource. This can be used to get specific pages or multiple pages */ export default class PaginatedResult<RESOURCE> { private requester; readonly totalPages: number; readonly totalResults: number; readonly perPage: number; private readonly pages; constructor(attr: PaginatedResponseAttributes, requester: RequesterFn<RESOURCE>); /** * Appends contents of a page to this paginated result * @param page The page number of the contents to append * @param items The resources of that page to append * @returns This current paginated result */ appendPage(page: number, items: RESOURCE[]): this; /** * Get the contents from a page * @param page The page to get the contents from. Page numbers start from 1 * @returns A list of the resources of that specific page */ getPage(page: number): RESOURCE[]; /** * Get all contents fetched from this paginated result * @returns All contents of all fetched pages. Note that missing pages will be ignoed */ getAll(): RESOURCE[]; /** * Fetches content from a page from the API, if it wasn't fetched yet * @param page The page number to fetch content from. Page numbers start from 1 * @param force This will force to fetch that page, even if it's already fetched * @returns The results from that page. */ fetchPage(page: number, force?: boolean): Promise<RESOURCE[]>; }