Home Manual Reference Source Repository

Function

Static Public Summary
public

clone(input: *, clonePrivate: boolean): *

public

Get all the pages from a PaginatedResourceListing or a range

Static Public

public clone(input: *, clonePrivate: boolean): * source

Params:

NameTypeAttributeDescription
input *
clonePrivate boolean
  • optional
  • default: true

Return:

*

public async getPaginatedRange(page: Promise<PaginatedResourceListing> | PaginatedResourceListing, start: Number, stop: Number): Promise<Array<ResourceBase>> source

import {getPaginatedRange} from '@mapcreator/api/src/utils/helpers.js'

Get all the pages from a PaginatedResourceListing or a range

Params:

NameTypeAttributeDescription
page Promise<PaginatedResourceListing> | PaginatedResourceListing

Promise that returns a PaginatedResourceListing

start Number
  • optional
  • default: 1
  • nullable: true

Start page

stop Number
  • optional
  • nullable: true

Stop page, defaults to the page count if not filled in.

Return:

Promise<Array<ResourceBase>>

multiple pages

Throw:

ApiError

If the api returns errors

Example:

import { helpers } from "@mapcreator/api";

const promise = api.users.list(1, 50); // 50 per page is more efficient

helpers.getPaginatedRange(promise).then(data => {
   data.map(row => `[${row.id}] ${row.name}`) // We just want the names
       .forEach(console.log) // Log the names and ids of every user
})