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

@glyphmoe/sdk

v0.1.10

Published

SDK for building Glyph extensions — types, request helpers, HTML parsing, and source factory

Readme

@glyphmoe/sdk

SDK for building Glyph extensions. Provides HTTP helpers, HTML parsing, rate limiting, retries, cookie management, and the source factory.

Install

npm install @glyphmoe/sdk cheerio

cheerio is a peer dependency (used for HTML parsing).

Quick Start

import { createSource, get, load, buildUrl, RateLimit } from '@glyphmoe/sdk'

const BASE = 'https://example-novels.com'

export default createSource({
  id: 'example',
  name: 'Example Novels',
  baseUrl: BASE,
  icon: `${BASE}/favicon.ico`,
  language: 'en',
  rateLimit: RateLimit.balanced,

  async searchNovels(query, page) {
    const html = await get(buildUrl(BASE, '/search', { q: query, page }))
    const $ = load(html)
    const items = $('div.result').map((_, el) => ({
      id: $(el).find('a').attr('href')!,
      title: $(el).find('h3').text().trim(),
      url: $(el).find('a').attr('href')!,
      cover: $(el).find('img').attr('src'),
    })).get()
    return { items, hasNextPage: $('a.next').length > 0 }
  },

  async fetchNovelDetails(novelUrl) {
    const html = await get(novelUrl)
    const $ = load(html)
    return {
      id: novelUrl, title: $('h1').text().trim(), url: novelUrl,
      chapters: $('ul.chapters a').map((i, el) => ({
        id: $(el).attr('href')!, title: $(el).text().trim(),
        number: i + 1, url: $(el).attr('href')!,
      })).get(),
    }
  },

  async fetchChapterContent(chapterUrl) {
    const $ = load(await get(chapterUrl))
    return $('div.content').html() ?? ''
  },
})

API

HTTP

  • get(url, headers?) — GET request, returns body string
  • post(url, body?, headers?) — POST request
  • json<T>(url, headers?) — GET + parse JSON
  • postJSON<T>(url, data, headers?) — POST JSON + parse response
  • request(req) / requestFull(req) — full control

Rate Limiting

// Via createSource (recommended):
rateLimit: RateLimit.strict   // 1 req/s
rateLimit: RateLimit.balanced // 3 req/s (recommended)
rateLimit: RateLimit.loose    // 10 req/s

// Or manually:
import { setRateLimit } from '@glyphmoe/sdk'
setRateLimit({ requests: 5, perSeconds: 2 })

Timeout

// Via createSource:
timeout: 60000  // 60s (default: 30s)

// Or manually:
import { setRequestTimeout } from '@glyphmoe/sdk'
setRequestTimeout(60000)

HTML Parsing

import { load } from '@glyphmoe/sdk' // re-export of cheerio.load
const $ = load(html)

Cookies

import { getCookies, setCookie } from '@glyphmoe/sdk'
const cookies = await getCookies('https://example.com')
setCookie('https://example.com', 'token', 'abc')

Content Rating

import { getMaxContentRating, isRatingAllowed } from '@glyphmoe/sdk'
const rating = await getMaxContentRating() // 'everyone'|'teen'|'mature'|'adult'

Pagination

import { fetchAllPages } from '@glyphmoe/sdk'
const all = await fetchAllPages(async (page) => {
  const items = await fetchPage(page)
  return { items, hasNextPage: items.length === 20 }
})

// With error recovery (returns partial results on failure):
const chapters = await fetchAllPages(fetcher, 1, 200, (error, page) => {
  console.warn(`Page ${page} failed:`, error)
  return 'stop' // or 'skip' to continue to next page
})

Testing

The SDK provides a mock system so extensions can be tested without real HTTP requests.

Setup

Your test setup file needs to provide the Application global that the SDK calls at runtime. The SDK ships a ready-made mock for this:

// test-setup.js (or .ts)
import { findMock, isMockEnabled } from '@glyphmoe/sdk/test-runtime'

globalThis.Application = {
  async scheduleRequest(request) {
    const mock = findMock(request.url)
    if (mock) {
      return [{ status: mock.status ?? 200, headers: mock.headers ?? {} }, mock.body]
    }
    if (isMockEnabled()) {
      throw new Error(`No mock registered for: ${request.url}`)
    }
    // Fallback to real fetch for integration tests
    const resp = await fetch(request.url, {
      method: request.method,
      headers: request.headers,
      body: request.body ?? undefined,
    })
    return [{ status: resp.status, headers: Object.fromEntries(resp.headers.entries()) }, await resp.text()]
  },
  async getDefaultUserAgent() { return 'Test/1.0' },
  async getCookies() { return {} },
  setCookie() {},
  async getMaxContentRating() { return 'adult' },
}

Then point your test runner at it (e.g. in vitest.config.ts):

export default defineConfig({
  test: { setupFiles: ['./test-setup.js'] },
})

Mocking requests

import { mockRequest, clearMocks } from '@glyphmoe/sdk/testing'

beforeEach(() => clearMocks())

mockRequest('https://example.com/search?q=test', {
  body: '<html>...</html>',
})

// Wildcard patterns
mockRequest('https://example.com/api/*', { body: '{}' }, { pattern: true })

Docs

Full documentation at glyph.moe/docs.

License

MIT