How to use @citation-js/core - 10 common examples

To help you get started, we’ve selected a few @citation-js/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wikicite / wcite / lib / util / cite.js View on Github external
get: (ids, options = {}) => {
    require('@citation-js/plugin-wikidata')
    const languages = options.languages || []
    if (languages[0]) {
      plugins.config.get('@wikidata').langs = languages
    }
    return (Cite(ids) || { get: () => [] }).get().map(tidyCsl)
  },
github wikicite / wcite / lib / util / cite.js View on Github external
format: (items, format, options = {}) => {
    if (format === 'ndjson') {
      return items.map(item => JSON.stringify(item)).join('\n')
    } else if (format === 'json') {
      return JSON.stringify(items, null, 2)
    }

    const cite = new Cite(items)

    if (format === 'bibtex' || format === 'bibtxt') {
      require('@citation-js/plugin-bibtex')
    } else {
      require('@citation-js/plugin-csl')

      options.format = format
      if (format === 'text') {
        options.prepend = item => `${item.id}: `
      } else if (format !== 'html') {
        throw new Error(`unknown citation format ${format}`)
      }

      format = 'bibliography'
    }
github larsgw / citation.js / index.js View on Github external
function Cite (data, opts) {
  if (!(this instanceof Cite)) {
    return new Cite(data, opts)
  }

  var self = new core.Cite(data, opts)
  this._options = self._options
  this.log = self.log
  this.data = self.data
}
github larsgw / citation.js / index.js View on Github external
}

  var self = new core.Cite(data, opts)
  this._options = self._options
  this.log = self.log
  this.data = self.data
}

Cite.prototype = Object.create(core.Cite.prototype)

Cite.async = core.Cite.async
Cite.validateOptions = core.Cite.validateOptions
Cite.validateOutputOptions = core.Cite.validateOutputOptions

Cite.input = core.plugins.input.chain
Cite.inputAsync = core.plugins.input.chainAsync

Cite.util = Object.assign({ attr }, core.util)
Cite.version = {
  cite: core.version,
  citeproc: citeproc.PROCESSOR_VERSION
}

const CSL = core.plugins.config.get('@csl')

Cite.CSL = {
  engine: require('@citation-js/plugin-csl/lib/engines').fetchEngine,
  item (data) {
    return id => data.find(entry => entry.id === id)
  },
  locale (lang) {
    return CSL.styles.get(CSL.styles.has(lang) ? lang : 'en-US')
github larsgw / citation.js / index.js View on Github external
return new Cite(data, opts)
  }

  var self = new core.Cite(data, opts)
  this._options = self._options
  this.log = self.log
  this.data = self.data
}

Cite.prototype = Object.create(core.Cite.prototype)

Cite.async = core.Cite.async
Cite.validateOptions = core.Cite.validateOptions
Cite.validateOutputOptions = core.Cite.validateOutputOptions

Cite.input = core.plugins.input.chain
Cite.inputAsync = core.plugins.input.chainAsync

Cite.util = Object.assign({ attr }, core.util)
Cite.version = {
  cite: core.version,
  citeproc: citeproc.PROCESSOR_VERSION
}

const CSL = core.plugins.config.get('@csl')

Cite.CSL = {
  engine: require('@citation-js/plugin-csl/lib/engines').fetchEngine,
  item (data) {
    return id => data.find(entry => entry.id === id)
  },
  locale (lang) {
github larsgw / citation.js / index.js View on Github external
register: {
    addTemplate: CSL.templates.add.bind(CSL.templates),
    getTemplate: CSL.templates.get.bind(CSL.templates),
    hasTemplate: CSL.templates.has.bind(CSL.templates),
    addLocale: CSL.locales.add.bind(CSL.locales),
    getLocale: CSL.locales.get.bind(CSL.locales),
    hasLocale: CSL.locales.has.bind(CSL.locales)
  }
}

Cite.plugins = clone(core.plugins)
delete Cite.plugins.input.util.clean

Cite.parse = Object.assign({
  input: {
    chain: core.plugins.input.chain,
    chainAsync: core.plugins.input.chainAsync,
    chainLink: core.plugins.input.chainLink,
    chainLinkAsync: core.plugins.input.chainLinkAsync,
    data: core.plugins.input.data,
    dataAsync: core.plugins.input.dataAsync,
    type: core.plugins.input.type,
    async: {
      chain: core.plugins.input.chainAsync,
      chainLink: core.plugins.input.chainLinkAsync,
      data: core.plugins.input.dataAsync
    }
  },
  name: name.parse,
  date: date.parse,
  csl: core.plugins.input.util.clean,
github larsgw / citation.js / index.js View on Github external
}, Cite.plugins.input)

Cite.get = Object.assign({
  dict: Cite.plugins.dict,

  name: name.format,
  date: date.format,

  bibtex: {
    json: require('@citation-js/plugin-bibtex/lib/output/json').default,
    label: require('@citation-js/plugin-bibtex/lib/output/label').default,
    text: require('@citation-js/plugin-bibtex/lib/output/text').default,
    type: require('@citation-js/plugin-bibtex/lib/output/type').default
  },
  bibtxt: require('@citation-js/plugin-bibtex/lib/output/bibtxt').default,
  json: require('@citation-js/core/lib/plugin-common/output').default.data,
  label: require('@citation-js/core/lib/plugin-common/output').default.label
}, Cite.plugins.output)

module.exports = Cite
github larsgw / citation.js / index.js View on Github external
Cite.get = Object.assign({
  dict: Cite.plugins.dict,

  name: name.format,
  date: date.format,

  bibtex: {
    json: require('@citation-js/plugin-bibtex/lib/output/json').default,
    label: require('@citation-js/plugin-bibtex/lib/output/label').default,
    text: require('@citation-js/plugin-bibtex/lib/output/text').default,
    type: require('@citation-js/plugin-bibtex/lib/output/type').default
  },
  bibtxt: require('@citation-js/plugin-bibtex/lib/output/bibtxt').default,
  json: require('@citation-js/core/lib/plugin-common/output').default.data,
  label: require('@citation-js/core/lib/plugin-common/output').default.label
}, Cite.plugins.output)

module.exports = Cite
github wikicite / wcite / lib / util / cite.js View on Github external
get: (ids, options = {}) => {
    require('@citation-js/plugin-wikidata')
    const languages = options.languages || []
    if (languages[0]) {
      plugins.config.get('@wikidata').langs = languages
    }
    return (Cite(ids) || { get: () => [] }).get().map(tidyCsl)
  },
github larsgw / citation.js / index.js View on Github external
var self = new core.Cite(data, opts)
  this._options = self._options
  this.log = self.log
  this.data = self.data
}

Cite.prototype = Object.create(core.Cite.prototype)

Cite.async = core.Cite.async
Cite.validateOptions = core.Cite.validateOptions
Cite.validateOutputOptions = core.Cite.validateOutputOptions

Cite.input = core.plugins.input.chain
Cite.inputAsync = core.plugins.input.chainAsync

Cite.util = Object.assign({ attr }, core.util)
Cite.version = {
  cite: core.version,
  citeproc: citeproc.PROCESSOR_VERSION
}

const CSL = core.plugins.config.get('@csl')

Cite.CSL = {
  engine: require('@citation-js/plugin-csl/lib/engines').fetchEngine,
  item (data) {
    return id => data.find(entry => entry.id === id)
  },
  locale (lang) {
    return CSL.styles.get(CSL.styles.has(lang) ? lang : 'en-US')
  },
  style (style) {