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

@batchfy/bib-parser

v1.0.1

Published

A fully-typed TypeScript BibTeX parser and serializer, ported from ORCID/bibtexParseJs

Readme

@batchfy/bib-parser

A small, fully-typed TypeScript BibTeX parser, serializer, and @string macro expander. It is a modern port of ORCID/bibtexParseJs (original work by Henrik Muehe, 2010) with a strict type layer, a robust hand-written scanner, and a thorough test suite.

  • Zero runtime dependencies.
  • Fully typed — strict TypeScript with noUncheckedIndexedAccess, exactOptionalPropertyTypes, and friends.
  • Parse BibTeX → typed JSON, serialize JSON → BibTeX (compact or pretty).
  • A separate @string expander supporting every common definition syntax.

Installation

npm install @batchfy/bib-parser

Or, to build from source:

npm install
npm run build   # emits ./dist (JS + .d.ts)

Requires Node.js 24+ (the toolchain and test suite run TypeScript sources natively via type stripping).

Quick start

import { parse, toBibtex } from "@batchfy/bib-parser";

const entries = parse("@article{muehe2010, title = {A Parser}, year = 2010}");
// [{ entryType: "article", citationKey: "muehe2010",
//    entryTags: { title: "A Parser", year: "2010" } }]

toBibtex(entries); // '@article{muehe2010,title={A Parser},year={2010}}\n'

API

parse(bibtex, options?) => BibtexEntry[]

Parses BibTeX source into a list of typed entries. Also exported as toJSON for compatibility with the original library.

interface BibtexParserOptions {
  /** Synthesise a citation key from author + year when one is missing. Default: true. */
  deriveMissingCitationKey?: boolean;
}

The parser is deliberately tolerant: unknown bare identifiers (e.g. an unresolved @string reference like publisher = acm) are kept verbatim rather than throwing. Genuinely malformed input (unterminated values, a missing =, runaway keys) throws a BibtexParseError carrying the failing position.

toBibtex(entries, options?) => string

Serializes entries back to BibTeX. { compact: true } (default) is terse; { compact: false } is indented and multi-line.

expandStrings(bibtex, options?) => string

Separate, text-in / text-out function that substitutes every @string macro reference and returns the rewritten BibTeX with the definitions removed (by default). Entry skeletons — types, delimiters, citation keys, field names, and layout — are preserved; only field values are rewritten.

Every common @string syntax is supported:

@string{ pub = "ACM Press" }          % quoted value, brace delimiters
@string( pub = {ACM Press} )          % braced value, PAREN delimiters
@STRING{ y2020 = 2020 }               % numeric value, any @string casing
@string{ a = "A" # " and " # b }      % # concatenation + nested reference
@string{ x = "X", y = "Y" }           % multiple assignments per block
interface ExpandStringsOptions {
  /** Remove @string blocks from the output. Default: true. */
  removeDefinitions?: boolean;
  /** Extra predefined macros (matched case-insensitively). */
  additionalStrings?: Record<string, string>;
  /** Predefine jan..dec to full English month names. Default: false. */
  includeDefaultMonths?: boolean;
}
expandStrings('@string{acm = "ACM Press"}\n@article{k, publisher = acm}');
// '@article{k, publisher = {ACM Press}}\n'   (definition removed)

Definitions may reference each other in any order (resolved transitively; cycles are handled gracefully). Text inside braced/quoted literals that merely looks like a macro is never touched.

getStringDefinitions(bibtex, options?) => Record<string, string>

Returns a map from (lower-cased) macro name to its fully-resolved value.

Types & guards

BibtexEntry is a discriminated union of RegularEntry, StringEntry, PreambleEntry, and CommentEntry. Narrow with the exported guards isRegularEntry, isStringEntry, isPreambleEntry, isCommentEntry.

Project layout

src/
  index.ts        # public API surface
  parser.ts       # recursive-descent BibTeX parser
  serializer.ts   # entries -> BibTeX (toBibtex)
  strings.ts      # standalone @string expander
  errors.ts       # BibtexParseError
  types.ts        # shared types + type guards
test/
  library.test.ts     # single consolidated suite driven by one fixture
  errors.test.ts      # malformed-input error handling
  fixtures/
    library.bib       # one comprehensive fixture exercising the whole grammar

Scripts

| Command | Description | | -------------------- | -------------------------------------------- | | npm test | Run the test suite (Node's built-in runner). | | npm run typecheck | Type-check without emitting. | | npm run build | Emit JS + declarations to ./dist. |

License

MIT