@retorquere/bibtex-parser 6.1.4 → 6.2.2

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 -0
  2. package/index.js +50 -2
  3. package/package.json +12 -12
package/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as bibtex from './grammar';
2
2
  import { JabRefMetadata } from './jabref';
3
+ export declare function toSentenceCase(text: string): string;
3
4
  declare 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;
4
5
  export interface Name {
5
6
  /**
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jabref = exports.chunker = exports.promises = exports.ast = exports.parse = exports.fields = void 0;
3
+ exports.jabref = exports.chunker = exports.promises = exports.ast = exports.parse = exports.fields = exports.toSentenceCase = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  /* eslint-disable @typescript-eslint/no-unsafe-argument */
6
6
  const bibtex = tslib_1.__importStar(require("./grammar"));
@@ -8,6 +8,54 @@ const chunker = tslib_1.__importStar(require("./chunker"));
8
8
  const jabref_1 = require("./jabref");
9
9
  const unicode2latex_1 = require("unicode2latex");
10
10
  const crossref_json_1 = tslib_1.__importDefault(require("./crossref.json"));
11
+ class SentenceCaser {
12
+ constructor() {
13
+ this.acronym = /^[A-Z][.]([A-Z][.])+(?=$|[^\w])/;
14
+ }
15
+ convert(text) {
16
+ this.input = text;
17
+ this.result = '';
18
+ this.sentenceStart = true;
19
+ let m;
20
+ while (this.input) {
21
+ if (m = this.input.match(this.acronym)) { // U.S.
22
+ this.add(m[0], true);
23
+ }
24
+ else if (m = this.input.match(/^[a-z]+n't\b/i)) { // isn't
25
+ this.add(m[0]);
26
+ }
27
+ else if (m = this.input.match(/^[\w-]+/)) { // gallium-nitride
28
+ this.add(m[0]);
29
+ }
30
+ else {
31
+ this.add(this.input[0]);
32
+ }
33
+ }
34
+ return this.result;
35
+ }
36
+ add(word, keep = false) {
37
+ const parts = word.split('-');
38
+ const result = [];
39
+ if (this.sentenceStart || keep)
40
+ result.push(parts.shift());
41
+ for (word of parts) {
42
+ if (!word.match(/[a-z][A-Z]/))
43
+ word = word.toLowerCase();
44
+ result.push(word);
45
+ }
46
+ word = result.join('-');
47
+ this.result += word;
48
+ this.input = this.input.substr(word.length);
49
+ if (!word.match(/^\s+$/)) {
50
+ this.sentenceStart = !!word.match(/^[.?!]$/);
51
+ }
52
+ }
53
+ }
54
+ const sentenceCaser = new SentenceCaser;
55
+ function toSentenceCase(text) {
56
+ return sentenceCaser.convert(text);
57
+ }
58
+ exports.toSentenceCase = toSentenceCase;
11
59
  class ParserError extends Error {
12
60
  constructor(message, node) {
13
61
  super(message); // 'Error' breaks prototype chain here
@@ -1284,7 +1332,7 @@ class Parser {
1284
1332
  else {
1285
1333
  this.preserve(0, 1);
1286
1334
  }
1287
- let sentenceCased = text.toLowerCase().replace(/(([?!]\s*|^)(['"¡¿“‘„«\s]+)?[^\s])/g, x => x.toUpperCase());
1335
+ let sentenceCased = toSentenceCase(text);
1288
1336
  for (const { start, end } of this.field.preserveRanges) {
1289
1337
  sentenceCased = sentenceCased.substring(0, start) + text.substring(start, end) + sentenceCased.substring(end);
1290
1338
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retorquere/bibtex-parser",
3
- "version": "6.1.4",
3
+ "version": "6.2.2",
4
4
  "description": "BibTeX parser",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -32,27 +32,27 @@
32
32
  "author": "Emiliano Heyns",
33
33
  "license": "ISC",
34
34
  "devDependencies": {
35
- "@types/node": "^17.0.21",
36
- "@typescript-eslint/eslint-plugin": "^5.14.0",
37
- "@typescript-eslint/parser": "^5.14.0",
35
+ "@types/node": "^17.0.25",
36
+ "@typescript-eslint/eslint-plugin": "^5.20.0",
37
+ "@typescript-eslint/parser": "^5.20.0",
38
38
  "command-line-args": "^5.2.1",
39
39
  "csv": "^6.0.5",
40
- "digital-tree": "^2.0.3",
40
+ "digital-tree": "^2.0.4",
41
41
  "ejs": "^3.1.6",
42
- "eslint": "^8.10.0",
43
- "eslint-plugin-import": "^2.25.4",
42
+ "eslint": "^8.13.0",
43
+ "eslint-plugin-import": "^2.26.0",
44
44
  "eslint-plugin-prefer-arrow": "^1.2.3",
45
- "glob": "^7.2.0",
45
+ "glob": "^8.0.1",
46
46
  "mkdirp": "^1.0.4",
47
- "node-fetch": "^3.2.2",
47
+ "node-fetch": "^3.2.3",
48
48
  "peggy": "^1.2.0",
49
49
  "piscina": "^3.2.0",
50
50
  "slug": "^5.3.0",
51
- "tap": "^16.0.0",
51
+ "tap": "^16.0.1",
52
52
  "ts-node": "^10.7.0",
53
53
  "tslib": "^2.3.1",
54
- "typedoc": "^0.22.13",
55
- "typescript": "^4.6.2"
54
+ "typedoc": "^0.22.15",
55
+ "typescript": "^4.6.3"
56
56
  },
57
57
  "dependencies": {
58
58
  "unicode2latex": "^3.0.0",