bibtex-parse
Parse BibTeX to JSON.
npm install bibtex-parse
Example
const bibtexParse = ;const fs = ;const bibtex = fs;bibtexParse;
example.bib
:
@preamble{"Reference list"}@string{ian = "Brown, Ian"}@string{jane = "Woods, Jane"}%references@inproceedings{Smith2009, author=jane, year=2009, month=dec, title={{Quantum somethings}}, journal={Journal of {B}lah}} @book{IP:1990,author = ian # " and " # jane,year = {1990},title = {Methods for Research}}
output:
Note: fields are always output in capitals to distinguish from build in attributes (key
and type
).
Abstract Syntax Tree
To get the AST, use:
bibtexParse;
Where bibtex
is a string representing bibtex to be parsed, and options an object with any of the following:
number
: tells the parser how numbers should be returned.number: "auto"
(default): return a JavaScript number, unless over MAX_SAFE_INTEGER (9007199254740991), in which case a BigInt is returned.number: "number"
: always return a JavaScript number, even if over MAX_SAFE_INTEGER (in which case the precision will be lost).number: "bigint"
: always return a BigInt.number: "string"
: return number as a string.
This will return an array of items. There are four types of item:
- string:
{ itemtype: 'string', name, value, datatype, enclosed }
- preamble:
{ itemtype: 'preamble', value, datatype, enclosed }
- comment:
{ itemtype: 'comment', comment }
- entry:
{ itemtype: 'entry', type, key, enclosed, fields }
,type
: e.g. article, inproceedings, bookkey
: the unique identifier for the entryfields
: e.g. title, year[{ name: 'year', value: 2001, datatype: 'number' }, ...]
Datatype can be one of the following:
number
: an integer numberidentifier
: a string variable namebraced
: a value which was enclosed in curly bracesquoted
: a value which was enclosed in double quotesconcatinate
: in which case the correspondingvalue
property will be an array[{ datatype, value }, ...]
null
: used when no value has been assigned, e.g.@string{a}
unenclosed
: used when a preamble has not been properly enclosed (e.g@preamble{this isn't enclosed}
).
Enclosed can be one of the following:
braces
- when item is enclosed in curly braces (e.g.@string{a = 1}
)parentheses
- when item is enclosed in brackets (e.g.@string(a = 1)
)
Resources
- A summary of BibTex - http://maverick.inria.fr/~Xavier.Decoret/resources/xdkbibtex/bibtex_summary.html
- ORCID bibtex parse library - https://github.com/ORCID/bibtexParseJs