Skip to main content
Paginator for posts

Hierarchy

Constructors

constructor

new PostPaginator(fetchPage): PostPaginator Creates a new paginator instance

Parameters

NameTypeDescription
fetchPage(token?: string) => Promise<PaginatedResponse<any>>Function that fetches a page of data given a pagination token

Returns

PostPaginator

Inherited from

Paginator.constructor

Defined in

paginator.ts:87

Accessors

items

get items(): T[] Get all fetched items

Returns

T[]

Inherited from

Paginator.items

Defined in

paginator.ts:94

meta

get meta(): any Get current pagination metadata

Returns

any

Inherited from

Paginator.meta

Defined in

paginator.ts:101

includes

get includes(): undefined | Record<string, any> Get current includes data

Returns

undefined | Record<string, any>

Inherited from

Paginator.includes

Defined in

paginator.ts:108

errors

get errors(): undefined | any[] Get current errors

Returns

undefined | any[]

Inherited from

Paginator.errors

Defined in

paginator.ts:115

done

get done(): boolean Check if pagination is done

Returns

boolean

Inherited from

Paginator.done

Defined in

paginator.ts:122

rateLimited

get rateLimited(): boolean Check if rate limit was hit

Returns

boolean

Inherited from

Paginator.rateLimited

Defined in

paginator.ts:129

posts

get posts(): any[]

Returns

any[]

Defined in

paginator.ts:339

Methods

fetchNext

fetchNext(): Promise<void> Fetch the next page and add items to current instance This method fetches the next page of data and appends the items to the current paginator instance. It updates the pagination state and metadata.

Returns

Promise<void> Example
const followers = await client.users.getFollowers('783214');
await followers.fetchNext(); // Fetch first page
console.log(followers.items.length); // Number of followers

if (!followers.done) {
  await followers.fetchNext(); // Fetch second page
  console.log(followers.items.length); // Total followers across pages
}
Throws When the API request fails

Inherited from

Paginator.fetchNext

Defined in

paginator.ts:153

next

next(): Promise<Paginator<any>> Get next page as a new instance This method creates a new paginator instance that starts from the next page, without affecting the current paginator’s state.

Returns

Promise<Paginator<any>> New paginator instance for the next page Example
const followers = await client.users.getFollowers('783214');
await followers.fetchNext(); // Fetch first page

if (!followers.done) {
  const nextPage = await followers.next(); // Get next page as new instance
  console.log(followers.items.length); // Still first page
  console.log(nextPage.items.length); // Second page
}

Inherited from

Paginator.next

Defined in

paginator.ts:208

fetchPrevious

fetchPrevious(): Promise<void> Fetch previous page (if supported)

Returns

Promise<void>

Inherited from

Paginator.fetchPrevious

Defined in

paginator.ts:222

previous

previous(): Promise<Paginator<any>> Get previous page as a new instance

Returns

Promise<Paginator<any>>

Inherited from

Paginator.previous

Defined in

paginator.ts:257

fetchLast

fetchLast(count): Promise<void> Fetch up to a specified number of additional items

Parameters

NameType
countnumber

Returns

Promise<void>

Inherited from

Paginator.fetchLast

Defined in

paginator.ts:271

reset

reset(): void Reset paginator to initial state

Returns

void

Inherited from

Paginator.reset

Defined in

paginator.ts:285

[iterator]

[iterator](): Iterator<any, any, undefined> Iterator for all fetched items

Returns

Iterator<any, any, undefined>

Inherited from

Paginator.[iterator]

Defined in

paginator.ts:300

[asyncIterator]

[asyncIterator](): AsyncIterator<any, any, undefined> Async iterator that fetches pages automatically

Returns

AsyncIterator<any, any, undefined>

Inherited from

Paginator.[asyncIterator]

Defined in

paginator.ts:309