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

connectionify

v0.1.5

Published

Convert page number based pagenation to cursor based connection

Downloads

3

Readme

Connectionify

Change page-number-based pagination to cursor-based connection conforming to Relay Server Specification.

What is the Connection?

Install

$ yarn add connectionify

If your API...

Assume that your API

  • using pagination based on page-number.
  • 1 page has 5 items.

/users.json?&pageNum=1

{
  "items": [
    { "id": "a937e5fb-35e1-575f-b5e3-ac6e9409c624" },
    { "id": "577dce48-5167-56a6-b3e7-893407fa54dc" },
    { "id": "44eb22a3-48a1-5275-a2ef-e103da8674ae" },
    { "id": "1421a3b1-5468-51a4-a758-0b901c8f4315" },
    { "id": "c8c39625-217d-5095-ac23-c64367c9303d" }
  ],
  "pageInfo": {
    "currentPageNum": 1,
    "nextPageNum": 2,
    "prevPageNum": null
  }
}

Usage

import connectionify from 'connectionify'
import { getUsers } from './api'

const getUsersConnection = connectionify(({ pageNum }) => {
  return getUsers({
    pageNum,
  })
}, {
  itemNumPerPage: 5,
})

const connection = await getUsersConnection({
  first: 8,
})

Result

{
  "edges": [
    {
      "cursor": "MSMw",
      "node": { "id": "a937e5fb-35e1-575f-b5e3-ac6e9409c624" }
    },
    {
      "cursor": "MSMx",
      "node": { "id": "577dce48-5167-56a6-b3e7-893407fa54dc" }
    },
    {
      "cursor": "MSMy",
      "node": { "id": "44eb22a3-48a1-5275-a2ef-e103da8674ae" }
    },
    {
      "cursor": "MSMz",
      "node": { "id": "1421a3b1-5468-51a4-a758-0b901c8f4315" }
    },
    {
      "cursor": "MSM0",
      "node": { "id": "c8c39625-217d-5095-ac23-c64367c9303d" }
    },
    {
      "cursor": "MiMw",
      "node": { "id": "b6949725-7349-5dbf-a078-d56b7445f07c" }
    },
    {
      "cursor": "MiMx",
      "node": { "id": "d37c5be5-44fd-5410-8b0a-91282f4a5bc5" }
    },
    {
      "cursor": "MiMy",
      "node": { "id": "aae1f1db-ff6d-5b27-8759-faa05754aec3" }
    },
  ],
  "pageInfo": {
    "hasNextPage": true,
    "hasPrevPage": false,
    "startCursor": "MSMw",
    "endCursor" "MiMy"
  }
}

See also

Todo

  • [ ] support 'last' argument without 'before' argument
  • [ ] offset-based pagination support
  • [ ] connectionify as a nexus.js plugin

If you have a feature request or a bug, please create a new issue. And also, pull requests are always welcome🙏