larsgw / 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.
https://citation.js.org/
MIT License
226 stars 30 forks source link

Sort based on keys #43

Closed larsgw closed 7 years ago

larsgw commented 7 years ago

Currently, sorting is done by BibTeX label. It would be nice if there's an option to sort as you want, for example first by author, then by year, then by title. Example API could be like this:

const data = Cite(...)

data.sort(['author', 'year', 'title'])
larsgw commented 7 years ago

Also, sort by custom comparison function.

larsgw commented 7 years ago

Now implemented. Will push as soon as DOI is fixed and test cases and docs are ready. Syntax as above:

Regular:

const data = Cite(...)

data.sort(['author', 'year', 'title'])

Sort author reversed:

const data = Cite(...)

data.sort(['!author'])

Custom callback (same as callback for Array#sort()):

const data = Cite(...)

data.sort((objA, objB) => Math.sign(Math.random() - .5))
larsgw commented 7 years ago

Closed in e528dc919311576658124a7e60e866ecf132e6a8