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

defuss-frontmatter

v0.1.0

Published

Frontmatter parsing and serialization.

Readme

defuss-frontmatter

A zero-dependency, isomorphic frontmatter parser, writer, and validator.

Overview

defuss-frontmatter parses simple key: value frontmatter blocks delimited by ---, serializes objects back to frontmatter text, and validates frontmatter against a schema.

Designed for Markdown, MDX, and any text format that uses YAML-style frontmatter — without pulling in a full YAML parser.

Features

  • 📦 Zero dependencies — Pure TypeScript, no runtime imports
  • 🌐 Isomorphic — Works in browsers, Node.js, and Bun
  • ✍️ Parser — Extract frontmatter from text into { meta, body }
  • 📝 Writer — Serialize objects to frontmatter text
  • Validator — Check required fields and value types
  • 🧪 100% test coverage — 41 tests across 3 test files

Installation

bun add defuss-frontmatter

API Reference

parse(text: string): ParseResult

Extracts frontmatter from the beginning of a text string.

import { parse } from "defuss-frontmatter";

const input = `---
title: My Page
date: 2025-09-06
---

Body content here.`;

const { meta, body } = parse(input);
// meta = { title: "My Page", date: "2025-09-06" }
// body = "Body content here."

If no frontmatter is found, returns { meta: {}, body: text }.

ParseResult type:

interface ParseResult {
  meta: Record<string, string>;
  body: string;
}

write(meta: Record<string, string>): string

Serializes a plain object to frontmatter text.

import { write } from "defuss-frontmatter";

const meta = { title: "My Page", date: "2025-09-06" };
const result = write(meta);
// "---\ntitle: My Page\ndate: 2025-09-06\n---\n"

Values containing colons, newlines, or quotes are automatically double-quoted.

validate(meta, schema): ValidationResult

Validates parsed frontmatter against a schema.

import { validate } from "defuss-frontmatter";

const meta = { title: "My Page", date: "2025-09-06" };
const schema = {
  title: { required: true },
  date: { required: true, type: "date" },
  status: { required: false, default: "draft" },
};

const result = validate(meta, schema);
// result.valid = true
// result.data = { title: "My Page", date: "2025-09-06", status: "draft" }

ValidationSchema type:

interface ValidationSchema {
  [field: string]: {
    required?: boolean;
    type?: "string" | "number" | "boolean" | "date";
    default?: string;
  };
}

ValidationResult type:

interface ValidationResult {
  valid: boolean;
  errors: string[];
  data: Record<string, string>;
}

Supported types: "string", "number", "boolean", "date".

Frontmatter Format

Frontmatter uses --- delimiters with simple key: value pairs:

---
title: My Page
date: 2025-09-06
author: "Jane Doe"
---

Body content starts here.
  • Values are trimmed automatically
  • Quoted values (single or double) have quotes stripped during parsing
  • Keys with no value (no colon) parse as empty strings
  • Frontmatter must start at line 1

License

MIT — see LICENSE for details.

Part of the defuss ecosystem.