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

@steinnes/snippets

v0.1.2

Published

In-memory snippet store with an LLM-friendly editing API for Office.js and similar generated-code workflows.

Readme

@steinnes/snippets

An in-memory store for named text snippets, with an editing API shaped for use by LLMs and tooling. Snippets are created, retrieved, and mutated by name or id; edits specify oldText / newText pairs and apply with forward-cursor, fuzzy-matched semantics. Also supports single-snippet patches for multi-chunk updates.

This package is Node ESM, no runtime dependencies, and has no persistence — all state lives in the SnippetStore instance.

Install

npm install @steinnes/snippets

Usage

import { SnippetStore } from '@steinnes/snippets';

const store = new SnippetStore();

// Create
const snippet = store.create({ name: 'greeting', content: 'hello world\n' });

// Edit (oldText → newText, with a forward cursor across multiple edits)
const edited = store.edit(snippet.id, [
  { oldText: 'world', newText: 'universe' },
]);
console.log(edited.content); // 'hello universe\n'

// Patch (single-snippet, one or more @@ chunks)
const patchText = [
  '*** Begin Patch',
  '*** Update File: greeting',
  '@@',
  '-universe',
  '+everyone',
  '*** End Patch',
  '',
].join('\n');
const patched = store.patch(snippet.id, patchText);
console.log(patched.content); // 'hello everyone\n'

// List all snippets
const all = store.list();

// Rename
const renamed = store.rename(snippet.id, 'new-name');

// Replace all content
const fresh = store.replace(snippet.id, 'brand new content');

// Delete
store.delete(snippet.id);

Errors

All errors extend Error and carry typed context fields:

  • SnippetNotFoundError — the given snippet id is not in the store. Fields: snippetId.
  • SnippetNameConflictError — creating or renaming to a name that is already taken. Fields: conflictName.
  • OldTextNotFoundErroroldText was not found in the snippet during an edit. Fields: snippetId, oldText, editIndex (for batch edits, the 0-based index of the failing edit).
  • PatchParseError — the patch text is malformed (missing sentinels, multi-file patches, or structurally invalid chunks).
  • PatchApplyError — a chunk's oldText could not be matched against the snippet during patch application. Fields: snippetId, chunkIndex, detail (the raw mismatch message).
  • PatchTargetMismatchError — the patch's *** Update File: header names a snippet that does not match the target id. Fields: snippetId, snippetName, patchTargetName.

Fuzzy matching

Text matching for edit and patch runs a four-tier cascade until the first tier matches (or all fail):

  1. Exact — literal substring match.
  2. Rstrip — line-wise, trailing whitespace ignored on both sides.
  3. Trim — line-wise, leading+trailing whitespace ignored on both sides.
  4. NFC — line-wise, Unicode-normalized (e.g. é as \u00e9 matches e\u0301).

Returned offsets always point at the original (un-normalized) content, so replacement is lossless. Pass { fuzzy: false } to edit / patch (or set fuzzy: false on the SnippetStore constructor options) to restrict matching to tier 1 only.

Patch format

The patch format is a simple single-snippet text-patching format:

*** Begin Patch
*** Update File: <snippet-name>   (optional; triggers strict name validation)
@@
- line to remove
+ line to add
  context line (unchanged)
@@
...more chunks...
*** End Patch

What IS supported:

  • *** Begin Patch / *** End Patch sentinels
  • Optional *** Update File: <name> header — when present, store.patch validates that <name> matches the snippet's current name and throws PatchTargetMismatchError if it does not
  • One or more @@ chunk markers
  • Lines prefixed with - (removed), + (added), or (space; context)
  • Blank lines within a chunk (represented as empty strings in both oldText and newText)
  • Fuzzy matching (optional; default on)

What is NOT supported:

  • @@ <context-string> navigation (the @@ line takes no arguments)
  • *** End of File sentinel
  • *** Add File / *** Delete File multi-file headers
  • Multi-file patches (a single patch with multiple *** Update File: headers throws PatchParseError)