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

prompt-chunker

v1.0.0

Published

Advanced prompt chunking library for AI applications. Split large prompts intelligently for LLMs.

Downloads

110

Readme

🚀 prompt-chunker

A high-performance, framework-agnostic library for intelligent prompt chunking.

Designed for AI developers building applications with LLMs (ChatGPT, Claude, Gemini) where long context needs to be managed efficiently on either the frontend or backend.

NPM Version License: MIT

✨ Why prompt-chunker?

Sending massive prompts to LLMs often leads to "Message too long" errors or context window exhaustion. prompt-chunker solves this by:

  • 🧠 Intelligent Splitting: Respects sentence boundaries and paragraphs.
  • 🔗 Contextual Overlap: Maintains coherence by overlapping chunk edges.
  • ⚛️ React Ready: Comes with a powerful usePromptChunker hook.
  • 🛠️ Environment Agnostic: Works in Browser, Node.js, and Edge environments.
  • Ultra Lightweight: Zero dependencies (core), tiny bundle size, tree-shakeable.

📦 Installation

npm install prompt-chunker

📖 Usage

Base Library (Node/Native JS)

import { Chunker } from 'prompt-chunker';

const text = "Your very long prompt here...";
const result = Chunker.split(text, {
  maxSize: 1000,
  overlap: 100,
  strategy: 'intelligent'
});

console.log(`Split into ${result.chunks.length} chunks`);
console.log(result.chunks[0].content);

React Hook

Perfect for building "Prompt Splitter" UIs or handled automated multi-message flows.

import { usePromptChunker } from 'prompt-chunker/react';

function PromptSplitter({ longPrompt }) {
  const { 
    currentChunk, 
    next, 
    prev, 
    isLast, 
    progress 
  } = usePromptChunker(longPrompt, { maxSize: 2000 });

  if (!currentChunk) return null;

  return (
    <div>
      <div className="progress-bar" style={{ width: `${progress}%` }} />
      <h3>Chunk {currentChunk.index} of {currentChunk.total}</h3>
      <pre>{currentChunk.content}</pre>
      
      <button onClick={prev}>Previous</button>
      <button onClick={next} disabled={isLast}>Next</button>
      
      <button onClick={() => navigator.clipboard.writeText(currentChunk.content)}>
        Copy to Clipboard
      </button>
    </div>
  );
}


💎 Advanced Features

💻 Code Block Protection

Unlike simple string splitters, prompt-chunker detects Markdown code blocks (...) and keeps them intact within a single chunk whenever possible. It will only split a code block if the block itself exceeds the maxSize.

🏁 Automatic Progress Headers

Want the LLM to know it's reading a multi-part prompt? Enable appendMetadata to automatically add headers to every chunk:

const result = Chunker.split(text, {
  appendMetadata: true 
});

// Chunk 1 will start with: "[Part 1/5]"
// Chunk 2 will start with: "[Part 2/5]"
// ... etc

⚙️ API Configuration

| Option | Type | Default | Description | | :--- | :--- | :--- | :--- | | maxSize | number | 2000 | Max characters per chunk. | | overlap | number | 0 | Characters to repeat from previous chunk for context. | | strategy | string | 'intelligent' | intelligent (sentence), hard (fixed), or delimiter. | | delimiter| string | \n\n | Custom string to split by (only for delimiter strategy). | | appendMetadata | boolean | false | Automatically prepend "[Part X/Y]" to chunks. | | tokenEstimator | fn | undefined | Custom function to calculate token counts. |


🏗️ Advanced Integration

Token Estimation

You can integrate any tokenizer like gpt-tokenizer or tiktoken:

import { encode } from 'gpt-tokenizer';

const result = Chunker.split(text, {
  tokenEstimator: (t) => encode(t).length
});

console.log(result.chunks[0].tokensEstimate);

📈 Performance & Bundle Size

  • Core Library: ~1.2 KB (Minified + Gzipped)
  • React Hook: ~0.8 KB (Minified + Gzipped)
  • Dependencies: 0 total dependencies.

📄 License

MIT © aswintt