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

@bibtex/stringify

v0.3.0

Published

A lightweight, fast, and robust utility to stringify JavaScript objects into BibTeX format.

Readme

@bibtex/stringify

A lightweight, fast, and robust utility to stringify JavaScript objects into BibTeX format.

Installation

npm install @bibtex/stringify

(You can also use yarn, pnpm, or bun)

API Overview

The core export is the stringify function, which converts an array of strongly-typed objects into a raw BibTeX string.

Function Signature

function stringify(entries: BibTeXEntry[], options?: StringifyOptions): string;

Type Definitions

BibTeXEntry Represents a single bibliographic record.

  • type (string): The publication type (e.g., "article", "book").
  • key (string): The unique citation identifier.
  • fields (Record<string, string | number | string[]>): Key-value pairs of bibliographic data.

StringifyOptions Controls parsing behavior and error handling.

  • mode ("clean" | "markup"):

  • "clean" (Default): Auto-escapes TeX characters and protects casing by wrapping capitalized words in braces.

  • "markup": Assumes existing valid TeX markup. Skips escaping and verifies brace structural balance.

  • onError ("throw" | "omit" | "recover"):

  • "throw" (Default): Throws a MalformedBibTeXError on structural issues.

  • "omit": Silently drops malformed fields or entries.

  • "recover": Attempts to auto-repair unbalanced braces.

Basic Usage

Supply an array of BibTeXEntry objects to generate standard output using default settings (mode: "clean", onError: "throw").

import { stringify, type BibTeXEntry } from '@bibtex/stringify';

const entries: BibTeXEntry[] = [
  {
    type: "article",
    key: "knuth1984",
    fields: {
      author: ["Donald E. Knuth", "Oren Patashnik"], // Arrays join with " and "
      title: "Literate Programming", // "Programming" will be brace-protected
      year: 1984,
      journal: "The Computer Journal",
      pages: "97-111" // Hyphens convert to en-dashes (--)
    }
  }
];

const bibtexString = stringify(entries);
console.log(bibtexString);

Advanced Configuration

Pass the options object to override default behavior. This is useful when working with pre-formatted TeX strings or handling dirty datasets.

import { stringify, type StringifyOptions } from '@bibtex/stringify';

const options: StringifyOptions = {
  mode: "markup", 
  onError: "recover"
};

const dirtyEntries = [
  {
    type: "misc",
    key: "paper2026",
    fields: {
      // unescaped `\` and math-mode delimiters are preserved in "markup" mode
      title: "Proof of $E=mc^2$ and \\textbf{other} formulas", 
      // missing closing brace will be repaired by onError: "recover"
      note: "Unbalanced {brace structure" 
    }
  }
];

const safeOutput = stringify(dirtyEntries, options);

Features

  • Dual-Mode Processing: clean mode for raw data auto-escaping, and markup mode for preserving TeX macros.
  • Structural Integrity: Actively validates brace balancing and macro structures using fuzzer-hardened invariants.
  • Smart Escaping: Automatically escapes special BibTeX characters (&, %, $, #, _) in clean mode while preserving math mode blocks.
  • Casing Protection: In clean mode, words containing uppercase letters are safely wrapped in braces to prevent parsers from downcasing them.
  • Verbatim Fields: Leaves verbatim fields (like url, doi, eprint, file) unescaped so links do not break.
  • Zero Dependencies: A standalone utility with robust fuzzy testing against leading parsers.