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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@sphido/collections

v1.0.0

Published

Sorting, pagination, tag pages and prev/next navigation helpers for Sphido pages

Readme

@sphido/collections

Small pure helpers over the Sphido pages tree: sorting, pagination, tag pages and prev/next navigation. Zero runtime dependencies — just functions, in the spirit of Sphido. Pairs with @sphido/hashtags for generating /tag/... pages.

Install

pnpm add @sphido/collections

API

sortBy(pages, selector, direction = 'asc')

Stable sort by the selector result (string | number | Date). Pages where the selector returns undefined always go last, regardless of direction. Returns a new array — the input is never mutated.

import { sortBy } from '@sphido/collections';

const posts = sortBy(pages, (page) => page.date, 'desc'); // newest first
const alphabetical = sortBy(pages, (page) => page.title);

paginate(pages, perPage)

Splits pages into chunks of perPage items and returns Array<{items, page, total, prev, next}>. page is 1-based; prev and next are page numbers or null at the boundaries. Empty input returns an empty array. Throws a RangeError when perPage < 1.

import { paginate } from '@sphido/collections';

for (const { items, page, total, prev, next } of paginate(posts, 10)) {
	console.log(`page ${page}/${total}`, items.length, { prev, next });
}

groupByTag(pages, key = 'tags')

Groups pages by tag into a Map<string, Page[]> with keys sorted by tag name. Accepts both a Set (as produced by the hashtags extender) and an array (as produced by frontmatter) on the page; pages without the key are skipped.

import { groupByTag } from '@sphido/collections';

for (const [tag, tagged] of groupByTag(posts)) {
	console.log(tag, tagged.map((page) => page.title));
}

siblings(pages, page)

Returns {prev, next} for a page within the given ordered array, matched by identity. Either side is null at the boundaries; if the page is not found, both are null.

import { siblings } from '@sphido/collections';

const { prev, next } = siblings(posts, page);

Recipe: blog with tag pages and pagination

A complete blog index with pagination, /tag/<tag>/ pages and prev/next links in the article footer — no custom utility code needed:

import { getPages, allPages, writeFile } from '@sphido/core';
import { hashtags } from '@sphido/hashtags';
import { sortBy, paginate, groupByTag, siblings } from '@sphido/collections';

const pages = await getPages({ path: 'content' }, hashtags);

// 1. All posts, newest first
const posts = sortBy([...allPages(pages)], (page) => page.date, 'desc');

// 2. Paginated blog index: /index.html, /page/2/index.html, ...
for (const { items, page, total, prev, next } of paginate(posts, 10)) {
	const list = items.map((post) => `- [${post.name}](/${post.name}/)`).join('\n');
	const nav = [
		prev ? `[← newer](${prev === 1 ? '/' : `/page/${prev}/`})` : '',
		next ? `[older →](/page/${next}/)` : '',
	].join(' ');

	await writeFile(
		page === 1 ? 'public/index.html' : `public/page/${page}/index.html`,
		`<main>${list}</main><nav>${nav} (${page}/${total})</nav>`,
	);
}

// 3. Tag pages: /tag/<tag>/index.html (targets of the links @sphido/hashtags generates)
for (const [tag, tagged] of groupByTag(posts)) {
	const list = tagged.map((post) => `- [${post.name}](/${post.name}/)`).join('\n');
	await writeFile(`public/tag/${tag}/index.html`, `<h1>#${tag}</h1><main>${list}</main>`);
}

// 4. Article pages with prev/next navigation in the footer
for (const post of posts) {
	const { prev, next } = siblings(posts, post);
	const footer = [
		prev ? `[← ${prev.name}](/${prev.name}/)` : '',
		next ? `[${next.name} →](/${next.name}/)` : '',
	].join(' ');

	await writeFile(`public/${post.name}/index.html`, `<article>${post.content}</article><footer>${footer}</footer>`);
}

Need just the latest N posts? Plain posts.slice(0, n) is all it takes — no wrapper needed.

Source code

@sphido/collections