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

coverpage

v0.0.1

Published

obtain an optimal set of pages covering a set of integer intervals

Downloads

1

Readme

coverpage

Many APIs giving access to list of items use the concept of pages. Some of them enforce you to request these lists of items by giving a page size and a page index.

What if you only knows which items indexes you want to obtain and you want to know the optimal set of pages you need to request in order to get all of these items?

coverpage tries to answer this question by providing you this minimal API:

const coverpage = require('coverpage')(pageSize => π => {
  // compute the cost of the paged interval π knowing its boundaries and the page size
  return cost;
});

coverpage(I1, I2, ..., IN) // Ix are integer pairs [lower bound, upper bound]

The cost function is entirely up to you, see further for what data is bound to a paged interval.

Note that it first takes the page size as its only argument and then should return a function taking a paged interval as its only argument, this later function must finally return the cost as a number.

Also note that the upper bound of an interval is the lowest integer greater than any element of the interval and is thus not part of the interval.

The following prerequisite on integer intervals passed in argument is required: I1 < I2 < ... < IN. Which means that the intervals must be disjoint and passed in ascending order. coverpage will throw an error if this prerequisite is not fulfilled.

Given all these intervals, coverpage will return a set of objects having the following structure:

{
  pageSize: pageSize, // the size of all pages used by the paged intervals
  cost: cost, // the cost of this current set of paged intervals computed with the cost function given to coverpage
  pagedIntervals: [
    [lowerBound1, upperBound1, lowerIntervalIndex1, upperIntervalIndex1],
    // ...
    [lowerBoundM, upperBoundM, lowerIntervalIndexM, upperIntervalIndexM]
  ]
]

Each paged interval is a tuple (an array) with four elements:

  • the first element is the lowest integer in the paged interval and is by construct a multiple of the page size
  • the second element is the lowest integer that is greater than any element in the paged interval and is also by construct a multiple of the page size
  • the third element is the lowest index of the interval passed as argument that is covered by the current paged interval
  • the fourth element is the lowest index of the interval that is greater than the current paged interval

In order to get page indexes, you can just divide the first and second elements by the page size:

  • the first one will provide the first page index from the paged interval
  • the second one will provide the first page index that is not part anymore of the paged interval