@retorquere/bibtex-parser 6.4.14 → 6.4.17

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 (3) hide show
  1. package/index.d.ts +1 -1
  2. package/index.js +4 -98
  3. package/package.json +16 -16
package/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import * as bibtex from './grammar';
2
2
  import * as chunker from './chunker';
3
3
  import * as jabref from './jabref';
4
4
  import { JabRefMetadata } from './jabref';
5
- export declare function toSentenceCase(text: string, ignoreHTML?: boolean): string;
5
+ export { toSentenceCase } from './sentence-case';
6
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
7
  export interface Name {
8
8
  /**
package/index.js CHANGED
@@ -37,103 +37,9 @@ const jabref_1 = require("./jabref");
37
37
  const unicode2latex_1 = require("unicode2latex");
38
38
  const crossref_json_1 = __importDefault(require("./crossref.json"));
39
39
  const fields_json_1 = __importDefault(require("./fields.json"));
40
- const xregexp_1 = __importDefault(require("xregexp"));
41
- function restore(text, orig, preserve) {
42
- for (const { start, end } of preserve) {
43
- text = text.substring(0, start) + orig.substring(start, end) + text.substring(end);
44
- }
45
- return text;
46
- }
47
- class SentenceCaser {
48
- constructor() {
49
- this.acronym = (0, xregexp_1.default)('^(\\p{Lu}[.])+(?=$|[\\P{L}])');
50
- this.quoted = (0, xregexp_1.default)('^"[^"]+"(?=$|[\\P{L}])');
51
- this.innerCaps = (0, xregexp_1.default)('\\p{Ll}\\p{Lu}');
52
- this.allCaps = (0, xregexp_1.default)('^\\p{Lu}+$');
53
- this.aint = (0, xregexp_1.default)("^\\p{L}n't(?=$|[\\P{L}])"); // isn't
54
- this.word = (0, xregexp_1.default)('^\\p{L}+(-\\p{L}+)*'); // also match gallium-nitride as one word
55
- this.and = (0, xregexp_1.default)('^\\p{Lu}&\\p{Lu}(?=$|[\\P{L}])'); // Q&A
56
- }
57
- convert(text, ignoreHTML = false) {
58
- this.input = text;
59
- this.result = '';
60
- this.sentenceStart = true;
61
- const preserve = [];
62
- if (ignoreHTML) {
63
- let replace = true;
64
- while (replace) {
65
- replace = false;
66
- // always keep the leading char, but skip markup
67
- this.input = this.input.replace(/[^<>]<[^>]+>/, (match, i) => {
68
- preserve.push({ start: i + 1, end: i + match.length });
69
- replace = true;
70
- return match[0].repeat(match.length);
71
- });
72
- }
73
- replace = true;
74
- while (replace) {
75
- replace = false;
76
- // always keep the leading char, but skip markup
77
- this.input = this.input.replace(/<[^>]+>[^<>]/, (match, i) => {
78
- preserve.push({ start: i, end: i + match.length - 1 });
79
- replace = true;
80
- return match[match.length - 1].repeat(match.length);
81
- });
82
- }
83
- }
84
- this.input = this.input.replace(/[;:]\s+A\s/g, match => match.toLowerCase());
85
- this.input = this.input.replace(/[–—]\s*A\s/g, match => match.toLowerCase());
86
- let m;
87
- while (this.input) {
88
- if (m = xregexp_1.default.exec(this.input, this.quoted)) { // "Hello There"
89
- this.add(m[0], undefined, true);
90
- }
91
- else if (m = xregexp_1.default.exec(this.input, this.acronym)) { // U.S.
92
- this.add(m[0], undefined, true);
93
- }
94
- else if (m = xregexp_1.default.exec(this.input, this.aint)) { // isn't
95
- this.add(m[0], undefined, false);
96
- }
97
- else if (m = xregexp_1.default.exec(this.input, this.word)) {
98
- this.add(m[0], '-', false);
99
- }
100
- else if (m = xregexp_1.default.exec(this.input, this.and)) {
101
- this.add(m[0], undefined, true);
102
- }
103
- else {
104
- this.add(this.input[0], undefined, false);
105
- }
106
- }
107
- return restore(this.result, text, preserve);
108
- }
109
- add(word, splitter, keep) {
110
- if (splitter) {
111
- word = word.split(splitter).map((part, i) => {
112
- if ((keep || this.sentenceStart) && i === 0)
113
- return part;
114
- if (xregexp_1.default.exec(part, this.innerCaps))
115
- return part;
116
- if (xregexp_1.default.exec(part, this.allCaps))
117
- return part;
118
- return part.toLowerCase();
119
- }).join(splitter);
120
- }
121
- else {
122
- if (!keep)
123
- word = word.toLowerCase();
124
- }
125
- this.result += word;
126
- this.input = this.input.substr(word.length);
127
- if (!word.match(/^\s+$/)) {
128
- this.sentenceStart = !!word.match(/^[.?!]$/) || (word.length === 2 && word[1] === '.'); // Vitamin A. Vitamin B.
129
- }
130
- }
131
- }
132
- const sentenceCaser = new SentenceCaser;
133
- function toSentenceCase(text, ignoreHTML = false) {
134
- return sentenceCaser.convert(text, ignoreHTML);
135
- }
136
- exports.toSentenceCase = toSentenceCase;
40
+ var sentence_case_1 = require("./sentence-case");
41
+ Object.defineProperty(exports, "toSentenceCase", { enumerable: true, get: function () { return sentence_case_1.toSentenceCase; } });
42
+ const sentence_case_2 = require("./sentence-case");
137
43
  class ParserError extends Error {
138
44
  constructor(message, node) {
139
45
  super(message); // 'Error' breaks prototype chain here
@@ -1451,7 +1357,7 @@ class Parser {
1451
1357
  convertToSentenceCase(text) {
1452
1358
  if (!this.field.preserveRanges)
1453
1359
  return text;
1454
- const sentenceCased = restore(sentenceCaser.convert(text, true), text, this.field.preserveRanges);
1360
+ const sentenceCased = (0, sentence_case_2.restore)((0, sentence_case_2.toSentenceCase)(text, true), text, this.field.preserveRanges);
1455
1361
  if (text !== sentenceCased)
1456
1362
  this.entry.sentenceCased = true;
1457
1363
  return sentenceCased;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retorquere/bibtex-parser",
3
- "version": "6.4.14",
3
+ "version": "6.4.17",
4
4
  "description": "BibTeX parser",
5
5
  "main": "index.js",
6
6
  "typings": "./index.d.ts",
@@ -36,28 +36,28 @@
36
36
  "author": "Emiliano Heyns",
37
37
  "license": "ISC",
38
38
  "devDependencies": {
39
- "@microsoft/api-documenter": "^7.22.3",
40
- "@microsoft/api-extractor": "^7.34.7",
41
- "@types/node": "^18.16.3",
42
- "@typescript-eslint/eslint-plugin": "^5.59.2",
43
- "@typescript-eslint/parser": "^5.59.2",
39
+ "@microsoft/api-documenter": "^7.22.32",
40
+ "@microsoft/api-extractor": "^7.36.3",
41
+ "@types/node": "^20.4.8",
42
+ "@typescript-eslint/eslint-plugin": "^6.2.1",
43
+ "@typescript-eslint/parser": "^6.2.1",
44
44
  "command-line-args": "^5.2.1",
45
- "csv": "^6.2.11",
45
+ "csv": "^6.3.1",
46
46
  "digital-tree": "^2.0.4",
47
47
  "ejs": "^3.1.9",
48
- "eslint": "^8.39.0",
49
- "eslint-plugin-import": "^2.27.5",
48
+ "eslint": "^8.46.0",
49
+ "eslint-plugin-import": "^2.28.0",
50
50
  "eslint-plugin-prefer-arrow": "^1.2.3",
51
- "glob": "^10.2.2",
51
+ "glob": "^10.3.3",
52
52
  "mkdirp": "^3.0.1",
53
- "node-fetch": "^3.3.1",
53
+ "node-fetch": "^3.3.2",
54
54
  "peggy": "^3.0.2",
55
- "piscina": "^3.2.0",
56
- "slug": "^8.2.2",
57
- "tap": "^16.3.4",
55
+ "piscina": "^4.1.0",
56
+ "slug": "^8.2.3",
57
+ "tap": "^16.3.8",
58
58
  "ts-node": "^10.9.1",
59
- "tslib": "^2.5.0",
60
- "typescript": "^5.0.4"
59
+ "tslib": "^2.6.1",
60
+ "typescript": "^5.1.6"
61
61
  },
62
62
  "dependencies": {
63
63
  "unicode2latex": "^3.0.3",