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 🙏

© 2025 – Pkg Stats / Ryan Hefner

bibex-json-toolbox

v1.2.3

Published

A JavaScript toolbox for parsing BibTeX and formatting citations/bibliographies (APA, Harvard, etc.) in text, Markdown, or HTML.

Readme

About

This project provides JavaScript classes for parsing BibTeX data and formatting citations and bibliographies. The core logic includes:

  • TinyBibReader: Parses BibTeX strings and extracts citation keys and bibliographic data.
  • TinyBibFormatter: Formats in-text citations and bibliographies in various styles (e.g., APA) and output formats (plain text, Markdown, HTML).

The library is suitable for integrating citation and bibliography features into web applications or other JavaScript projects.


Installation

You can install this package from npm:

npm install bibex-json-toolbox

Usage Examples

1. Parsing BibTeX Data

// Import the classes from the npm package
import { TinyBibReader, TinyBibFormatter } from 'bibex-json-toolbox';

// Example BibTeX string
const bibtex = `
@article{smith2020,
  author = {John Smith and Jane Doe},
  title = {A Study on Something},
  year = {2020},
  journal = {Journal of Examples}
}
@book{doe2021,
  author = {Jane Doe},
  title = {Book Title},
  year = {2021},
  publisher = {Fictional Press}
}
`;

// Parse BibTeX entries
const reader = new TinyBibReader(bibtex);
console.log(reader.citeKeys); // ['smith2020', 'doe2021']
console.log(reader.bibliography['smith2020'].author); // "John Smith and Jane Doe"

2. Formatting In-Text Citations

// Format a single in-text citation (APA style, plain text)
const formatter = new TinyBibFormatter(reader.bibliography, { style: 'apa', format: 'text' });
const citation = formatter.codeToCitation('[@smith2020]');
console.log(citation); // (Smith & Doe, 2020)

3. Formatting Multiple Citations

// Multiple citations in one in-text citation
const multiCitation = formatter.codeToCitation('[@smith2020; @doe2021]');
console.log(multiCitation); // (Smith & Doe, 2020; Doe, 2021)

4. Generating a Bibliography

// Generate a bibliography in APA style (plain text output)
const ref1 = formatter.getFullReference('smith2020');
const ref2 = formatter.getFullReference('doe2021');
console.log(ref1);
// Smith, J., & Doe, J. (2020). A Study on Something. Journal of Examples.
console.log(ref2);
// Doe, J. (2021). Book Title. Fictional Press.

5. Comprehensive Example

Suppose you have a text want to insert citations and generate a bibliography in different formats.

import { TinyBibReader, TinyBibFormatter } from 'bibex-json-toolbox';

// Example a text with citation codes
const scholarlyText = `
The importance of recent findings cannot be overstated [see @smith2020, p. 12]. According to @doe2021, the field has advanced rapidly.

Further research is needed, as highlighted by [e.g. @smith2020; @doe2021]. Some authors -@smith2020[pp. 15-16] argue for a different approach.
`;

const bibtex = `
@article{smith2020,
  author = {John Smith and Jane Doe},
  title = {A Study on Something},
  year = {2020},
  journal = {Journal of Examples}
}
@book{doe2021,
  author = {Jane Doe},
  title = {Book Title},
  year = {2021},
  publisher = {Fictional Press}
}
`;

const reader = new TinyBibReader(bibtex);
const bibliography = reader.bibliography;

// Prepare formatter for plain text output.
// You may also use: { format: 'markdown' } or { format: 'html' } for other output styles.
const formatter = new TinyBibFormatter(bibliography, { style: 'apa', format: 'text' });

// Plain text
console.log('--- Plain Text ---');
console.log(formatter.transformInTextCitations(scholarlyText));
console.log('\nReferences:');
for (const key of reader.citeKeys) {
  console.log('-' + formatter.getFullReference(key));
}

Output will look like:

--- Plain Text ---
The importance of recent findings cannot be overstated (Smith & Doe, 2020, p. 12). According to Doe (2021), the field has advanced rapidly.

Further research is needed, as highlighted by (Smith & Doe, 2020; Doe, 2021). Some authors Smith & Doe (2020, pp. 15-16) argue for a different approach.

References:
- Smith, J., & Doe, J. (2020). A Study on Something. Journal of Examples.
- Doe, J. (2021). Book Title. Fictional Press.

Markdown and HTML outputs will have citations and references formatted accordingly (with italics or links).


Supported Citation Tag Styles

You can use the following styles of reference @tags in your text (see main.test.js for examples):

  • @citekey
    Narrative citation, e.g. @smith2020 will be transformed to Smith et al. (2020)

  • [@citekey]
    Parenthetical citation, e.g. [@smith2020] will be transformed to (Smith et al., 2020)

  • [@citekey; @otherkey]
    Multiple parenthetical citations, e.g. [@smith2020; @doe2021] will be transformed to (Smith et al., 2020; Doe, 2021)

  • @citekey[suffix]
    Narrative citation with suffix, e.g. @smith2020[p. 12] will be transformed to Smith et al. (2020, p. 12)

  • [@citekey; @otherkey[suffix]]
    Multiple citations, each with optional suffix, e.g. [@smith2020; @doe2021[p. 12]] will be transformed to (Smith et al., 2020; Doe, 2021, p. 12)

  • [prefix @citekey, suffix]
    Parenthetical citation with prefix and suffix, e.g. [e.g. @smith2020, p. 12] will be transformed to (e.g. Smith et al., 2020, p. 12)

  • [-@citekey]
    Parenthetical, year only, e.g. [-@smith2020] will be transformed to (2020)

  • [prefix -@citekey, suffix]
    Parenthetical, year only, with prefix/suffix, e.g. [e.g. -@smith2020, p. 12] will be transformed to (e.g. 2020, p. 12)

  • @citekey [suffix]
    Narrative citation with suffix in brackets, e.g. @smith2020 [p. 12] will be transformed to Smith et al. (2020, p. 12)


Author: Dominik M. Ramík