AniLink - v3.0.0
    Preparing search index...

    Function malPaginate

    • Collect items from MyAnimeList list pages until the list ends or the maxPages limit is reached.

      The helper calls fetchPage(page, perPage, signal) for each page. The callback maps the page number to endpoint parameters with offset = (page - 1) * perPage. A response with a paging node and no next URL ends traversal, even if the page is full. Without a paging node, a short page ends traversal. The maxPages limit bounds requests. Like AniList's paginate, this helper uses the shared engine.

      Type Parameters

      • TItem

        The list entry shape of the paginated endpoint.

      Parameters

      • fetchPage: (page: number, perPage: number, signal?: AbortSignal) => Promise<MalPage<TItem>>

        Callback that fetches a single page given its 1-based number, perPage, and an optional AbortSignal forwarded from the traversal; return the raw MAL list response ({ data, paging? }).

      • Optionaloptions: MalPaginateOptions

        Optional perPage, startPage, maxPages, concurrency, signal, onPage, and onHookError controls.

      Returns Promise<MalPaginateResult<TItem>>

      The collected items, per-page snapshots, page count, and whether the maxPages guard truncated the run.

      An AniLinkValidationError when a fetched page response has no data key at all (a closure returning the wrong object); a present non-array value collects nothing.

      A TypeError when a numeric option is defined but not a finite, positive integer.

      const result = await aniLink.mal.paginate(
      (page, perPage, signal) => aniLink.mal.anime.search(
      { q: "one piece", limit: perPage, offset: (page - 1) * perPage },
      { signal }
      ),
      { perPage: 100, maxPages: 5 }
      );
      console.log(result.items.length, result.pageCount, result.truncated);