@retorquere/bibtex-parser 7.0.0 → 7.0.3

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.js CHANGED
@@ -1330,10 +1330,14 @@ class Parser {
1330
1330
  }
1331
1331
  else {
1332
1332
  if (this.field.preserveRanges) {
1333
- if (this.options.guessAlreadySentenceCased && Math.max(this.field.words.upper, this.field.words.lower) > (this.field.words.other + Math.min(this.field.words.upper, this.field.words.lower))) {
1333
+ const allCaps = this.field.text.match(/\s/) && this.field.words.upper && !this.field.words.lower && !this.field.words.other;
1334
+ const seemsSentenceCased = Math.max(this.field.words.upper, this.field.words.lower) > (this.field.words.other + Math.min(this.field.words.upper, this.field.words.lower));
1335
+ if (!allCaps && seemsSentenceCased && this.options.guessAlreadySentenceCased) {
1334
1336
  this.preserve(null, null); // , 'mostly sentence cased already')
1335
1337
  }
1336
1338
  else {
1339
+ if (allCaps)
1340
+ this.field.preserveRanges = [];
1337
1341
  const txt = this.field.text.replace(preserveCase.markup, markup => marker.markup.repeat(markup.length));
1338
1342
  let match;
1339
1343
  preserveCase.sentenceStart.lastIndex = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retorquere/bibtex-parser",
3
- "version": "7.0.0",
3
+ "version": "7.0.3",
4
4
  "description": "BibTeX parser",
5
5
  "main": "index.js",
6
6
  "typings": "./index.d.ts",
@@ -37,11 +37,11 @@
37
37
  "author": "Emiliano Heyns",
38
38
  "license": "ISC",
39
39
  "devDependencies": {
40
- "@microsoft/api-documenter": "^7.22.32",
41
- "@microsoft/api-extractor": "^7.36.3",
42
- "@types/node": "^20.4.8",
43
- "@typescript-eslint/eslint-plugin": "^6.2.1",
44
- "@typescript-eslint/parser": "^6.2.1",
40
+ "@microsoft/api-documenter": "^7.22.33",
41
+ "@microsoft/api-extractor": "^7.36.4",
42
+ "@types/node": "^20.4.9",
43
+ "@typescript-eslint/eslint-plugin": "^6.3.0",
44
+ "@typescript-eslint/parser": "^6.3.0",
45
45
  "command-line-args": "^5.2.1",
46
46
  "csv": "^6.3.1",
47
47
  "digital-tree": "^2.0.4",
package/sentence-case.js CHANGED
@@ -22,10 +22,14 @@ const re = {
22
22
  // private aint = XRegExp("^\\p{L}n't(?=$|[\\P{L}])") // isn't
23
23
  // private word = XRegExp('^\\p{L}+([-.]\\p{L}+)*') // also match gallium-nitride as one word
24
24
  // private and = XRegExp('^\\p{Lu}&\\p{Lu}(?=$|[\\P{L}])') // Q&A
25
+ subSentenceStart: new RegExp(`([.?!][\\s]+)(<[^>]+>)?([${Lu}])`, 'g'),
26
+ sentenceStart: new RegExp(`^(<[^>]+>)?([${Lu}])`, 'g'),
25
27
  };
26
- function lowercase(word) {
28
+ function lowercase(word, allcaps) {
27
29
  if (!word)
28
30
  return word;
31
+ if (allcaps)
32
+ return word.toLowerCase();
29
33
  const unmasked = word.replace(/\uFFFD/g, '');
30
34
  if (unmasked.match(re.skipWords))
31
35
  return word.toLowerCase();
@@ -41,14 +45,15 @@ function lowercase(word) {
41
45
  return word.toLowerCase();
42
46
  }
43
47
  function toSentenceCase(sentence, preserveQuoted = false) {
48
+ const allcaps = sentence === sentence.toUpperCase();
44
49
  const preserve = [];
45
- sentence.replace(/([.?!][\s]+)(<[^>]+>)?([A-Z])/g, (match, end, markup, char, i) => {
50
+ sentence.replace(re.subSentenceStart, (match, end, markup, char, i) => {
46
51
  if (!sentence.substring(0, i + 1).match(re.acronym)) {
47
52
  preserve.push({ pos: i + end.length + ((markup === null || markup === void 0 ? void 0 : markup.length) || 0), text: char, description: 'sub-sentence-start' });
48
53
  }
49
54
  return '';
50
55
  });
51
- sentence.replace(/^(<[^>]+>)?([A-Z])/, (match, markup, char) => {
56
+ sentence.replace(re.sentenceStart, (match, markup, char) => {
52
57
  preserve.push({ pos: ((markup === null || markup === void 0 ? void 0 : markup.length) || 0), text: char, description: 'sentence-start' });
53
58
  return '';
54
59
  });
@@ -74,7 +79,7 @@ function toSentenceCase(sentence, preserveQuoted = false) {
74
79
  masked = masked
75
80
  .replace(/[;:]\uFFFD*\s+\uFFFD*A\s/g, match => match.toLowerCase())
76
81
  .replace(/[–—]\uFFFD*\s*\uFFFD*A\s/g, match => match.toLowerCase())
77
- .replace(re.words, word => lowercase(word));
82
+ .replace(re.words, word => lowercase(word, allcaps));
78
83
  sentence = masked;
79
84
  for (const { pos, text } of preserve) {
80
85
  sentence = sentence.substring(0, pos) + text + sentence.substring(pos + text.length);