Coder Social home page Coder Social logo

citation-js / citation-js Goto Github PK

View Code? Open in Web Editor NEW
137.0 5.0 41.0 6.38 MB

Core functionality of Citation.js, as well as the original plugins (CSL, BibTeX, RIS, DOI, Wikidata, and BibJSON)

Home Page: https://citation.js.org

License: MIT License

JavaScript 91.02% Roff 0.43% TeX 8.56%
hacktoberfest

citation-js's Introduction

Citation.js

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

Read the paper Citation.js: a format-independent, modular bibliography tool for the browser and command line. DOI 10.7717/peerj-cs.214


SiteRepoGetting StartedDocumentationDemo


NPM version NPM yearly downloads jsDelivr yearly hits Build Status License JavaScript Style Guide Join the chat at https://gitter.im/citation-js/Lobby DOI

Packages

citation-js/citation-js replaces larsgw/citation.js
This repository contains the npm package @citation-js/core and several other components. This repository contains the npm package citation-js that wraps the aforementioned components for backwards compatibility.

Core

Core functionality:

  • Cite: reference manager
  • plugins: plugins manager
  • util: several utility functions and classes
  • version

Plugins

Plugin Description
plugin-bibjson Plugin for BibJSON formats for Citation.js
plugin-bibtex Plugin for BibTeX formats for Citation.js
plugin-csl Plugin for CSL output for Citation.js
plugin-doi Plugin for DOI input for Citation.js
plugin-ris Plugin for RIS formats for Citation.js
plugin-wikidata Plugin for Wikidata for Citation.js

Plugins in other repositories

Plugin Description
plugin-software-formats Plugin for CFF, Zenodo JSON, input from GitHub and npm URLs
plugin-isbn Plugin for ISBNs (from Google Books, OpenLibrary)
plugin-orcid Plugin for ORCID profiles (metadata from DOIs and ISBNs)
plugin-pubmed Plugin for PubMed and PubMed Central identifiers
plugin-quickstatements Plugin for output to Wikidata QuickStatements
plugin-zotero-translation-server Plugin for Zotero JSON and interfacing with a Zotero translation server
plugin-refer Plugin for the refer file format
plugin-refworks Plugin for the RefWorks tagged format

CLI

CLI:

Usage: citation-js [options]

