@retorquere/bibtex-parser 7.0.16 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -1,130 +1,12 @@
1
- import * as bibtex from './grammar';
2
- import * as chunker from './chunker';
3
- import * as jabref from './jabref';
4
- import { JabRefMetadata } from './jabref';
1
+ import { Node } from '@unified-latex/unified-latex-types';
2
+ import * as bibtex from './verbatim';
3
+ import * as JabRef from './jabref';
5
4
  export { toSentenceCase } from './sentence-case';
6
- type Node = bibtex.Bibliography | bibtex.Math | bibtex.Environment | bibtex.Block | bibtex.RegularCommand | bibtex.DiacriticCommand | bibtex.Entry | bibtex.Field | bibtex.NumberValue | bibtex.StringDeclaration | bibtex.StringReference | bibtex.SubscriptCommand | bibtex.SuperscriptCommand | bibtex.SymbolCommand | bibtex.TextValue | bibtex.PreambleExpression | bibtex.BracedComment | bibtex.LineComment | bibtex.Markup | bibtex.NonEntryText;
7
- export interface Name {
8
- /**
9
- * If the name is a literal (surrounded by braces) it will be in this property, and none of the other properties will be set
10
- */
11
- literal?: string;
12
- /**
13
- * Family name
14
- */
15
- lastName?: string;
16
- /**
17
- * available when parsing biblatex extended name format
18
- */
19
- useprefix?: boolean;
20
- /**
21
- * available when parsing biblatex extended name format
22
- */
23
- juniorcomma?: boolean;
24
- /**
25
- * given name. Will include middle names and initials.
26
- */
27
- firstName?: string;
28
- /**
29
- * Initials.
30
- */
31
- initial?: string;
32
- /**
33
- * things like `Jr.`, `III`, etc
34
- */
35
- suffix?: string;
36
- /**
37
- * things like `von`, `van der`, etc
38
- */
39
- prefix?: string;
40
- }
41
- export interface Entry {
42
- /**
43
- * citation key
44
- */
45
- key: string;
46
- /**
47
- * entry type
48
- */
49
- type: string;
50
- /**
51
- * entry fields. The keys are always in lowercase
52
- */
53
- fields: {
54
- [key: string]: string[];
55
- };
56
- /**
57
- * authors, editors, by creator type. Name order within the creator-type is retained.
58
- */
59
- creators: {
60
- [type: string]: Name[];
61
- };
62
- /**
63
- * will be set to `true` if sentence casing was applied to the entry
64
- */
65
- sentenceCased?: boolean;
66
- /**
67
- * list of fields that have been inherited/donated using crossref/xdata
68
- */
69
- crossref: {
70
- donated: string[];
71
- inherited: string[];
72
- };
73
- }
74
- /**
75
- * Markup mapping. As the bibtex file is parsed, markup will be transformed according to this table
76
- */
77
- export interface MarkupMapping {
78
- sub?: {
79
- open: string;
80
- close: string;
81
- };
82
- sup?: {
83
- open: string;
84
- close: string;
85
- };
86
- bold?: {
87
- open: string;
88
- close: string;
89
- };
90
- italics?: {
91
- open: string;
92
- close: string;
93
- };
94
- smallCaps?: {
95
- open: string;
96
- close: string;
97
- };
98
- caseProtect?: {
99
- open: string;
100
- close: string;
101
- };
102
- enquote?: {
103
- open: string;
104
- close: string;
105
- };
106
- h1?: {
107
- open: string;
108
- close: string;
109
- };
110
- h2?: {
111
- open: string;
112
- close: string;
113
- };
114
- roman?: {
115
- open: string;
116
- close: string;
117
- };
118
- fixedWidth?: {
119
- open: string;
120
- close: string;
121
- };
122
- }
123
5
  export interface Bibliography {
124
6
  /**
125
7
  * errors found while parsing
126
8
  */
127
- errors: ParseError[];
9
+ errors: bibtex.ParseError[];
128
10
  /**
129
11
  * entries in the order in which they are found, omitting those which could not be parsed.
130
12
  */
@@ -144,114 +26,87 @@ export interface Bibliography {
144
26
  /**
145
27
  * jabref metadata (such as groups information) found in the bibtex file
146
28
  */
147
- jabref: JabRefMetadata;
148
- }
149
- export interface ParseError {
150
- /**
151
- * error message
152
- */
153
- message: string;
154
- /**
155
- * text block that was parsed where the error was found
156
- */
157
- source?: string;
158
- /**
159
- * Error line number within the bibtex file
160
- */
161
- line?: number;
162
- /**
163
- * Error column number within the bibtex file
164
- */
165
- column?: number;
29
+ jabref: JabRef.JabRefMetadata;
166
30
  }
167
- export declare const fields: {
168
- creator: string[];
169
- title: string[];
170
- unnest: string[];
171
- verbatim: string[];
172
- html: string[];
173
- unabbrev: string[];
174
- };
175
- export interface ParserOptions {
176
- /**
177
- * BibTeX files are expected to store title-type fields in Sentence Case, where other reference managers (such as Zotero) expect them to be stored as Sentence case. When there is no language field, or the language field
178
- * is one of the languages (case insensitive) passed in this option, the parser will attempt to sentence-case title-type fields as they are being parsed. This uses heuristics and does not employ any kind of natural
179
- * language processing, so you should always inspect the results. Default languages to sentenceCase are:
180
- *
181
- * - american
182
- * - british
183
- * - canadian
184
- * - english
185
- * - australian
186
- * - newzealand
187
- * - usenglish
188
- * - ukenglish
189
- * - en
190
- * - eng
191
- * - en-au
192
- * - en-bz
193
- * - en-ca
194
- * - en-cb
195
- * - en-gb
196
- * - en-ie
197
- * - en-jm
198
- * - en-nz
199
- * - en-ph
200
- * - en-tt
201
- * - en-us
202
- * - en-za
203
- * - en-zw
204
- *
205
- * If you pass an empty array, or `false`, no sentence casing will be applied (even when there's no language field).
206
- */
207
- sentenceCase?: string[] | boolean;
208
- /**
209
- * If you have sentence-casing on, you can independently choose whether quoted titles within a title are preserved as-is (true) or also sentence-cased(false)
210
- */
211
- sentenceCasePreserveQuoted?: boolean;
212
- /**
213
- * Some bibtex has titles in sentence case, or all-uppercase. If this is on, and there is a field that would normally have sentence-casing applied in which more words are all-`X`case
214
- * (where `X` is either lower or upper) than mixed-case, it is assumed that you want them this way, and no sentence-casing will be applied to that field
215
- */
216
- guessAlreadySentenceCased?: boolean;
31
+ export interface Options {
32
+ sentenceCase?: {
33
+ /**
34
+ * BibTeX files are expected to store title-type fields in Sentence Case, where other reference managers (such as Zotero) expect them to be stored as Sentence case. When there is no language field, or the language field
35
+ * is one of the languages (case insensitive) passed in this option, the parser will attempt to sentence-case title-type fields as they are being parsed. This uses heuristics and does not employ any kind of natural
36
+ * language processing, so you should always inspect the results. Default languages to sentenceCase are:
37
+ *
38
+ * - american
39
+ * - british
40
+ * - canadian
41
+ * - english
42
+ * - australian
43
+ * - newzealand
44
+ * - usenglish
45
+ * - ukenglish
46
+ * - en
47
+ * - eng
48
+ * - en-au
49
+ * - en-bz
50
+ * - en-ca
51
+ * - en-cb
52
+ * - en-gb
53
+ * - en-ie
54
+ * - en-jm
55
+ * - en-nz
56
+ * - en-ph
57
+ * - en-tt
58
+ * - en-us
59
+ * - en-za
60
+ * - en-zw
61
+ *
62
+ * If you pass an empty array, or `false`, no sentence casing will be applied (even when there's no language field).
63
+ */
64
+ langids?: string[] | boolean;
65
+ /**
66
+ * By default, `langid` and `hyphenation` are used to determine whether an entry should be sentence-cased, but some sources (ab)use the `language` field
67
+ * for this. If you turn on this option, this field will also be taken into account as a source for `langid`.
68
+ */
69
+ language?: boolean;
70
+ /**
71
+ * Some bibtex files will have titles in sentence case, or all-uppercase. If this is on, and there is a field that would normally have sentence-casing applied in which more words are all-`X`case
72
+ * (where `X` is either lower or upper) than mixed-case, it is assumed that you want them this way, and no sentence-casing will be applied to that field
73
+ */
74
+ guess?: boolean;
75
+ /**
76
+ * Capitalize sub-sentences after colons. Given the input title "Structured Interviewing For OCB: Construct Validity, Faking, And The Effects Of Question Type":
77
+ * - when `true`, sentence-cases to "Structured interviewing for OCB: Construct validity, faking, and the effects of question type"
78
+ * - when `false`, sentence-cases to "Structured interviewing for OCB: construct validity, faking, and the effects of question type"
79
+ */
80
+ subSentence?: boolean;
81
+ /**
82
+ * If you have sentence-casing on, you can independently choose whether quoted titles within a title are preserved as-is (true) or also sentence-cased(false)
83
+ */
84
+ preserveQuoted?: boolean;
85
+ };
217
86
  /**
218
- * translate braced parts of text into a case-protected counterpart; uses the [[MarkupMapping]] table in `markup`. Default == true == as-needed.
87
+ * translate braced parts of text into a case-protected counterpart; Default == true == as-needed.
219
88
  * In as-needed mode the parser will assume that words that have capitals in them imply "nocase" behavior in the consuming application. If you don't want this, turn this option on, and you'll get
220
89
  * case protection exactly as the input has it
221
90
  */
222
91
  caseProtection?: 'as-needed' | 'strict' | boolean;
223
92
  /**
224
- * The parser can change TeX markup (\\textsc, \\emph, etc) to a text equivalent. The defaults are HTML-oriented, but you can pass in your own configuration here
225
- */
226
- markup?: MarkupMapping;
227
- /**
228
- * By default, when an unexpected parsing error is found (such as a TeX command which the parser does not know about), the parser will throw an error. You can pass a function to handle the error instead,
229
- * where you can log it, display it, or even still throw an error
230
- */
231
- errorHandler?: false | ((err: Error) => void);
232
- /**
233
- * By default, when a TeX command is encountered which the parser does not know about, the parser will throw an error. You can pass a function here to return the appropriate AST for the command.
93
+ * By default, when a TeX command is encountered which the parser does not know about, the parser will throw an error. You can pass a function here to return the appropriate text output for the command.
234
94
  */
235
- unknownCommandHandler?: false | ((node: bibtex.RegularCommand) => Node);
95
+ unsupported?: 'ignore' | unsupportedHandler;
236
96
  /**
237
97
  * Some fields such as `url` are parsed in what is called "verbatim mode" where pretty much everything except braces is treated as regular text, not TeX commands. You can change the default list here if you want,
238
98
  * for example to help parse Mendeley `file` fields, which against spec are not in verbatim mode.
239
99
  */
240
100
  verbatimFields?: (string | RegExp)[];
241
- /**
242
- * Some commands such as `url` are parsed in what is called "verbatim mode" where pretty much everything except braces is treated as regular text, not TeX commands.
243
- */
244
- verbatimCommands?: string[];
245
101
  /**
246
102
  * In the past many bibtex entries would just always wrap a field in double braces, likely because whomever was writing them couldn't figure out the case meddling rules (and who could
247
103
  * blame them). Fields listed here will either have one outer layer of braces treated as case-preserve, or have the outer braced be ignored completely, if this is detected.
248
104
  */
249
- unnestFields?: string[];
250
- unnestMode?: 'preserve' | 'unwrap';
105
+ removeOuterBraces?: string[];
251
106
  /**
252
- * Some note-like fields may have more rich formatting. If listed here, more HTML conversions will be applied.
107
+ * Specify parsing mode for specific fields
253
108
  */
254
- htmlFields?: string[];
109
+ fieldMode?: Record<string, ParseMode>;
255
110
  /**
256
111
  * If this flag is set entries will be returned without conversion of LaTeX to unicode equivalents.
257
112
  */
@@ -263,20 +118,58 @@ export interface ParserOptions {
263
118
  /**
264
119
  * BibTeX files may have abbreviations in the journal field. If you provide a dictionary, journal names that are found in the dictionary are replaced with the attached full name
265
120
  */
266
- unabbreviate?: Record<string, string>;
121
+ unabbreviations?: boolean | Record<string, string>;
267
122
  /**
268
123
  * Apply crossref inheritance
269
124
  */
270
125
  applyCrossRef?: boolean;
271
126
  }
272
- /**
273
- * parse bibtex. This will try to convert TeX commands into unicode equivalents, and apply `@string` expansion
274
- */
275
- export declare function parse(input: string, options?: ParserOptions): Bibliography;
276
- export declare function ast(input: string, options?: ParserOptions, clean?: boolean): Node[];
277
- export declare const promises: {
278
- parse(input: string, options?: ParserOptions): Promise<Bibliography>;
127
+ interface Creator {
128
+ name?: string;
129
+ lastName?: string;
130
+ firstName?: string;
131
+ prefix?: string;
132
+ suffix?: string;
133
+ initial?: string;
134
+ useprefix?: boolean;
135
+ juniorcomma?: boolean;
136
+ }
137
+ interface Entry {
138
+ type: string;
139
+ key: string;
140
+ fields: {
141
+ author?: Creator[];
142
+ bookauthor?: Creator[];
143
+ collaborator?: Creator[];
144
+ commentator?: Creator[];
145
+ director?: Creator[];
146
+ editor?: Creator[];
147
+ editora?: Creator[];
148
+ editorb?: Creator[];
149
+ editors?: Creator[];
150
+ holder?: Creator[];
151
+ scriptwriter?: Creator[];
152
+ translator?: Creator[];
153
+ keywords?: string[];
154
+ institution?: string[];
155
+ publisher?: string[];
156
+ origpublisher?: string[];
157
+ organization?: string[];
158
+ location?: string[];
159
+ origlocation?: string[];
160
+ [key: string]: number | string | string[] | Creator[];
161
+ };
162
+ }
163
+ export declare const FieldMode: {
164
+ creator: string[];
165
+ title: string[];
166
+ verbatim: (string | RegExp)[];
167
+ richtext: string[];
168
+ commalist: string[];
169
+ literallist: string[];
279
170
  };
280
- export { chunker };
281
- export { jabref };
171
+ type ParseMode = keyof typeof FieldMode | 'literal';
172
+ type unsupportedHandler = (node: Node, tex?: string, entry?: Entry) => string | undefined;
173
+ export declare function parse(input: string, options?: Options): Bibliography;
174
+ export declare function parseAsync(input: string, options?: Options): Promise<Bibliography>;
282
175
  //# sourceMappingURL=index.d.ts.map