@retorquere/bibtex-parser 6.4.2 → 6.4.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/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import * as bibtex from './grammar';
2
+ import * as chunker from './chunker';
3
+ import * as jabref from './jabref';
2
4
  import { JabRefMetadata } from './jabref';
3
5
  export declare function toSentenceCase(text: string, ignoreHTML?: boolean): string;
4
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;
@@ -208,7 +210,7 @@ export interface ParserOptions {
208
210
  */
209
211
  caseProtection?: 'as-needed' | 'strict' | boolean;
210
212
  /**
211
- * 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
213
+ * 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
212
214
  */
213
215
  markup?: MarkupMapping;
214
216
  /**
@@ -264,5 +266,6 @@ export declare function ast(input: string, options?: ParserOptions, clean?: bool
264
266
  export declare const promises: {
265
267
  parse(input: string, options?: ParserOptions): Promise<Bibliography>;
266
268
  };
267
- export * as chunker from './chunker';
268
- export * as jabref from './jabref';
269
+ export { chunker };
270
+ export { jabref };
271
+ //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -5,9 +5,13 @@ const tslib_1 = require("tslib");
5
5
  /* eslint-disable @typescript-eslint/no-unsafe-argument */
6
6
  const bibtex = tslib_1.__importStar(require("./grammar"));
7
7
  const chunker = tslib_1.__importStar(require("./chunker"));
8
+ exports.chunker = chunker;
9
+ const jabref = tslib_1.__importStar(require("./jabref"));
10
+ exports.jabref = jabref;
8
11
  const jabref_1 = require("./jabref");
9
12
  const unicode2latex_1 = require("unicode2latex");
10
13
  const crossref_json_1 = tslib_1.__importDefault(require("./crossref.json"));
14
+ const fields_json_1 = tslib_1.__importDefault(require("./fields.json"));
11
15
  const xregexp_1 = tslib_1.__importDefault(require("xregexp"));
12
16
  function restore(text, orig, preserve) {
13
17
  for (const { start, end } of preserve) {
@@ -383,6 +387,42 @@ class Parser {
383
387
  }
384
388
  return this.parsed();
385
389
  }
390
+ applyField(parent, parentfield, child, childfield) {
391
+ let applied = false;
392
+ for (const field of ['fields', 'creators']) {
393
+ if (!child[field][childfield] && parent[field][parentfield]) {
394
+ child[field][childfield] = parent[field][parentfield];
395
+ applied = true;
396
+ }
397
+ }
398
+ return applied;
399
+ }
400
+ applyCrossref(entry, entries) {
401
+ for (const xref of ['crossref', 'xdata']) {
402
+ if (!entry.fields[xref])
403
+ continue;
404
+ for (const parents of entry.fields[xref]) {
405
+ let applied = false;
406
+ for (const parent of parents.split(/\s*,\s*/).map(key => entries[key]).filter(p => p)) {
407
+ this.applyCrossref(parent, entries);
408
+ for (const mappings of [crossref_json_1.default[entry.type], crossref_json_1.default['*']].filter(m => m)) {
409
+ for (const mapping of [mappings[parent.type], mappings['*']].filter(m => m)) {
410
+ for (const [target, source] of Object.entries(mapping)) {
411
+ if (this.applyField(parent, source, entry, target))
412
+ applied = true;
413
+ }
414
+ for (const field of (fields_json_1.default[entry.type] || [])) {
415
+ if (this.applyField(parent, field, entry, field))
416
+ applied = true;
417
+ }
418
+ }
419
+ }
420
+ }
421
+ if (applied)
422
+ delete entry.fields[xref];
423
+ }
424
+ }
425
+ }
386
426
  parsed() {
387
427
  this.field = null;
388
428
  const strings = {};
@@ -408,22 +448,10 @@ class Parser {
408
448
  return acc;
409
449
  }, {});
410
450
  for (const entry of this.entries) {
411
- if (entry.fields.crossref) {
412
- for (const parent_key of entry.fields.crossref) {
413
- const parent = entries[parent_key];
414
- const mapping = parent && crossref_json_1.default.find(xref => xref.source.includes(parent.type) && xref.target.includes(entry.type));
415
- if (parent && mapping) {
416
- for (const { source, target } of mapping.fields) {
417
- if (parent.fields[source] && !entry.fields[target]) {
418
- entry.fields[target] = JSON.parse(JSON.stringify(parent.fields[source]));
419
- }
420
- }
421
- }
422
- }
423
- }
451
+ this.applyCrossref(entry, entries);
424
452
  }
425
453
  }
426
- const { comments, jabref } = (0, jabref_1.parse)(this.comments);
454
+ const { comments, jabref } = (0, jabref_1.parse)(this.comments); // eslint-disable-line @typescript-eslint/no-shadow
427
455
  return {
428
456
  errors: this.errors,
429
457
  entries: this.entries,
@@ -1538,6 +1566,4 @@ exports.promises = {
1538
1566
  return await parser.parseAsync(input);
1539
1567
  },
1540
1568
  };
1541
- exports.chunker = tslib_1.__importStar(require("./chunker"));
1542
- exports.jabref = tslib_1.__importStar(require("./jabref"));
1543
1569
  //# sourceMappingURL=index.js.map
package/jabref.d.ts CHANGED
@@ -55,3 +55,4 @@ export declare function parse(comments: string[]): {
55
55
  comments: string[];
56
56
  jabref: JabRefMetadata;
57
57
  };
58
+ //# sourceMappingURL=jabref.d.ts.map
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@retorquere/bibtex-parser",
3
- "version": "6.4.2",
3
+ "version": "6.4.4",
4
4
  "description": "BibTeX parser",
5
5
  "main": "index.js",
6
+ "typings": "./index.d.ts",
6
7
  "scripts": {
7
8
  "lint": "eslint . --ext .ts --cache --cache-location .eslintcache/",
8
9
  "prestart": "npm run lint && peggy grammar.peggy",
@@ -12,15 +13,18 @@
12
13
  "test": "tap test/tap --no-timeout --no-coverage",
13
14
  "snap": "npm test --snapshot",
14
15
  "snap:big": "npm test --snapshot --big",
15
- "minitest": "peggy grammar.peggy && tsc -d && node i.js",
16
+ "minitest": "peggy grammar.peggy && ./build/crossref.py && tsc -d && node i.js",
16
17
  "list": "tar tvf $(npm pack)",
17
18
  "prepublishOnly": "npm start",
18
19
  "abbr": "./build/abbr.py",
19
20
  "preversion": "npm test && npm run abbr",
20
21
  "postversion": "git push --follow-tags",
21
22
  "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/",
22
- "docs": "rm -rf docs && typedoc --name 'BibTeX parser' index.ts && touch docs/.nojekyll",
23
- "ncu": "./build/submodules.py && ncu -u && npm i && git add package.json package-lock.json && npm audit fix && git commit -m ncu"
23
+ "x-docs": "rm -rf docs temp && typedoc --name 'BibTeX parser' index.ts && touch docs/.nojekyll",
24
+ "docs": "mkdir -p etc temp && npm run api-extractor && npm run api-documenter",
25
+ "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",
26
+ "api-documenter": "api-documenter markdown --input temp --output docs",
27
+ "api-extractor": "api-extractor run --local --verbose"
24
28
  },
25
29
  "repository": {
26
30
  "type": "git",
@@ -32,15 +36,17 @@
32
36
  "author": "Emiliano Heyns",
33
37
  "license": "ISC",
34
38
  "devDependencies": {
39
+ "@microsoft/api-documenter": "^7.19.27",
40
+ "@microsoft/api-extractor": "^7.33.7",
35
41
  "@types/node": "^18.11.18",
36
- "@typescript-eslint/eslint-plugin": "^5.48.0",
37
- "@typescript-eslint/parser": "^5.48.0",
42
+ "@typescript-eslint/eslint-plugin": "^5.48.1",
43
+ "@typescript-eslint/parser": "^5.48.1",
38
44
  "command-line-args": "^5.2.1",
39
45
  "csv": "^6.2.5",
40
46
  "digital-tree": "^2.0.4",
41
47
  "ejs": "^3.1.8",
42
48
  "eslint": "^8.31.0",
43
- "eslint-plugin-import": "^2.26.0",
49
+ "eslint-plugin-import": "^2.27.4",
44
50
  "eslint-plugin-prefer-arrow": "^1.2.3",
45
51
  "glob": "^8.0.3",
46
52
  "mkdirp": "^1.0.4",
@@ -48,10 +54,9 @@
48
54
  "peggy": "^2.0.1",
49
55
  "piscina": "^3.2.0",
50
56
  "slug": "^8.2.2",
51
- "tap": "^16.3.2",
57
+ "tap": "^16.3.3",
52
58
  "ts-node": "^10.9.1",
53
59
  "tslib": "^2.4.1",
54
- "typedoc": "^0.23.23",
55
60
  "typescript": "^4.9.4"
56
61
  },
57
62
  "dependencies": {
@@ -70,6 +75,7 @@
70
75
  "jabref.js",
71
76
  "README.md",
72
77
  "crossref.json",
78
+ "fields.json",
73
79
  "strings.bib",
74
80
  "unabbrev.json"
75
81
  ],