Options:
  -V, --version                   output the version number
  -i, --input <path>              Input file. If all input options are omitted, it uses stdin
  -t, --text <string>             Input text. If all input options are omitted, it uses stdin
  -u, --url <string>              Deprecated in favor of -t, --text. If all input options are omitted, it uses stdin
  -o, --output <path>             Output file (omit file extension). If this option is omitted, the output is written to stdout
  -R, --output-non-real           Output as a text file
  -f, --output-type <option>      Output structure type: string, html, json (default: "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) (default: "csl")
  -l, --output-language <option>  Output language. [RFC 5646](https://tools.ietf.org/html/rfc5646) codes (default: "en-US")
  -h, --help                      output usage information

Acknowledgements

JS.ORG

BrowserStack

  • Thanks to BrowserStack for the free Open Source plan, allowing me to automate testing browser support, and avoid issues like this one!

citation-js's People

Contributors

alexanderzeilmann avatar anadrome avatar bwiernik avatar dependabot[bot] avatar egonw avatar gabestein avatar jheer avatar joshmoore avatar larsgw avatar me2d09 avatar nichtich avatar rubenverborgh avatar soulchainer avatar symbitic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

citation-js's Issues

`parseUntil` option

Option to parse until a certain format is reached, instead of the default @csl/object+list. Currently it's not possible to parse A into B without passing through CSL-JSON if they're not a defined distance apart, and very unwieldy if it is defined but more than one.

BibTeX export: but edition into {..}

Edition numbers may not be simple numeric. I have an edition number 1.56 which is exported as edition=1.56 in BibTeX, causing an error. Export as edition={1.56} solves the issue.

Centralize CSL schema data

Centralize CSL schema data: used in plugins.input.util.clean, but should also be available in

  • Cite#sort() for sort key rendering

Remove backwards compatibility for deprecated features

Deprecations

CLI

  • -u, --url option: use -t, --text

Core

  • Cite#get(): use Cite#format()
  • Cite#validateOutputOptions(): N/A
  • @plugin-common::output::getJsonWrapper(): use Cite#format('data')
  • @plugin-common output format data with option format: 'html': N/A
  • plugins.dict.htmlDict, plugins.dict.textDict: use plugins.dict

plugin-ris

  • config.outputSpec: use the spec option of the output format ris instead

plugin-wikidata

  • @wikidata/prop and @wikidata/type input formats

BibTeX/BibLaTeX rework [CANONICAL]

jQuery input broken

jQuery input is broken because Object inputs are now cloned to avoid problems with accidental changes while parsing but the cloning doesn't account for constructors and prototypes. Probably also affects DOM input.

[lerna] Build failing

The build is failing because of an out-of-date package-lock. This is only relevant for the GitHub version.

Also, a familiar error:

$ npm install
npm WARN tar ENOENT: no such file or directory, open '/home/travis/build/citation-js/citation-js/node_modules/.staging/regexpu-core-ba91c628/package.json'
npm WARN tar ENOENT: no such file or directory, open '/home/travis/build/citation-js/citation-js/node_modules/.staging/regexpu-core-ba91c628/LICENSE-MIT.txt'
npm WARN tar ENOENT: no such file or directory, open '/home/travis/build/citation-js/citation-js/node_modules/.staging/umask-3109e5c5/package.json'
npm WARN tar ENOENT: no such file or directory, open '/home/travis/build/citation-js/citation-js/node_modules/.staging/regexpu-core-ba91c628/README.md'
npm WARN tar ENOENT: no such file or directory, open '/home/travis/build/citation-js/citation-js/node_modules/.staging/umask-3109e5c5/.npmignore'
npm WARN tar ENOENT: no such file or directory, open '/home/travis/build/citation-js/citation-js/node_modules/.staging/umask-3109e5c5/README.md'
npm WARN tar ENOENT: no such file or directory, open '/home/travis/build/citation-js/citation-js/node_modules/.staging/@babel/plugin-transform-dotall-regex-e2abb1d2/LICENSE'
npm WARN tar ENOENT: no such file or directory, open '/home/travis/build/citation-js/citation-js/node_modules/.staging/regexpu-core-ba91c628/rewrite-pattern.js'
npm WARN tar ENOENT: no such file or directory, open '/home/travis/build/citation-js/citation-js/node_modules/.staging/umask-3109e5c5/LICENSE'
npm WARN tar ENOENT: no such file or directory, open '/home/travis/build/citation-js/citation-js/node_modules/.staging/@babel/plugin-transform-dotall-regex-e2abb1d2/README.md'
npm WARN tar ENOENT: no such file or directory, open '/home/travis/build/citation-js/citation-js/node_modules/.staging/umask-3109e5c5/index.js'
npm WARN tar ENOENT: no such file or directory, open '/home/travis/build/citation-js/citation-js/node_modules/.staging/umask-3109e5c5/ChangeLog'
npm WARN tar ENOENT: no such file or directory, open '/home/travis/build/citation-js/citation-js/node_modules/.staging/fs-extra-e695f82f/LICENSE'
npm WARN tar ENOENT: no such file or directory, open '/home/travis/build/citation-js/citation-js/node_modules/.staging/umask-3109e5c5/index.js~'
npm WARN tar ENOENT: no such file or directory, open '/home/travis/build/citation-js/citation-js/node_modules/.staging/@babel/plugin-transform-unicode-regex-96c17eed/lib/index.js'
npm WARN tar ENOENT: no such file or directory, open '/home/travis/build/citation-js/citation-js/node_modules/.staging/fs-extra-e695f82f/README.md'
npm WARN tar ENOENT: no such file or directory, open '/home/travis/build/citation-js/citation-js/node_modules/.staging/node-gyp-5b0334d1/gyp/pylib/gyp/generator/ninja_test.py'
npm WARN tar ENOENT: no such file or directory, open '/home/travis/build/citation-js/citation-js/node_modules/.staging/node-gyp-5b0334d1/gyp/pylib/gyp/generator/ninja.py'

unmet peer dependency @citation-js/core@^0.4.0-rc.0

I'm trying to cherry-pick only parts of citation-js. With package.json having

{
  "dependencies": {
    "@citation-js/plugin-bibtex": "^0.4.0",
    "@citation-js/plugin-csl": "^0.4.0",
    "@citation-js/plugin-wikidata": "^0.4.0"
  }
}

calling npm install emits the warnings:

npm WARN @citation-js/[email protected] requires a peer of @citation-js/core@^0.4.0-rc.0 but none was installed.
npm WARN @citation-js/[email protected] requires a peer of @citation-js/core@^0.4.0-rc.0 but none was installed.
npm WARN @citation-js/[email protected] requires a peer of @citation-js/core@^0.4.0-rc.0 but none was installed.

BibTeX: Cannot read property 'replace' of undefined

Input: probably just { author: [{ given: 'foo' }] }

TypeError: Cannot read property 'replace' of undefined
    at safeSlug (label.js:10)
    at getBibTeXLabel (label.js:26)
    at getBibTeXJSON (json.js:24)
    at serializeEntry (text.js:66)
    at text.js:76
    at Array.map (<anonymous>)
    at getBibtex (text.js:76)
    at index.js:27
    at format (output.js:53)
    at Cite.format (get.js:29)

Centralize parsing error handling

  • remove individual parser error handling
    • Only known impactful handler is in plugin-bibtex, which returns completed entries, but that feature might be dropped entirely with a new parser anyway
  • add strict: Boolean parsing parameter to not handle the errors
  • determine default strict state (true would be a breaking change, but the better option)

See larsgw/citation.js#130
See larsgw/citation.js#173

Additional Wikidata property mappings

Add

* requires fetching additional resources

Ignore

Undecided

wikidata: respect precision of TimeValues

Dates in Wikidata are given with a precision that gets lost if values are simplified to ISO date strings and parsed again to get year, month, and date. Most books only have a year which is wrongly mapped to January the first of this year.

I first though to fix this in citation-js but after fixing citation-js/date@6328751 I think this should better be done in function simplify of wikidata-sdk. this can be done with option timeConverter of wikidata-sdk's simplify as documented here.

Global User-Agent settings

Allow users/developers to globally set the User-Agent; there is little reason for Citation.js to be responsible for requests made using it, apart from performance (#16).

Better async error handling in Wikidata

As #21, #22, #23 are all UnhandledPromiseRejectionWarning, which come with

DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Wikidata: Cannot convert undefined or null to object

UnhandledPromiseRejectionWarning: TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at Object.simplifyEntities [as entities] (/packages/plugin-wikidata/node_modules/wikidata-sdk/lib/helpers/simplify_entity.js:35:17)
    at entities (/packages/plugin-wikidata/src/prop.js:117:12)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/packages/plugin-wikidata/src/prop.js:28:103)
    at _next (/packages/plugin-wikidata/src/prop.js:30:194)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)

Error for wd:Q149998

TypeError: Cannot read property 'P1813' of undefined
    at getPlace (/packages/plugin-wikidata/lib/prop.js:61:50)
    at parseProp (/packages/plugin-wikidata/lib/prop.js:117:14)
    at parseEntity (/packages/plugin-wikidata/lib/entity.js:67:42)
    at Array.map (<anonymous>)
    at Object.<anonymous> (/packages/plugin-wikidata/lib/entity.js:135:50)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/packages/plugin-wikidata/lib/entity.js:20:103)
    at _next (/packages/plugin-wikidata/lib/entity.js:22:194)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)

