node package manager
Love JavaScript? Your insights can make it even better. Take the 2017 JavaScript Ecosystem Survey »

citation-js

Citation.js

Citation.js converts formats like BibTeX, Wikidata JSON and ContentMine JSON to CSL-JSON to convert to other formats like APA, Vancouver and back to BibTeX.

NPM version NPM total downloads Build Status Dependency Status codecov license DOI

JavaScript Style Guide JS.ORG


Install

On Node.js, install the package (citation-js) like this:

npm install citation-js

To install the CLI as a global command, do this:

npm install --global citation-js

Browser releases are available here. These define require and add citation-js as a module.

<script src="path/to/citation.js" type="text/javascript"></script>
<script>
  const Cite = require('citation-js')
</script> 

Getting Started

You can read a guide on how to get started, together with some tutorials and examples, here.

CLI

More info

Run the CLI like this:

citation-js  [options]

Options:

  -h, --help                      output usage information
  -V, --version                   output the version number
  
  -i, --input <path>              Input file
  -u, --url <url>                 Input url
  -t, --text <string>             Input text
  
  -o, --output <path>             Output file (omit file extension)
  
  -R, --output-non-real           Do not output the file in its mime type, but as a string
  -f, --output-type <option>      Output structure type: string, html, json
  -s, --output-style <option>     Output scheme. A combination of --output-format json and --output-style citation-* is considered invalid. Options: csl (Citation Style Lanugage JSON), bibtex, citation-* (where * is any formatting style)
  -l, --output-language <option>  Output language. [RFC 5646](https://tools.ietf.org/html/rfc5646) codes

Cite

More info

To use the Cite constructor, require() the module like this:

const Cite = require('citation-js')

For example, to get the bibliographical data of the Wikidata item wd:Q21972834, and then format it in HTML, English and APA:

const data = new Cite('Q21972834')
 
const output = data.get({
  format: 'string',
  type: 'html',
  style: 'citation-apa',
  lang: 'en-US'
})
 
console.log(output)

To test this code, go to RunKit.

Async

Use the async API (recommended for Wikidata, URL, and DOI input) like this:

const data = await Cite.async('Q21972834')
 
const output = data.get({
  format: 'string',
  type: 'html',
  style: 'citation-apa',
  lang: 'en-US'
})
 
console.log(output)

Cite.async() also supports a callback function as the second or third argument

More

More Docs

Further explanation can be found here.

Demo

NPM Demo

NPM Demo. Example code:

var Cite = require('citation-js')
 
var data = new Cite('Q21972834')
 
data.get({
  format: 'string',
  type: 'html',
  style: 'citation-apa',
  lang: 'en-US'
})
 
// Should implicitly display

Browser Demos