@retorquere/bibtex-parser 12.1.2 → 12.1.4
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/README.md +12 -0
- package/dist/cjs/index.js +22 -5
- package/dist/cjs/index.js.map +3 -3
- package/dist/esm/index.js +22 -5
- package/dist/esm/index.js.map +3 -3
- package/dist/types/index.d.ts +19 -7
- package/dist/types/index.d.ts.map +1 -1
- package/dist/wasm/bibtex_parser.d.ts +11 -2
- package/dist/wasm/bibtex_parser.js +151 -6
- package/dist/wasm/bibtex_parser_bg.wasm +0 -0
- package/dist/wasm/bibtex_parser_bg.wasm.d.ts +6 -1
- package/dist/wasm/index.d.ts +119 -99
- package/dist/wasm/index.js +86 -109
- package/dist/wasm/snippets/rq-bibtex-parser-a708c588fcf0dba5/inline0.js +1 -0
- package/package.json +14 -10
package/dist/wasm/index.js
CHANGED
|
@@ -1,122 +1,99 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return rust
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function library(result) {
|
|
60
|
-
if (Array.isArray(result.preambles)) {
|
|
61
|
-
result.preamble = result.preambles
|
|
62
|
-
delete result.preambles
|
|
63
|
-
}
|
|
64
|
-
return result
|
|
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';
|
|
3
|
+
/** Initializes the WebAssembly parser; await this before using its exports. */
|
|
4
|
+
export { init, initSync };
|
|
5
|
+
export default init;
|
|
6
|
+
/** Default language identifiers treated as English. */
|
|
7
|
+
export const english = [
|
|
8
|
+
'',
|
|
9
|
+
'american',
|
|
10
|
+
'british',
|
|
11
|
+
'canadian',
|
|
12
|
+
'english',
|
|
13
|
+
'australian',
|
|
14
|
+
'newzealand',
|
|
15
|
+
'usenglish',
|
|
16
|
+
'ukenglish',
|
|
17
|
+
'en',
|
|
18
|
+
'eng',
|
|
19
|
+
'en-au',
|
|
20
|
+
'en-bz',
|
|
21
|
+
'en-ca',
|
|
22
|
+
'en-cb',
|
|
23
|
+
'en-gb',
|
|
24
|
+
'en-ie',
|
|
25
|
+
'en-jm',
|
|
26
|
+
'en-nz',
|
|
27
|
+
'en-ph',
|
|
28
|
+
'en-tt',
|
|
29
|
+
'en-us',
|
|
30
|
+
'en-za',
|
|
31
|
+
'en-zw',
|
|
32
|
+
'anglais',
|
|
33
|
+
];
|
|
34
|
+
function prepare(input, options = {}) {
|
|
35
|
+
const parserOptions = Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined));
|
|
36
|
+
if (typeof parserOptions.strings === 'string') {
|
|
37
|
+
input = `${parserOptions.strings}\n${input}`;
|
|
38
|
+
delete parserOptions.strings;
|
|
39
|
+
}
|
|
40
|
+
if (parserOptions.unsupported && !['ignore', 'keep', 'throw'].includes(parserOptions.unsupported)) {
|
|
41
|
+
throw new TypeError('unsupported must be ignore, keep, or throw');
|
|
42
|
+
}
|
|
43
|
+
if (parserOptions.unsupported === 'ignore')
|
|
44
|
+
parserOptions.ignoreUnsupported = true;
|
|
45
|
+
delete parserOptions.unsupported;
|
|
46
|
+
if (Array.isArray(parserOptions.verbatimFields)) {
|
|
47
|
+
parserOptions.verbatimFields = parserOptions.verbatimFields.map((field) => {
|
|
48
|
+
if (typeof field === 'string')
|
|
49
|
+
return field;
|
|
50
|
+
const flags = `${field.multiline ? 'm' : ''}${field.dotAll ? 's' : ''}`;
|
|
51
|
+
const source = flags ? `(?${flags}:${field.source})` : field.source;
|
|
52
|
+
return { source: field.sticky ? `\\A(?:${source})` : source };
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return { input, options: parserOptions };
|
|
65
56
|
}
|
|
66
|
-
|
|
67
57
|
function throwOnUnsupported(result) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
58
|
+
const unsupported = result.errors.find(error => error.error.startsWith('unhandled macro ') || error.error.startsWith('unhandled environment '));
|
|
59
|
+
if (unsupported)
|
|
60
|
+
throw new Error(unsupported.error);
|
|
61
|
+
return result;
|
|
71
62
|
}
|
|
72
|
-
|
|
63
|
+
/** Parses BibTeX while leaving field contents uninterpreted. */
|
|
73
64
|
export function parseVerbatim(input, options = {}) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return result
|
|
65
|
+
const prepared = prepare(input, options);
|
|
66
|
+
return parseVerbatimWasm(prepared.input, prepared.options);
|
|
77
67
|
}
|
|
78
|
-
|
|
79
|
-
export function
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
let normalizedOptions = options
|
|
83
|
-
if (patterns.length) {
|
|
84
|
-
const exactFields = new Set(selectors.filter(selector => typeof selector === 'string'))
|
|
85
|
-
const raw = parseVerbatimWasm(input, rustOptions({
|
|
86
|
-
...options,
|
|
87
|
-
verbatimFields: [...exactFields],
|
|
88
|
-
}))
|
|
89
|
-
for (const entry of raw.entries) {
|
|
90
|
-
for (const field of Object.keys(entry.fields)) {
|
|
91
|
-
if (patterns.some(pattern => field.match(new RegExp(
|
|
92
|
-
pattern.source,
|
|
93
|
-
pattern.flags.includes('i') ? pattern.flags : `${pattern.flags}i`,
|
|
94
|
-
)))) {
|
|
95
|
-
exactFields.add(field)
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
normalizedOptions = { ...options, verbatimFields: [...exactFields] }
|
|
100
|
-
}
|
|
101
|
-
const result = library(parseNormalizedWasm(input, rustOptions(normalizedOptions)))
|
|
102
|
-
if (options.unsupported === 'throw') return throwOnUnsupported(result)
|
|
103
|
-
return result
|
|
68
|
+
/** Asynchronous variant of {@link parseVerbatim}. */
|
|
69
|
+
export async function parseVerbatimAsync(input, options = {}) {
|
|
70
|
+
const prepared = prepare(input, options);
|
|
71
|
+
return await parseVerbatimAsyncWasm(prepared.input, prepared.options);
|
|
104
72
|
}
|
|
105
|
-
|
|
73
|
+
/** Parses BibTeX or BibLaTeX source into a normalized library. */
|
|
106
74
|
export function parse(input, options = {}) {
|
|
107
|
-
|
|
75
|
+
const prepared = prepare(input, options);
|
|
76
|
+
const result = parseWasm(prepared.input, prepared.options);
|
|
77
|
+
if (options.unsupported === 'throw')
|
|
78
|
+
return throwOnUnsupported(result);
|
|
79
|
+
return result;
|
|
108
80
|
}
|
|
109
|
-
|
|
81
|
+
/** Asynchronous variant of {@link parse}, yielding during large parses. */
|
|
110
82
|
export async function parseAsync(input, options = {}) {
|
|
111
|
-
|
|
83
|
+
const prepared = prepare(input, options);
|
|
84
|
+
const result = await parseAsyncWasm(prepared.input, prepared.options);
|
|
85
|
+
if (options.unsupported === 'throw')
|
|
86
|
+
return throwOnUnsupported(result);
|
|
87
|
+
return result;
|
|
112
88
|
}
|
|
113
|
-
|
|
89
|
+
/** Converts a title to sentence case using heuristic token classification. */
|
|
114
90
|
export function toSentenceCase(input, options = {}) {
|
|
115
|
-
|
|
91
|
+
return toSentenceCaseWasm(input, options);
|
|
116
92
|
}
|
|
117
|
-
|
|
93
|
+
/** Splits text into classified tokens with source offsets. */
|
|
118
94
|
export function tokenize(input, markup) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
95
|
+
if (!(markup instanceof RegExp))
|
|
96
|
+
return tokenizeWasm(input);
|
|
97
|
+
const masked = input.replace(markup, match => '\u2060'.repeat(match.length));
|
|
98
|
+
return tokenizeWasm(masked);
|
|
99
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function playnice() { return new Promise(resolve => setTimeout(resolve, 0)); }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@retorquere/bibtex-parser",
|
|
3
|
-
"version": "12.1.
|
|
3
|
+
"version": "12.1.4",
|
|
4
4
|
"description": "BibTeX parser",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"postversion": "git push --follow-tags",
|
|
48
48
|
"update-cases": "curl -s https://raw.githubusercontent.com/retorquere/zotero-better-bibtex/master/test/loaded.json | jq -r '.[] | select(test(\"\\\\.bib((la)?tex)?$\"))' | rsync -av --delete -m --files-from=- ../better-bibtex/test/fixtures/ test/better-bibtex/",
|
|
49
49
|
"predocs": "npm start",
|
|
50
|
-
"docs": "typedoc --tsconfig tsconfig.
|
|
50
|
+
"docs": "typedoc --tsconfig tsconfig.typedoc.json",
|
|
51
51
|
"modules": "git submodule update --init --recursive",
|
|
52
52
|
"wasm:test": "npm run build:wasm && node --test test/wasm.js test/rust-wasm-parity.test.js",
|
|
53
53
|
"ncu": "./build/submodules.py && ./build/crossref.py && ncu -u && npm i && git add package.json package-lock.json && npm audit fix && git commit -m ncu"
|
|
@@ -62,22 +62,22 @@
|
|
|
62
62
|
"author": "Emiliano Heyns",
|
|
63
63
|
"license": "ISC",
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@types/node": "^26.
|
|
65
|
+
"@types/node": "^26.6.5",
|
|
66
66
|
"@unified-latex/unified-latex-types": "^1.8.4",
|
|
67
67
|
"command-line-args": "^6.0.2",
|
|
68
|
-
"csv": "^6.6.
|
|
68
|
+
"csv": "^6.6.4",
|
|
69
69
|
"digital-tree": "^2.0.4",
|
|
70
|
-
"dprint": "^0.
|
|
71
|
-
"ejs": "^
|
|
70
|
+
"dprint": "^0.63.0",
|
|
71
|
+
"ejs": "^7.0.1",
|
|
72
72
|
"esbuild": "^0.28.2",
|
|
73
73
|
"glob": "^13.0.6",
|
|
74
|
-
"js-yaml": "^5.
|
|
74
|
+
"js-yaml": "^5.4.3",
|
|
75
75
|
"minimist": "^1.2.8",
|
|
76
76
|
"mkdirp": "^3.0.1",
|
|
77
77
|
"node-fetch": "^3.3.2",
|
|
78
|
-
"piscina": "^5.3.
|
|
78
|
+
"piscina": "^5.3.2",
|
|
79
79
|
"slug": "^12.0.1",
|
|
80
|
-
"tap": "^21.
|
|
80
|
+
"tap": "^21.8.0",
|
|
81
81
|
"ts-node": "^10.9.2",
|
|
82
82
|
"tslib": "^2.8.1",
|
|
83
83
|
"typedoc": "^0.28.20",
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"lodash.merge": "^4.6.2",
|
|
93
93
|
"moo": "^0.5.3",
|
|
94
94
|
"nearley": "^2.20.1",
|
|
95
|
-
"unicode2latex": "^7.0.
|
|
95
|
+
"unicode2latex": "^7.0.37",
|
|
96
96
|
"wink-eng-lite-web-model": "^1.8.1",
|
|
97
97
|
"wink-nlp": "^2.4.0"
|
|
98
98
|
},
|
|
@@ -103,5 +103,9 @@
|
|
|
103
103
|
],
|
|
104
104
|
"publishConfig": {
|
|
105
105
|
"access": "public"
|
|
106
|
+
},
|
|
107
|
+
"allowScripts": {
|
|
108
|
+
"esbuild@0.28.2": true,
|
|
109
|
+
"dprint@0.63.0": true
|
|
106
110
|
}
|
|
107
111
|
}
|