Improve logging of incomplete mappings

While messages have been improved in #10 (and the refactor preceding #7), it would be better to completely standardize the logging of incomplete mappings and make them more machine-readable as well.

DOI content negotiation fallback

DOI content negotiation doesn't give a 404 message when certain data isn't available; it redirects to the HTML page, which currently gives an unclear error message:

SyntaxError: Unexpected token < in JSON at position 0

Check in fetchFile[Async] whether the resulting Content-Type matches the Accept header.

Wikidata: values.map is not a function

UnhandledPromiseRejectionWarning: TypeError: values.map is not a function
    at map (/packages/plugin-wikidata/src/prop.js:149:21)
    at parseProp (/packages/plugin-wikidata/src/prop.js:197:14)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/packages/plugin-wikidata/src/prop.js:28:103)
    at _next (/packages/plugin-wikidata/src/prop.js:30:194)
    at /packages/plugin-wikidata/src/prop.js:30:364
    at new Promise (<anonymous>)
    at /packages/plugin-wikidata/src/prop.js:30:97
    at parsePropAsync (/packages/plugin-wikidata/src/prop.js:134:26)
    at /packages/plugin-wikidata/src/entity.js:53:37

Wikidata: Cannot read property 'labels' of undefined

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'labels' of undefined
    at labels (/packages/plugin-wikidata/src/prop.js:242:11)
    at getLabel (/packages/plugin-wikidata/src/prop.js:195:14)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/packages/plugin-wikidata/src/prop.js:28:103)
    at _next (/packages/plugin-wikidata/src/prop.js:30:194)
    at processTicksAndRejections (internal/process/next_tick.js:81:5)

