simple-cite
v0.2.1
Published
A simple package for generating citations and bibliographies
Downloads
153
Maintainers
Readme
Install
Download the package from NPM using npm
:
npm install --save simple-cite style-apa locale-en-us
or yarn
:
yarn add simple-cite style-apa locale-en-us
Simple Usage
Import the citation processor from the package, configure it with a CSL style and locale, a list of citeable items and optionally a format ('html', 'text' or 'rst'):
import Processor from 'simple-cite'
// citation formatting configuration
import style from 'style-apa'
// localization configuration
import locale from 'locale-en-US'
// a list of citable items with relevant metadata
import items from './references'
const processor = new Processor({
items,
style,
locale
})
Making Citations
Citation
objects may be made using the cite
method of the Processor
, providing a citation datastructure as argument:
const citation = processor.cite({ citationItems: [{ id: 'hawking1988' }] })
Citation
objects maintain the value of a citation registered with the processor within their value
property:
citation.value
// (Hawking, 1988)
This allows disambiguations to future citations and more to be made. For example, if we cite Lucy Hawking within the same context, we ought to disambiguate the authors according to the APA style. This would be tracked by the processor:
const lucyCitation = processor.cite({ citationItems: [{ id: 'hawking2000' }] })
lucyCitation.value
// (Lucy Hawking, 2000)
citation.value
// (Stephen Hawking, 1988)
As such, it is important to remember that citation values may change while citations are being registered.
Making Bibliographies
A Bibliography
object may be made using the bibliography
method:
const bibliography = processor.bibliography()
Like with Citation
, this maintains the value of long form references for items previously cited by the processor with a value
property:
bibliography.value
// Hawking, S. W. (1988). A brief history of time: from the big bang to black holes. Toronto: Bantam Books
Again, the value will update as citations are registered with the Processor
.
In depth Usage
In addition to simple citations, in-narrative citations by adding an "in-narrative"
property to the citation:
const citation = processor.cite({
citationItems: [{ id: 'hawking1988' }],
properties: { 'in-narrative': true }
})
citation.value
// Hawking (1988)
Items to be included in bibliographies without explicit citation (no-cites) may be registered with the noCite
method, which takes an array of item ids as argument:
processor.noCite(['hawking1988'])
Citation data structures
Citation data is described according to the CSL-JSON schema.
Items
A single bibliographic work or resource, such as an article, book or book chapter.
An item is represented as an object, with a required id
field (analogous to the BibTeX cite-key) and type
field (analogous to the BibTeX entry type).
Further metadata, such as authors, date of issue etc. may be included with appropriate fields.
An example would be:
[
{
"id": "hawking1988",
"type": "book",
"title": "A brief history of time: from the big bang to black holes",
"publisher": "Bantam Books",
"number-of-pages": "198",
"event-place": "Toronto",
"ISBN": "978-0-553-05340-1",
"shortTitle": "A brief history of time",
"author": [
{
"family": "Hawking",
"given": "Stephen W."
}
],
"issued": {
"date-parts": [["1988"]]
}
}
]
These data are most easily generated using a compatible citation manager, such as Zotero.
Cite-Items
A cite-item corresponds to a single in-document reference to an item via matching id property, with optional locator
and label
, prefix
and suffix
annotations, and the option to not include reference to the author ("suppress-author"
) or include only the author ("author-only"
).
For example,
{
"id": "hawking1988",
"label": "page",
"locator": "140",
"prefix": "see",
"suffix": "for the most expensive equation in history"
}
Citations
A citation corresponds to a collection of cite-items referenced at a single point within a document, with a properties object providing metadata about the citation within the text, for example the index of the footnote in which it is located (if using a "note"-based citation style).
For example,
{
"citationItems": [
{
"id": "hawking1988",
"label": "chapter",
"locator": "3"
}
],
"properties": {
"noteIndex": 2
}
}
Citation Styles
The CSL style may be specified using either the XML-based Citation Style Language, or a derived JSON representation.
These may be found for a great many journals in the official CSL style repository, or obtained as a JavaScript package hosted on NPM under the scope style-*
.
Citation Locales
The CSL locale may be specified in the same way, and obtained from the official CSL locale repository, or obtained from NPM under the scope locale-*
.