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

gobbet

v0.1.2

Published

Boundary-aware text chunking with overlap for LLM/embedding pipelines — respects paragraphs and sentences, pluggable size metric.

Downloads

31

Readme

gobbet

npm version License: MIT

Boundary-aware text chunking with overlap for LLM/embedding pipelines — respects paragraphs and sentences, pluggable size metric.

The problem

Feeding documents to LLMs or embedding models requires splitting text into size-constrained chunks. Naive splitters that cut every N characters break sentences mid-word and lose meaning at chunk boundaries, reducing the quality of downstream processing.

Effective chunking needs to respect text boundaries (paragraphs → sentences → words) while maintaining context through overlap. Most solutions either drag in heavy framework dependencies or don't handle both boundaries and overlap well.

Install

npm install gobbet
# or
pnpm add gobbet
# or
yarn add gobbet

Use

Quick start with default character counting:

import gobbet from "gobbet";

const text = "Paragraph one. Paragraph two. Paragraph three.";
const chunks = gobbet(text, { size: 30, overlap: 5 });
// Result: chunks split on sentence boundaries, with 5-char overlap

Realistic example with overlap and custom token measure:

import gobbet from "gobbet";

const document = `Gobbet handles boundary-aware chunking for LLM pipelines.
It respects paragraph and sentence boundaries automatically.

With overlap, context is preserved across chunk boundaries.`;

// Chunk by approximate tokens (4 chars ≈ 1 token)
const tokenMeasure = (s: string) => Math.ceil(s.length / 4);
const chunks = gobbet(document, {
  size: 50,           // 50 tokens max per chunk
  overlap: 10,        // 10 tokens overlap between chunks
  measure: tokenMeasure,
  separators: ["\n\n", "\n", ". ", " ", ""]
});

// Each chunk satisfies: tokenMeasure(chunk.text) <= 50
// Chunks prefer paragraph breaks, then sentence breaks, then word breaks

API

gobbet(input, options)

Main function that splits text into boundary-aware chunks with optional overlap.

Parameters:

  • input: string — The text to chunk. Empty string returns empty array.
  • options: GobbetOptions — Configuration object

Returns: Chunk[] — Array of chunks sorted by position in original text.

Throws: RangeError — If size <= 0 or overlap >= size.

GobbetOptions

interface GobbetOptions {
  size: number;              // Maximum chunk size (must be > 0)
  overlap?: number;          // Overlap between chunks (default: 0, must be < size)
  measure?: (s: string) => number;  // Size metric (default: s.length)
  separators?: string[];     // Boundary preferences (default: ["\n\n", "\n", ". ", " ", ""])
}

Chunk

interface Chunk {
  text: string;   // Chunk content (includes overlap for all but first chunk)
  start: number;  // Character offset in original input (non-overlap content)
  end: number;    // Exclusive end offset (non-overlap content)
}

Non-goals

gobbet intentionally does NOT provide:

  • Markdown/HTML awareness: Does not understand document structure. Use a markdown parser first if needed.
  • Semantic chunking: Does not analyze content meaning. For embedding-based chunking, post-process with vector similarity.
  • Real tokenization: Uses pluggable measure functions instead. Pair with a tokenizer for accurate token counts.
  • Language detection: Treats all text uniformly. Handle language-specific needs in your measure function.

Composability example for markdown:

// First extract markdown sections, then chunk each
const sections = markdown.split(/^##\s+/m);
for (const section of sections) {
  const chunks = gobbet(section, { size: 100, overlap: 20 });
  // Process chunks...
}

TypeScript

gobbet is written in TypeScript with full type definitions. Import types for full type safety:

import gobbet, { type GobbetOptions, type Chunk } from "gobbet";

const options: GobbetOptions = { size: 100, overlap: 10 };
const chunks: Chunk[] = gobbet(input, options);

Related Packages

Caching & Concurrency:

Text Processing:

  • @azghr/shorn — Truncate strings by byte budget without breaking graphemes
  • seriatim — Sequential processing utilities

HTTP & Network:

  • forbear — Read server rate-limit instructions from HTTP responses
  • forestall — Delay execution until a condition is met
  • obviate — Render operations unnecessary through caching

System & Process:

  • quiesce — Ordered, timeboxed graceful shutdown for Node
  • sortition — Deterministic percentage rollouts and A/B bucketing
  • stanch — Stop flows or operations based on conditions

Utilities:

  • expunge — Remove or exclude items from collections
  • occlude — Hide or mask data and functionality
  • placemark — Geographic location and mapping utilities
  • specie — Currency and financial calculations

License

MIT