Improve input type system format

Improve annoying things in the input type system formats, like naming collisions between arrays of ids and arrays of records (both list+object now), and certain scopes not being descriptive and contained.

npm based citation styles

Hi Lars,

Really nice project! I had an idea about how to distribute CSL citation styles/locales in an NPM-friendly world, as very simple NPM packages. I set up a repo to produce these, and have uploaded a few useful ones:

  • style-nature
  • style-apa
  • style-mla
  • style-chicago
  • style-vancouver
  • style-rsc
  • locale-en-gb
  • locale-en-us
  • locale-es-es
  • locale-de-de
  • locale-fr-fr

What do you think? This was just a trial to see if it works, but it seems to work nicely. Thought this project could use them too.

Rich

Create core tests

  • core.util
  • plugins-common JSON output
  • Cite#get and Cite#validate
  • Cite#sort
  • core.plugins.input

Drop Node 6 support

  • Node 6 is out of maintenance a few months now
  • dependencies have started dropping support (and rightfully so I guess, although doing that in a patch version bump is a bit drastic) ForbesLindesay/sync-request#121
  • I really want to be able to use Object.entries

Disable logging by default

How can I disable all that noise printed to stderr? Even a `require('citation-js') emits

[set] Subclass "@bibjson/quickscrape+record+object" is waiting on parent type "@bibjson/record+object"
[set] Subclasses "@bibjson/quickscrape+record+object" finally registered to parent type

I'd prefer disabled logging by default and enabling with an environment variable (can be set in .env with dotenv package).

Changes to the Plugins API

I realize this is a breaking change, so it probably won't be added until you decide it's time for the 1.0 release.

This suggestion builds upon my pull request (#29). As ES6 modules become more and more widespread, global variables are increasingly frowned upon. Citation.js relies on globals for registering plugins: require('@citation-js/plugin-bibtex')

I would suggest changing the API to use explicit plugin registering. For example:

import { Cite } from '@citation-js/core';
import bibtex from '@citation-js/plugin-bibtex';
import ris from '@citation-js/plugin-ris';

const cite = await Cite
  .use(bibtex)
  .use(ris)
  .async('Q21972834');

It would basically involve two steps:

  1. Add a .use() method to Cite that calls plugins.add and then returns this.
  2. Remove plugins.add from each plugin.

I would be willing to work on this, if you want. But first I have to make sure you even think it's a good idea.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.