npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@salling-group/pagination-traverser

v1.0.1

Published

A library for traversing paginated API resources.

Downloads

4

Readme

Salling Group Pagination Traverser

Traverser helps you paginate through Salling Group API resources (e.g. the Stores API serves stores in pages). It relies on a Link header in responses and will throw an error if none is present. Traverser class is required like this:

const Traverser = require('@salling-group/pagination-traverser');

The class is instantiated like this:

const traverser = new Traverser(instance, '/v1/stores/', {
  'params': {
    'brand': 'netto',
  },
});

The parameters for the initialization is:

| Parameter | Required | Type | Description | |-----------|----------|------|-------------| |instance| Yes | Axios instance|An authenticated Axios instance (see NPM module @salling-group/auth). | |resource| Yes | String | The resource to traverse. | |baseOptions| No | Object | Axios options to apply to the requests. |

The Traverser class has the following methods:

| Method | Description | ---------|-------------| | async get() | Get the current page. | | async next() | Move the traverser to the next page and get it. | | async previous() | Move the traverser to the previous page and get it.| | async first() | Move the traverser to the first page and get it. | | async last() | Move the traverser to the last page and get it. | | async goto(page) | Move the traverser to the given page and get it. | | pageNumber() | Get the page that the traverser is on.

Example: Paginate response from Stores API

const Traverser = require('@salling-group/pagination-traverser');
const { createInstance } = require('@salling-group/auth');

const instance = createInstance({
  'auth': {
    'issuer': 'my_issuer',
    'secret': 'my_secret',
    'type': 'jwt',
  },
});
const traverser = new Traverser(instance, '/v1/stores/');

traverser.get().then((firstPage) => {
  console.log(firstPage);
  traverser.next().then((secondPage) => {
    console.log(secondPage);
  });
});