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 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-cite

v0.2.1

Published

A simple package for generating citations and bibliographies

Downloads

153

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-*.