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

@gemini-tools/gemtext

v0.0.4

Published

Parser for the Gemtext markup format used in the Gemini protocol

Readme

gemtext

A simple parser for the Gemtext markup based on the Gemini spec.

Usage

Parsing

import {
    GemtextLineType,
    GemtextLine,
    parseGemtext,
    serializeGemtext,
} from '@gemini-tools/gemtext';

declare const content: string;

const lines: Array<GemtextLine> = parseGemtext(content);

for (const line in lines) {
  if (line.type === GemTextLineType.TEXT) {
    // line -> { type: GemtextLineType.TEXT; text: string }
  }

  if (line.type === GemTextLineType.LINK) {
    // line -> { type: GemtextLineType.LINK; url: string; text: string | null }
  }

  if (line.type === GemTextLineType.PRE) {
    // line -> { type: GemtextLineType.PRE; alt: string; lines: Array<string> }
  }

  if (line.type === GemTextLineType.HEADER) {
    // line -> { type: GemtextLineType.HEADER; level: number; text: string | null }
  }

  if (line.type === GemTextLineType.LIST_ITEM) {
    // line -> { type: GemtextLineType.LIST_ITEM; text: string }
  }

  if (line.type === GemTextLineType.QUOTE) {
    // line -> { type: GemtextLineType.QUOTE; text: string }
  }
}

Serialization

Convert parsed AST back to gemtext format:

// Parse gemtext
const lines = parseGemtext(gemtextString);

// Modify the AST as needed
lines.push({
  type: GemtextLineType.LINK,
  url: 'https://example.com',
  text: 'New link',
});

// Serialize back to gemtext
const output = serializeGemtext(lines);
console.log(output);

Round-Trip Parsing

Parsing and serializing preserves semantic content:

const original = parseGemtext(input);
const serialized = serializeGemtext(original);
const roundTrip = parseGemtext(serialized);

// original and roundTrip are structurally identical

Streaming Support

For large files or streaming sources, use the generator functions:

Sync Generators

import {
  parseGemtextLines,
  serializeGemtextLines,
} from '@gemini-tools/gemtext';

// Parse line-by-line from an array
const lines = ['# Header', 'Text', '=> https://example.com Link'];
for (const parsed of parseGemtextLines(lines)) {
  console.log(parsed.type, parsed);
}

// Serialize incrementally
const ast = [
  { type: GemtextLineType.HEADER, level: 1, text: 'Title' },
  { type: GemtextLineType.TEXT, text: 'Content' },
];
for (const line of serializeGemtextLines(ast)) {
  console.log(line); // Outputs gemtext strings one at a time
}

Async Generators

import {
  streamParseGemtext,
  streamSerializeGemtext,
} from '@gemini-tools/gemtext';
import * as fs from 'fs';
import * as readline from 'readline';

// Parse from file stream
const fileStream = fs.createReadStream('document.gmi', { encoding: 'utf-8' });
const rl = readline.createInterface({ input: fileStream, crlfDelay: Infinity });

for await (const parsed of streamParseGemtext(rl)) {
  console.log('Streamed:', parsed);
}

// Full async pipeline: read file -> parse -> serialize
const input = fs.createReadStream('input.gmi', { encoding: 'utf-8' });
const lines = readline.createInterface({ input, crlfDelay: Infinity });

for await (const line of streamSerializeGemtext(streamParseGemtext(lines))) {
  process.stdout.write(line + '\n');
}