@retorquere/bibtex-parser 12.1.11 → 13.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.
Files changed (76) hide show
  1. package/README.md +14 -10
  2. package/dist/esm/crossref.d.ts.map +1 -0
  3. package/dist/esm/crossref.js.map +1 -1
  4. package/dist/esm/fields.d.ts.map +1 -0
  5. package/dist/esm/fields.js.map +1 -1
  6. package/dist/{types → esm}/index.d.ts +41 -12
  7. package/dist/esm/index.d.ts.map +1 -0
  8. package/dist/esm/index.js +27 -3
  9. package/dist/esm/index.js.map +3 -3
  10. package/dist/{types → esm}/jabref.d.ts +9 -21
  11. package/dist/esm/jabref.d.ts.map +1 -0
  12. package/dist/esm/jabref.js +2 -3
  13. package/dist/esm/jabref.js.map +3 -3
  14. package/dist/esm/merge.d.ts.map +1 -0
  15. package/dist/esm/merge.js.map +1 -1
  16. package/dist/esm/prepositions.d.ts.map +1 -0
  17. package/dist/esm/prepositions.js.map +1 -1
  18. package/dist/{types → esm}/sentence-case.d.ts +1 -0
  19. package/dist/esm/sentence-case.d.ts.map +1 -0
  20. package/dist/esm/sentence-case.js +126 -28
  21. package/dist/esm/sentence-case.js.map +3 -3
  22. package/dist/esm/tokenizer.d.ts.map +1 -0
  23. package/dist/esm/tokenizer.js.map +1 -1
  24. package/dist/esm/verbatim.d.ts +90 -0
  25. package/dist/esm/verbatim.d.ts.map +1 -0
  26. package/dist/esm/verbatim.js +10 -0
  27. package/dist/esm/verbatim.js.map +3 -3
  28. package/dist/esm/yield.d.ts.map +1 -0
  29. package/dist/esm/yield.js.map +1 -1
  30. package/dist/wasm/bibtex_parser.d.ts +12 -9
  31. package/dist/wasm/bibtex_parser.js +13 -23
  32. package/dist/wasm/bibtex_parser_bg.wasm +0 -0
  33. package/dist/wasm/bibtex_parser_bg.wasm.d.ts +2 -3
  34. package/dist/wasm/english.json +27 -0
  35. package/dist/wasm/index.d.ts +105 -29
  36. package/dist/wasm/index.js +54 -51
  37. package/dist/wasm/jabref.d.ts +9 -21
  38. package/dist/wasm/jabref.js +3 -3
  39. package/package.json +25 -26
  40. package/dist/cjs/crossref.js +0 -201
  41. package/dist/cjs/crossref.js.map +0 -7
  42. package/dist/cjs/fields.js +0 -7186
  43. package/dist/cjs/fields.js.map +0 -7
  44. package/dist/cjs/index.js +0 -1126
  45. package/dist/cjs/index.js.map +0 -7
  46. package/dist/cjs/jabref.js +0 -135
  47. package/dist/cjs/jabref.js.map +0 -7
  48. package/dist/cjs/merge.js +0 -37
  49. package/dist/cjs/merge.js.map +0 -7
  50. package/dist/cjs/prepositions.js +0 -111
  51. package/dist/cjs/prepositions.js.map +0 -7
  52. package/dist/cjs/sentence-case.js +0 -98
  53. package/dist/cjs/sentence-case.js.map +0 -7
  54. package/dist/cjs/tokenizer.js +0 -194
  55. package/dist/cjs/tokenizer.js.map +0 -7
  56. package/dist/cjs/verbatim.js +0 -403
  57. package/dist/cjs/verbatim.js.map +0 -7
  58. package/dist/cjs/yield.js +0 -26
  59. package/dist/cjs/yield.js.map +0 -7
  60. package/dist/types/crossref.d.ts.map +0 -1
  61. package/dist/types/fields.d.ts.map +0 -1
  62. package/dist/types/index.d.ts.map +0 -1
  63. package/dist/types/jabref.d.ts.map +0 -1
  64. package/dist/types/merge.d.ts.map +0 -1
  65. package/dist/types/prepositions.d.ts.map +0 -1
  66. package/dist/types/sentence-case.d.ts.map +0 -1
  67. package/dist/types/tokenizer.d.ts.map +0 -1
  68. package/dist/types/verbatim.d.ts +0 -66
  69. package/dist/types/verbatim.d.ts.map +0 -1
  70. package/dist/types/yield.d.ts.map +0 -1
  71. /package/dist/{types → esm}/crossref.d.ts +0 -0
  72. /package/dist/{types → esm}/fields.d.ts +0 -0
  73. /package/dist/{types → esm}/merge.d.ts +0 -0
  74. /package/dist/{types → esm}/prepositions.d.ts +0 -0
  75. /package/dist/{types → esm}/tokenizer.d.ts +0 -0
  76. /package/dist/{types → esm}/yield.d.ts +0 -0
