doi2bib

A node.js package to retrieve citation information of any given DOI, document or string text, and update it to a specified BibText (.bib) file.

Usage no npm install needed!

<script type="module">
  import doi2bib from 'https://cdn.skypack.dev/doi2bib';
</script>

README

DOI2BIB

Status GitHub Issues GitHub Pull Requests NPM Downloads License


A node.js package to retrieve citation information of any given DOI, document or string text, and update it to a specified BibText (.bib) file.

📝 Table of Contents

🧐 About

This package parse Markdown files or text strings searching for DOI references with the format: @DOI:---.---/-----------. It keeps a *.bib file (library.bib per default) updated by adding the necessary references and information obtained from http://dx.doi.org/.

This package is used as part of the pandoc-doi2bib filter and pdf2doi utilities.

🏁 Getting Started

These instructions will get you the doi2bib package to use on your node projects.

Installing

For using as Node.js package use:

npm install --save doi2bib

And for development, clone the repository as:

git clone https://github.com/aeroreyna/doi2bib
cd doi2bib
npm install

🎈 Usage

This package exposes the following functions:

  • updateFromText(text): Looks for DOI references and updates the .bib file.
  • updateFromFile(file): Read the file and uses the function updateFromText.
  • watchFile(file): Read the file and keeps and eye on it looking for new references.
  • getCitation(DOI): Obtain and return the citation of the DOI document and added to the library if necessary.
  • setLibraryFile(file): Change the bibliography .bib file to work on.

An example could be:

const doi2bib = require("./index.js");

doi2bib.getCitation('10.1007/s10462-018-09676-2').then((r)=>{
  console.log(r)
});

Which keeps an eye on the specified file in case of new DOI references are given.

Using Gulp

It also can be used with Gulp as a task to act when .md files in a directory changes using the follow gulp file.

const { src, dest, watch, task } = require('gulp');
const through = require('through2');
const doi2bib = require('doi2bib');


let updateBib = function() {
  return src(['**/*.md','!./node_modules/**/*.md'])
    .pipe(through.obj(function (chunk, enc, cb) {
      console.log('File:', chunk.path);
      doi2bib.updateFromText(chunk.contents.toString());
      cb(null, chunk);
    }));
}

task('default', updateBib);

let watcher = watch(['**/*.md','!./node_modules/**/*.md']);

watcher.on('change', function(path, stats) {
  console.log(`File ${path} was changed`);
  doi2bib.updateBibFromFile(path);
});

watcher.on('add', function(path, stats) {
  console.log(`File ${path} was added`);
  doi2bib.updateBibFromFile(path);
});

⛏️ Built Using

✍️ Authors

See also the list of contributors who participated in this project.

To do:

  • remove nets dependency
  • make sure all functions return a Promise
  • catch errors in promises