@@ -19,6 +19,7 @@ export function parse(input, options) {
19
19
  }
20
20
 
21
21
  /**
22
+ * Parse and render BibTeX cooperatively, yielding between directive and entry batches.
22
23
  * @param {string} input
23
24
  * @param {any | null} [options]
24
25
  * @returns {Promise<any>}
@@ -47,6 +48,7 @@ export function parseVerbatim(input, options) {
47
48
  }
48
49
 
49
50
  /**
51
+ * Parse raw BibTeX cooperatively, yielding between directive batches and returning a JS object.
50
52
  * @param {string} input
51
53
  * @param {any | null} [options]
52
54
  * @returns {Promise<any>}
@@ -58,12 +60,15 @@ export function parseVerbatimAsync(input, options) {
58
60
  return ret;
59
61
  }
60
62
 
63
+ /**
64
+ * Install the browser-console panic hook once when the WASM module is initialized.
65
+ */
61
66
  export function start() {
62
67
  wasm.start();
63
68
  }
64
69
 
65
70
  /**
66
- * Apply sentence casing with the standalone TypeScript API's defaulted option object.
71
+ * Apply sentence casing using optional `guess`, `subSentenceCapitalization`, and `preserveQuoted` flags.
67
72
  * @param {string} input
68
73
  * @param {any | null} [options]
69
74
  * @returns {string}
@@ -88,21 +93,6 @@ export function toSentenceCase(input, options) {
88
93
  wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
89
94
  }
90
95
  }
91
-
92
- /**
93
- * Tokenize Unicode title text using the same token record shape as TypeScript.
94
- * @param {string} input
95
- * @returns {any}
96
- */
97
- export function tokenize(input) {
98
- const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
99
- const len0 = WASM_VECTOR_LEN;
100
- const ret = wasm.tokenize(ptr0, len0);
101
- if (ret[2]) {
102
- throw takeFromExternrefTable0(ret[1]);
103
- }
104
- return takeFromExternrefTable0(ret[0]);
105
- }
106
96
  function __wbg_get_imports() {
107
97
  const import0 = {
108
98
  __proto__: null,
@@ -312,7 +302,7 @@ function __wbg_get_imports() {
312
302
  const a = state0.a;
313
303
  state0.a = 0;
314
304
  try {
315
- return wasm_bindgen_27e16af4bbf8dd6f___convert__closures_____invoke___js_sys_8149d826ad841366___Function_fn_wasm_bindgen_27e16af4bbf8dd6f___JsValue_____wasm_bindgen_27e16af4bbf8dd6f___sys__Undefined___js_sys_8149d826ad841366___Function_fn_wasm_bindgen_27e16af4bbf8dd6f___JsValue_____wasm_bindgen_27e16af4bbf8dd6f___sys__Undefined_______true_(a, state0.b, arg0, arg1);
305
+ return wasm_bindgen_7c27bb0bb2b93bf___convert__closures_____invoke___js_sys_4854f420e42f68ae___Function_fn_wasm_bindgen_7c27bb0bb2b93bf___JsValue_____wasm_bindgen_7c27bb0bb2b93bf___sys__Undefined___js_sys_4854f420e42f68ae___Function_fn_wasm_bindgen_7c27bb0bb2b93bf___JsValue_____wasm_bindgen_7c27bb0bb2b93bf___sys__Undefined_______true_(a, state0.b, arg0, arg1);
316
306
  } finally {
317
307
  state0.a = a;
318
308
  }
@@ -391,8 +381,8 @@ function __wbg_get_imports() {
391
381
  return ret;
392
382
  },
393
383
  __wbindgen_generic_0000000000000001: function(arg0, arg1) {
394
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 85, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
395
- const ret = makeMutClosure(arg0, arg1, wasm_bindgen_27e16af4bbf8dd6f___convert__closures_____invoke___wasm_bindgen_27e16af4bbf8dd6f___JsValue__core_37ee0ce0c4cd57d5___result__Result_____wasm_bindgen_27e16af4bbf8dd6f___JsError___true_);
384
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 87, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
385
+ const ret = makeMutClosure(arg0, arg1, wasm_bindgen_7c27bb0bb2b93bf___convert__closures_____invoke___wasm_bindgen_7c27bb0bb2b93bf___JsValue__core_37ee0ce0c4cd57d5___result__Result_____wasm_bindgen_7c27bb0bb2b93bf___JsError___true_);
396
386
  return ret;
397
387
  },
398
388
  __wbindgen_generic_0000000000000002: function(arg0) {
@@ -432,15 +422,15 @@ function __wbg_get_imports() {
432
422
  };
433
423
  }
434
424
 
435
- function wasm_bindgen_27e16af4bbf8dd6f___convert__closures_____invoke___wasm_bindgen_27e16af4bbf8dd6f___JsValue__core_37ee0ce0c4cd57d5___result__Result_____wasm_bindgen_27e16af4bbf8dd6f___JsError___true_(arg0, arg1, arg2) {
436
- const ret = wasm.wasm_bindgen_27e16af4bbf8dd6f___convert__closures_____invoke___wasm_bindgen_27e16af4bbf8dd6f___JsValue__core_37ee0ce0c4cd57d5___result__Result_____wasm_bindgen_27e16af4bbf8dd6f___JsError___true_(arg0, arg1, arg2);
425
+ function wasm_bindgen_7c27bb0bb2b93bf___convert__closures_____invoke___wasm_bindgen_7c27bb0bb2b93bf___JsValue__core_37ee0ce0c4cd57d5___result__Result_____wasm_bindgen_7c27bb0bb2b93bf___JsError___true_(arg0, arg1, arg2) {
426
+ const ret = wasm.wasm_bindgen_7c27bb0bb2b93bf___convert__closures_____invoke___wasm_bindgen_7c27bb0bb2b93bf___JsValue__core_37ee0ce0c4cd57d5___result__Result_____wasm_bindgen_7c27bb0bb2b93bf___JsError___true_(arg0, arg1, arg2);
437
427
  if (ret[1]) {
438
428
  throw takeFromExternrefTable0(ret[0]);
439
429
  }
440
430
  }
441
431
 
442
- function wasm_bindgen_27e16af4bbf8dd6f___convert__closures_____invoke___js_sys_8149d826ad841366___Function_fn_wasm_bindgen_27e16af4bbf8dd6f___JsValue_____wasm_bindgen_27e16af4bbf8dd6f___sys__Undefined___js_sys_8149d826ad841366___Function_fn_wasm_bindgen_27e16af4bbf8dd6f___JsValue_____wasm_bindgen_27e16af4bbf8dd6f___sys__Undefined_______true_(arg0, arg1, arg2, arg3) {
443
- wasm.wasm_bindgen_27e16af4bbf8dd6f___convert__closures_____invoke___js_sys_8149d826ad841366___Function_fn_wasm_bindgen_27e16af4bbf8dd6f___JsValue_____wasm_bindgen_27e16af4bbf8dd6f___sys__Undefined___js_sys_8149d826ad841366___Function_fn_wasm_bindgen_27e16af4bbf8dd6f___JsValue_____wasm_bindgen_27e16af4bbf8dd6f___sys__Undefined_______true_(arg0, arg1, arg2, arg3);
432
+ function wasm_bindgen_7c27bb0bb2b93bf___convert__closures_____invoke___js_sys_4854f420e42f68ae___Function_fn_wasm_bindgen_7c27bb0bb2b93bf___JsValue_____wasm_bindgen_7c27bb0bb2b93bf___sys__Undefined___js_sys_4854f420e42f68ae___Function_fn_wasm_bindgen_7c27bb0bb2b93bf___JsValue_____wasm_bindgen_7c27bb0bb2b93bf___sys__Undefined_______true_(arg0, arg1, arg2, arg3) {
433
+ wasm.wasm_bindgen_7c27bb0bb2b93bf___convert__closures_____invoke___js_sys_4854f420e42f68ae___Function_fn_wasm_bindgen_7c27bb0bb2b93bf___JsValue_____wasm_bindgen_7c27bb0bb2b93bf___sys__Undefined___js_sys_4854f420e42f68ae___Function_fn_wasm_bindgen_7c27bb0bb2b93bf___JsValue_____wasm_bindgen_7c27bb0bb2b93bf___sys__Undefined_______true_(arg0, arg1, arg2, arg3);
444
434
  }
445
435
 
446
436
  function addToExternrefTable0(obj) {
Binary file
@@ -7,9 +7,8 @@ export const parseVerbatim: (a: number, b: number, c: number) => [number, number
7
7
  export const parseVerbatimAsync: (a: number, b: number, c: number) => any;
8
8
  export const start: () => void;
9
9
  export const toSentenceCase: (a: number, b: number, c: number) => [number, number, number, number];
10
- export const tokenize: (a: number, b: number) => [number, number, number];
11
- export const wasm_bindgen_27e16af4bbf8dd6f___convert__closures_____invoke___js_sys_8149d826ad841366___Function_fn_wasm_bindgen_27e16af4bbf8dd6f___JsValue_____wasm_bindgen_27e16af4bbf8dd6f___sys__Undefined___js_sys_8149d826ad841366___Function_fn_wasm_bindgen_27e16af4bbf8dd6f___JsValue_____wasm_bindgen_27e16af4bbf8dd6f___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
12
- export const wasm_bindgen_27e16af4bbf8dd6f___convert__closures_____invoke___wasm_bindgen_27e16af4bbf8dd6f___JsValue__core_37ee0ce0c4cd57d5___result__Result_____wasm_bindgen_27e16af4bbf8dd6f___JsError___true_: (a: number, b: number, c: any) => [number, number];
10
+ export const wasm_bindgen_7c27bb0bb2b93bf___convert__closures_____invoke___js_sys_4854f420e42f68ae___Function_fn_wasm_bindgen_7c27bb0bb2b93bf___JsValue_____wasm_bindgen_7c27bb0bb2b93bf___sys__Undefined___js_sys_4854f420e42f68ae___Function_fn_wasm_bindgen_7c27bb0bb2b93bf___JsValue_____wasm_bindgen_7c27bb0bb2b93bf___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
11
+ export const wasm_bindgen_7c27bb0bb2b93bf___convert__closures_____invoke___wasm_bindgen_7c27bb0bb2b93bf___JsValue__core_37ee0ce0c4cd57d5___result__Result_____wasm_bindgen_7c27bb0bb2b93bf___JsError___true_: (a: number, b: number, c: any) => [number, number];
13
12
  export const __wbindgen_malloc: (a: number, b: number) => number;
14
13
  export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
15
14
  export const __wbindgen_exn_store: (a: number) => void;
@@ -0,0 +1,27 @@
1
+ [
2
+ "",
3
+ "american",
4
+ "british",
5
+ "canadian",
6
+ "english",
7
+ "australian",
8
+ "newzealand",
9
+ "usenglish",
10
+ "ukenglish",
11
+ "en",
12
+ "eng",
13
+ "en-au",
14
+ "en-bz",
15
+ "en-ca",
16
+ "en-cb",
17
+ "en-gb",
18
+ "en-ie",
19
+ "en-jm",
20
+ "en-nz",
21
+ "en-ph",
22
+ "en-tt",
23
+ "en-us",
24
+ "en-za",
25
+ "en-zw",
26
+ "anglais"
27
+ ]
@@ -1,26 +1,67 @@
1
- /** @module wasm */
1
+ /** @module @retorquere/bibtex-parser */
2
2
  import init, { initSync } from './bibtex_parser.js';
3
3
  import { JabRefMetadata } from './jabref.js';
4
4
  export { JabRefMetadata };
5
5
  export type { Group as JabRefGroup } from './jabref.js';
6
- export type { InitInput, InitOutput, SyncInitInput } from './bibtex_parser.js';
7
- /** Initializes the WebAssembly parser; await this before using its exports. */
8
- export { init, initSync };
6
+ /** Inputs for asynchronous WASM initialization: a URL-like resource to fetch, bytes, or a compiled module. */
7
+ export type { InitInput } from './bibtex_parser.js';
8
+ /** Inputs for synchronous WASM initialization: bytes or a compiled module; synchronous initialization cannot fetch a URL. */
9
+ export type { SyncInitInput } from './bibtex_parser.js';
10
+ /** @ignore */
11
+ export type { InitOutput } from './bibtex_parser.js';
12
+ /**
13
+ * Loads and initializes the WebAssembly parser asynchronously.
14
+ *
15
+ * With no argument, the browser build fetches the package's WASM file relative to this module. Pass a URL-like resource to choose another location, or pass bytes when the caller loads the binary itself. Initialize once before calling parser functions.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import init, { parse } from '@retorquere/bibtex-parser'
20
+ *
21
+ * await init()
22
+ * const library = parse('@article{example, title={A title}}')
23
+ * ```
24
+ */
25
+ export { init };
26
+ /**
27
+ * Initializes the WebAssembly parser from bytes or a compiled module without fetching it.
28
+ * Call this before any parser function; prefer {@link init} when the binary should be loaded asynchronously.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { readFile } from 'node:fs/promises'
33
+ * import { initSync, parse } from '@retorquere/bibtex-parser'
34
+ *
35
+ * initSync({ module: await readFile('bibtex_parser_bg.wasm') })
36
+ * const library = parse('@article{example, title={A title}}')
37
+ * ```
38
+ */
39
+ export { initSync };
9
40
  export default init;
10
41
  /** Describes how a BibTeX field is interpreted. */
11
42
  export type ParseMode = 'creatorlist' | 'title' | 'verbatim' | 'richtext' | 'literallist' | 'literal' | 'verbatimlist';
12
43
  /** A parsed personal or organizational name. */
13
44
  export interface Creator {
45
+ /** Complete name when the parser cannot safely separate the name into components. */
14
46
  name?: string;
47
+ /** Family name, including any parsed name prefix. */
15
48
  lastName?: string;
49
+ /** Given name. */
16
50
  firstName?: string;
51
+ /** Name particle, such as "von" or "de", when separated from the family name. */
17
52
  prefix?: string;
53
+ /** Generational or other name suffix. */
18
54
  suffix?: string;
55
+ /** Initials of the given name. */
19
56
  initial?: string;
57
+ /** Whether the parsed family name includes a name prefix. */
20
58
  useprefix?: boolean;
59
+ /** Whether the source separated the suffix from the name with a comma. */
21
60
  juniorcomma?: boolean;
22
61
  }
62
+ /** A normalized field value: scalar text, a list of strings, or parsed creator records. */
23
63
  export type FieldValue = string | string[] | Creator[];
64
+ /** Creator-list fields whose values are returned as arrays of {@link Creator} objects. */
24
65
  export type CreatorFields = {
25
66
  author?: Creator[];
26
67
  bookauthor?: Creator[];
@@ -35,6 +76,7 @@ export type CreatorFields = {
35
76
  scriptwriter?: Creator[];
36
77
  translator?: Creator[];
37
78
  };
79
+ /** List-valued fields whose elements remain strings. */
38
80
  export type ArrayFields = {
39
81
  keywords?: string[];
40
82
  institution?: string[];
@@ -44,52 +86,56 @@ export type ArrayFields = {
44
86
  location?: string[];
45
87
  origlocation?: string[];
46
88
  };
89
+ /** The known creator-list and string-list fields in a normalized entry. */
47
90
  export type TypedFields = CreatorFields & ArrayFields;
91
+ /** Normalized BibTeX fields: known list fields have structured values; other fields are strings. */
48
92
  export type Fields = TypedFields & Omit<Record<string, string>, keyof TypedFields>;
49
93
  /** A normalized BibTeX entry returned by the parser. */
50
94
  export interface Entry {
95
+ /** Entry type from the source, such as `article` or `inproceedings`. */
51
96
  type: string;
97
+ /** Citation key identifying this entry. */
52
98
  key: string;
99
+ /** Parsed field values, with known creator and list fields represented as arrays. */
53
100
  fields: Fields;
101
+ /** Parsing mode used for each field; see {@link ParseMode}. */
54
102
  mode: Record<string, ParseMode>;
103
+ /** For fields inherited through `crossref`, records the parent entry key and source field name. */
55
104
  crossref?: Record<string, {
56
105
  parent: string;
57
106
  field: string;
58
107
  }>;
108
+ /** Source text for this entry. */
59
109
  input: string;
60
110
  }
61
111
  /** A parsing diagnostic. */
62
112
  export interface ParseError {
113
+ /** Human-readable diagnostic describing the parse or normalization issue. */
63
114
  error: string;
115
+ /** Source fragment associated with the diagnostic, when available. */
64
116
  input?: string;
65
117
  }
66
118
  /** The parsed contents of a BibTeX library. */
67
119
  export interface Library {
120
+ /** Diagnostics collected while parsing; recoverable errors do not necessarily prevent entries from being returned. */
68
121
  errors: ParseError[];
122
+ /** Successfully parsed entries, in source order. */
69
123
  entries: Entry[];
124
+ /** Text from `@comment` directives. */
70
125
  comments: string[];
126
+ /** Resolved values declared by `@string` directives. */
71
127
  strings: Record<string, string>;
128
+ /** Values from `@preamble` directives, in source order. */
72
129
  preambles: string[];
130
+ /** JabRef metadata extracted from the library, including groups and file settings. */
73
131
  jabref: JabRefMetadata;
74
132
  }
75
- /** Options controlling title sentence casing. */
133
+ /** Options used for sentence casing during BibTeX field normalization. */
76
134
  export interface SentenceCaseOptions {
77
135
  guess?: boolean;
78
136
  subSentence?: boolean;
79
137
  preserveQuoted?: boolean;
80
138
  }
81
- /** A classified text token returned by {@link tokenize}. */
82
- export interface Token {
83
- type: 'word' | 'domain' | 'whitespace' | 'number' | 'email' | 'handle' | 'website' | 'markup' | 'other' | 'punctuation';
84
- subtype: '' | 'preposition' | 'acronym' | 'contraction' | 'ordinal' | 'word' | 'end' | 'colon' | 'ellipsis';
85
- text: string;
86
- start: number;
87
- end: number;
88
- shape: string;
89
- sentenceStart: boolean;
90
- subSentenceStart: boolean;
91
- hyphenated?: Token[];
92
- }
93
139
  /** Options for normalized BibTeX parsing. */
94
140
  export interface Options extends ParserOptions {
95
141
  /** Language identifiers treated as English for title casing. */
@@ -100,10 +146,14 @@ export interface Options extends ParserOptions {
100
146
  sentenceCase?: SentenceCaseOptions;
101
147
  /** Control preservation of capitalization inside braces. */
102
148
  caseProtection?: 'off' | 'as-needed' | 'strict';
149
+ /** Merge adjacent equal markup spans separated only by whitespace (default true). */
150
+ collapseMarkup?: boolean;
151
+ /** Render URL commands as HTML links (default true), or as case-protected destinations. */
152
+ richURL?: boolean;
103
153
  /** Policy for unsupported TeX commands and environments. */
104
154
  unsupported?: 'tex' | 'text' | 'ignore' | 'throw';
105
- /** Fields parsed as verbatim text rather than TeX. */
106
- verbatimFields?: (string | RegExp)[];
155
+ /** Field-name glob patterns parsed as verbatim text rather than TeX (`*`, `?`, and `\\`). */
156
+ verbatimFields?: string[];
107
157
  /** Fields for which a redundant outer brace pair is removed. */
108
158
  removeOuterBraces?: string[];
109
159
  /** Override the default parsing mode for individual fields. */
@@ -115,36 +165,64 @@ export interface Options extends ParserOptions {
115
165
  }
116
166
  /** Options shared by the normalized and verbatim parsers. */
117
167
  export interface ParserOptions {
118
- /** Stop after this many entries have been parsed. */
168
+ /** Stop after this many entries have been parsed; useful for quickly checking whether text is BibTeX. */
119
169
  maxEntries?: number;
120
- /** Preload string definitions as a dictionary or BibTeX source. */
170
+ /** Preload `@string` definitions as a name-to-value map or BibTeX source text. */
121
171
  strings?: Record<string, string> | string;
122
172
  }
123
- /** An entry whose field values retain their original BibTeX text. */
173
+ /** An entry whose field values retain their BibTeX text instead of being interpreted as LaTeX. */
124
174
  export interface VerbatimEntry {
175
+ /** Source text for this entry. */
125
176
  input: string;
177
+ /** Entry type from the source. */
126
178
  type: string;
179
+ /** Citation key identifying this entry. */
127
180
  key: string;
181
+ /** Field names mapped to their text values; creator names and LaTeX are not normalized. */
128
182
  fields: Record<string, string>;
129
183
  }
130
- /** The library returned by the verbatim parser. */
184
+ /** The library returned by the verbatim parser, before normalized field parsing. */
131
185
  export interface VerbatimLibrary {
186
+ /** Successfully parsed entries, in source order. */
132
187
  entries: VerbatimEntry[];
188
+ /** Resolved values declared by `@string` directives. */
133
189
  strings: Record<string, string>;
190
+ /** Text from `@comment` directives. */
134
191
  comments: string[];
192
+ /** Diagnostics collected while parsing. */
135
193
  errors: ParseError[];
194
+ /** Values from `@preamble` directives, in source order. */
136
195
  preambles: string[];
196
+ /** JabRef metadata extracted from the library. */
137
197
  jabref: JabRefMetadata;
138
198
  }
139
199
  /** Default language identifiers treated as English. */
140
200
  export declare const english: string[];
141
- /** Parses BibTeX while leaving field contents uninterpreted. */
201
+ /**
202
+ * Parses BibTeX without converting LaTeX field contents to Unicode or structured creator values.
203
+ * `@string` references are resolved, while each entry's fields remain strings for later processing.
204
+ *
205
+ * @example
206
+ * ```ts
207
+ * const library = parseVerbatim('@article{example, title={A \\LaTeX title}}')
208
+ * const rawTitle = library.entries[0]?.fields.title
209
+ * ```
210
+ */
142
211
  export declare function parseVerbatim(input: string, options?: ParserOptions): VerbatimLibrary;
143
- /** Asynchronous variant of {@link parseVerbatim}. */
212
+ /** Asynchronous variant of {@link parseVerbatim}; yields while processing large inputs. */
144
213
  export declare function parseVerbatimAsync(input: string, options?: ParserOptions): Promise<VerbatimLibrary>;
145
- /** Parses BibTeX or BibLaTeX source into a normalized library. */
214
+ /**
215
+ * Parses BibTeX or BibLaTeX source into normalized entries and field values.
216
+ * Recoverable problems are reported in `Library.errors`; set `unsupported: 'throw'` to throw on unsupported TeX commands or environments.
217
+ *
218
+ * @example
219
+ * ```ts
220
+ * const { entries, errors } = parse('@article{example, author={Ada Lovelace}, title={A title}}')
221
+ * const title = entries[0]?.fields.title
222
+ * ```
223
+ */
146
224
  export declare function parse(input: string, options?: Options): Library;
147
- /** Asynchronous variant of {@link parse}, yielding during large parses. */
225
+ /** Asynchronous variant of {@link parse}; returns the same result shape and yields between batches for large inputs. */
148
226
  export declare function parseAsync(input: string, options?: Options): Promise<Library>;
149
227
  /** Converts a title to sentence case using heuristic token classification. */
150
228
  export declare function toSentenceCase(input: string, options?: {
@@ -152,5 +230,3 @@ export declare function toSentenceCase(input: string, options?: {
152
230
  subSentenceCapitalization?: boolean;
153
231
  guess?: boolean;
154
232
  }): string;
155
- /** Splits text into classified tokens with source offsets. */
156
- export declare function tokenize(input: string, markup?: RegExp): Token[];
@@ -1,38 +1,39 @@
1
- /** @module wasm */
2
- import init, { initSync, parse as parseWasm, parseAsync as parseAsyncWasm, parseVerbatim as parseVerbatimWasm, parseVerbatimAsync as parseVerbatimAsyncWasm, tokenize as tokenizeWasm, toSentenceCase as toSentenceCaseWasm } from './bibtex_parser.js';
1
+ /** @module @retorquere/bibtex-parser */
2
+ import init, { initSync, parse as parseWasm, parseAsync as parseAsyncWasm, parseVerbatim as parseVerbatimWasm, parseVerbatimAsync as parseVerbatimAsyncWasm, toSentenceCase as toSentenceCaseWasm } from './bibtex_parser.js';
3
3
  import { JabRefMetadata } from './jabref.js';
4
+ import englishDefaults from './english.json' with { type: 'json' };
4
5
  export { JabRefMetadata };
5
- /** Initializes the WebAssembly parser; await this before using its exports. */
6
- export { init, initSync };
6
+ /**
7
+ * Loads and initializes the WebAssembly parser asynchronously.
8
+ *
9
+ * With no argument, the browser build fetches the package's WASM file relative to this module. Pass a URL-like resource to choose another location, or pass bytes when the caller loads the binary itself. Initialize once before calling parser functions.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import init, { parse } from '@retorquere/bibtex-parser'
14
+ *
15
+ * await init()
16
+ * const library = parse('@article{example, title={A title}}')
17
+ * ```
18
+ */
19
+ export { init };
20
+ /**
21
+ * Initializes the WebAssembly parser from bytes or a compiled module without fetching it.
22
+ * Call this before any parser function; prefer {@link init} when the binary should be loaded asynchronously.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import { readFile } from 'node:fs/promises'
27
+ * import { initSync, parse } from '@retorquere/bibtex-parser'
28
+ *
29
+ * initSync({ module: await readFile('bibtex_parser_bg.wasm') })
30
+ * const library = parse('@article{example, title={A title}}')
31
+ * ```
32
+ */
33
+ export { initSync };
7
34
  export default init;
8
35
  /** Default language identifiers treated as English. */
9
- export const english = [
10
- '',
11
- 'american',
12
- 'british',
13
- 'canadian',
14
- 'english',
15
- 'australian',
16
- 'newzealand',
17
- 'usenglish',
18
- 'ukenglish',
19
- 'en',
20
- 'eng',
21
- 'en-au',
22
- 'en-bz',
23
- 'en-ca',
24
- 'en-cb',
25
- 'en-gb',
26
- 'en-ie',
27
- 'en-jm',
28
- 'en-nz',
29
- 'en-ph',
30
- 'en-tt',
31
- 'en-us',
32
- 'en-za',
33
- 'en-zw',
34
- 'anglais',
35
- ];
36
+ export const english = englishDefaults;
36
37
  function prepare(input, options = {}) {
37
38
  const parserOptions = Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined));
38
39
  if (typeof parserOptions.strings === 'string') {
@@ -42,15 +43,6 @@ function prepare(input, options = {}) {
42
43
  if (parserOptions.unsupported !== undefined && !['tex', 'text', 'ignore', 'throw'].includes(parserOptions.unsupported)) {
43
44
  throw new TypeError('unsupported must be tex, text, ignore, or throw');
44
45
  }
45
- if (Array.isArray(parserOptions.verbatimFields)) {
46
- parserOptions.verbatimFields = parserOptions.verbatimFields.map((field) => {
47
- if (typeof field === 'string')
48
- return field;
49
- const flags = `${field.multiline ? 'm' : ''}${field.dotAll ? 's' : ''}`;
50
- const source = flags ? `(?${flags}:${field.source})` : field.source;
51
- return { source: field.sticky ? `\\A(?:${source})` : source };
52
- });
53
- }
54
46
  return { input, options: parserOptions };
55
47
  }
56
48
  function throwOnUnsupported(result) {
@@ -63,17 +55,35 @@ function withJabRef(result) {
63
55
  result.jabref = new JabRefMetadata(result.jabref);
64
56
  return result;
65
57
  }
66
- /** Parses BibTeX while leaving field contents uninterpreted. */
58
+ /**
59
+ * Parses BibTeX without converting LaTeX field contents to Unicode or structured creator values.
60
+ * `@string` references are resolved, while each entry's fields remain strings for later processing.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * const library = parseVerbatim('@article{example, title={A \\LaTeX title}}')
65
+ * const rawTitle = library.entries[0]?.fields.title
66
+ * ```
67
+ */
67
68
  export function parseVerbatim(input, options = {}) {
68
69
  const prepared = prepare(input, options);
69
70
  return withJabRef(parseVerbatimWasm(prepared.input, prepared.options));
70
71
  }
71
- /** Asynchronous variant of {@link parseVerbatim}. */
72
+ /** Asynchronous variant of {@link parseVerbatim}; yields while processing large inputs. */
72
73
  export async function parseVerbatimAsync(input, options = {}) {
73
74
  const prepared = prepare(input, options);
74
75
  return withJabRef(await parseVerbatimAsyncWasm(prepared.input, prepared.options));
75
76
  }
76
- /** Parses BibTeX or BibLaTeX source into a normalized library. */
77
+ /**
78
+ * Parses BibTeX or BibLaTeX source into normalized entries and field values.
79
+ * Recoverable problems are reported in `Library.errors`; set `unsupported: 'throw'` to throw on unsupported TeX commands or environments.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * const { entries, errors } = parse('@article{example, author={Ada Lovelace}, title={A title}}')
84
+ * const title = entries[0]?.fields.title
85
+ * ```
86
+ */
77
87
  export function parse(input, options = {}) {
78
88
  const prepared = prepare(input, options);
79
89
  const result = withJabRef(parseWasm(prepared.input, prepared.options));
@@ -81,7 +91,7 @@ export function parse(input, options = {}) {
81
91
  return throwOnUnsupported(result);
82
92
  return result;
83
93
  }
84
- /** Asynchronous variant of {@link parse}, yielding during large parses. */
94
+ /** Asynchronous variant of {@link parse}; returns the same result shape and yields between batches for large inputs. */
85
95
  export async function parseAsync(input, options = {}) {
86
96
  const prepared = prepare(input, options);
87
97
  const result = withJabRef(await parseAsyncWasm(prepared.input, prepared.options));
@@ -93,10 +103,3 @@ export async function parseAsync(input, options = {}) {
93
103
  export function toSentenceCase(input, options = {}) {
94
104
  return toSentenceCaseWasm(input, options);
95
105
  }
96
- /** Splits text into classified tokens with source offsets. */
97
- export function tokenize(input, markup) {
98
- if (!(markup instanceof RegExp))
99
- return tokenizeWasm(input);
100
- const masked = input.replace(markup, match => '\u2060'.repeat(match.length));
101
- return tokenizeWasm(masked);
102
- }
@@ -2,37 +2,25 @@
2
2
  * A JabRef group.
3
3
  */
4
4
  export interface Group {
5
- /**
6
- * the group name
7
- */
5
+ /** Name displayed for this group in JabRef. */
8
6
  name: string;
9
- /**
10
- * The citation keys which are specified to belong to this group, after intersection calculation has been applied
11
- */
7
+ /** Citation keys belonging to this group after supported group rules are applied. */
12
8
  entries: string[];
13
- /**
14
- * Sub-groups under this group
15
- */
9
+ /** Direct child groups. */
16
10
  groups: Group[];
17
11
  }
12
+ /** JabRef metadata parsed from a BibTeX library, including its group tree and file settings. */
18
13
  export declare class JabRefMetadata {
19
14
  #private;
20
- /**
21
- * The root groups. You can find the nested groups in their `groups` property
22
- */
15
+ /** Top-level groups; nested groups are available through each group's `groups` property. */
23
16
  root: Group[];
24
- /**
25
- * The base path for file paths
26
- */
17
+ /** Base directory used to resolve relative attachment paths. */
27
18
  fileDirectory?: string;
28
- /**
29
- * The JabRef metadata format version
30
- */
19
+ /** JabRef group metadata format version. */
31
20
  groupsversion?: number;
32
- /**
33
- * The JabRef metadata database type
34
- */
21
+ /** Database type recorded in the JabRef metadata. */
35
22
  databaseType?: string;
23
+ /** Creates metadata from parsed JabRef properties and indexes groups for membership updates. */
36
24
  constructor(data?: Partial<Pick<JabRefMetadata, 'root' | 'fileDirectory' | 'groupsversion' | 'databaseType'>>);
37
25
  /** Populates JabRef 3.8+ memberships in `root` by group name; duplicate names select the first node. */
38
26
  addEntry(name: string, key: string): boolean;
@@ -18,12 +18,12 @@ function decode(s = '', sep = ';') {
18
18
  }
19
19
  return records.reverse().filter(record => record);
20
20
  }
21
+ /** JabRef metadata parsed from a BibTeX library, including its group tree and file settings. */
21
22
  export class JabRefMetadata {
22
23
  #groups = new Map();
23
- /**
24
- * The root groups. You can find the nested groups in their `groups` property
25
- */
24
+ /** Top-level groups; nested groups are available through each group's `groups` property. */
26
25
  root = [];
26
+ /** Creates metadata from parsed JabRef properties and indexes groups for membership updates. */
27
27
  constructor(data = {}) {
28
28
  this.root = data.root ?? [];
29
29
  for (const field of ['fileDirectory', 'groupsversion', 'databaseType']) {