@retorquere/bibtex-parser 6.1.2 → 6.3.0

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 (4) hide show
  1. package/grammar.js +76 -65
  2. package/index.d.ts +1 -0
  3. package/index.js +54 -2
  4. package/package.json +13 -13
package/grammar.js CHANGED
@@ -407,7 +407,7 @@ function peg$parse(input, options) {
407
407
  kind: 'Text',
408
408
  loc: location(),
409
409
  source: text(),
410
- value: (v || '').trim(),
410
+ value: normalizeWhitespace((v || '').trim()),
411
411
  mode: 'verbatim',
412
412
  })
413
413
  };
@@ -416,7 +416,7 @@ function peg$parse(input, options) {
416
416
  kind: 'Text',
417
417
  loc: location(),
418
418
  source: text(),
419
- value: v.join('').trim(),
419
+ value: normalizeWhitespace(v.join('').trim()),
420
420
  mode: 'verbatim',
421
421
  })
422
422
  };
@@ -428,6 +428,15 @@ function peg$parse(input, options) {
428
428
  };
429
429
  var peg$f22 = function(v) { return v; };
430
430
  var peg$f23 = function(v) {
431
+ return basicTextConversions({
432
+ kind: 'Text',
433
+ loc: location(),
434
+ source: text(),
435
+ value: v.join('').trim(),
436
+ mode: 'verbatim',
437
+ })
438
+ };
439
+ var peg$f24 = function(v) {
431
440
  return basicTextConversions({
432
441
  kind: 'Text',
433
442
  loc: location(),
@@ -436,7 +445,7 @@ function peg$parse(input, options) {
436
445
  mode: math.on ? 'math' : 'text',
437
446
  })
438
447
  };
439
- var peg$f24 = function(v) {
448
+ var peg$f25 = function(v) {
440
449
  return {
441
450
  kind: 'Number',
442
451
  loc: location(),
@@ -444,7 +453,7 @@ function peg$parse(input, options) {
444
453
  value: parseInt(v, 10),
445
454
  }
446
455
  };
447
- var peg$f25 = function(v) {
456
+ var peg$f26 = function(v) {
448
457
  return {
449
458
  kind: 'StringReference',
450
459
  loc: location(),
@@ -452,8 +461,8 @@ function peg$parse(input, options) {
452
461
  name: v,
453
462
  }
454
463
  };
455
- var peg$f26 = function(env, v, cenv) { return env === cenv };
456
- var peg$f27 = function(env, v, cenv) {
464
+ var peg$f27 = function(env, v, cenv) { return env === cenv };
465
+ var peg$f28 = function(env, v, cenv) {
457
466
  if (markup[env]) {
458
467
  return {
459
468
  kind: 'Block',
@@ -472,7 +481,7 @@ function peg$parse(input, options) {
472
481
  }
473
482
  }
474
483
  };
475
- var peg$f28 = function(mark, char) {
484
+ var peg$f29 = function(mark, char) {
476
485
  return {
477
486
  kind: 'DiacriticCommand',
478
487
  loc: location(),
@@ -482,7 +491,7 @@ function peg$parse(input, options) {
482
491
  character: char[1] || char[0],
483
492
  }
484
493
  };
485
- var peg$f29 = function(v) {
494
+ var peg$f30 = function(v) {
486
495
  return basicTextConversions({
487
496
  kind: 'Text',
488
497
  loc: location(),
@@ -491,7 +500,7 @@ function peg$parse(input, options) {
491
500
  mode: 'verbatim',
492
501
  })
493
502
  };
494
- var peg$f30 = function(v) {
503
+ var peg$f31 = function(v) {
495
504
  const block = {
496
505
  kind: 'Block',
497
506
  loc: location(),
@@ -525,10 +534,10 @@ function peg$parse(input, options) {
525
534
 
526
535
  return handle_markup_switches(block)
527
536
  };
528
- var peg$f31 = function() { return !math.on };
529
- var peg$f32 = function(mode) { return math.set(true) };
530
- var peg$f33 = function(mode, v) { return math.set(false) };
531
- var peg$f34 = function(mode, v) {
537
+ var peg$f32 = function() { return !math.on };
538
+ var peg$f33 = function(mode) { return math.set(true) };
539
+ var peg$f34 = function(mode, v) { return math.set(false) };
540
+ var peg$f35 = function(mode, v) {
532
541
  return {
533
542
  kind: mode == '$$' ? 'DisplayMath' : 'InlineMath',
534
543
  loc: location(),
@@ -538,7 +547,7 @@ function peg$parse(input, options) {
538
547
  markup: {},
539
548
  }
540
549
  };
541
- var peg$f35 = function(v) {
550
+ var peg$f36 = function(v) {
542
551
  return {
543
552
  kind: 'LineComment',
544
553
  loc: location(),
@@ -546,7 +555,7 @@ function peg$parse(input, options) {
546
555
  value: v,
547
556
  }
548
557
  };
549
- var peg$f36 = function(mode, v) {
558
+ var peg$f37 = function(mode, v) {
550
559
  if (v.kind === 'Block') v = v.value
551
560
 
552
561
  return {
@@ -556,7 +565,7 @@ function peg$parse(input, options) {
556
565
  value: v,
557
566
  }
558
567
  };
559
- var peg$f37 = function(mark, v) {
568
+ var peg$f38 = function(mark, v) {
560
569
  return {
561
570
  kind: 'RegularCommand',
562
571
  loc: location(),
@@ -568,7 +577,7 @@ function peg$parse(input, options) {
568
577
  },
569
578
  }
570
579
  };
571
- var peg$f38 = function(v) {
580
+ var peg$f39 = function(v) {
572
581
  return {
573
582
  kind: 'SymbolCommand',
574
583
  loc: location(),
@@ -576,8 +585,8 @@ function peg$parse(input, options) {
576
585
  command: v,
577
586
  }
578
587
  };
579
- var peg$f39 = function(cmd, name) { return name.value.length == 1 && name.value[0].kind === 'RegularCommand' };
580
- var peg$f40 = function(cmd, name, optional, def) {
588
+ var peg$f40 = function(cmd, name) { return name.value.length == 1 && name.value[0].kind === 'RegularCommand' };
589
+ var peg$f41 = function(cmd, name, optional, def) {
581
590
  return {
582
591
  kind: 'RegularCommand',
583
592
  loc: location(),
@@ -589,7 +598,7 @@ function peg$parse(input, options) {
589
598
  },
590
599
  }
591
600
  };
592
- var peg$f41 = function(cmd, url, label) {
601
+ var peg$f42 = function(cmd, url, label) {
593
602
  return {
594
603
  kind: 'RegularCommand',
595
604
  loc: location(),
@@ -601,8 +610,8 @@ function peg$parse(input, options) {
601
610
  },
602
611
  }
603
612
  };
604
- var peg$f42 = function(cmd) { return verbatimCommands.includes(cmd) && (has_arguments[cmd] === 2) };
605
- var peg$f43 = function(cmd, optional, req1, req2) {
613
+ var peg$f43 = function(cmd) { return verbatimCommands.includes(cmd) && (has_arguments[cmd] === 2) };
614
+ var peg$f44 = function(cmd, optional, req1, req2) {
606
615
  return {
607
616
  kind: 'RegularCommand',
608
617
  loc: location(),
@@ -614,8 +623,8 @@ function peg$parse(input, options) {
614
623
  },
615
624
  }
616
625
  };
617
- var peg$f44 = function(cmd) { return verbatimCommands.includes(cmd) && (has_arguments[cmd] === 1) };
618
- var peg$f45 = function(cmd, optional, req) {
626
+ var peg$f45 = function(cmd) { return verbatimCommands.includes(cmd) && (has_arguments[cmd] === 1) };
627
+ var peg$f46 = function(cmd, optional, req) {
619
628
  return {
620
629
  kind: 'RegularCommand',
621
630
  loc: location(),
@@ -627,8 +636,8 @@ function peg$parse(input, options) {
627
636
  },
628
637
  }
629
638
  };
630
- var peg$f46 = function(cmd) { return (has_arguments[cmd] === 2) };
631
- var peg$f47 = function(cmd, optional, req1, req2) {
639
+ var peg$f47 = function(cmd) { return (has_arguments[cmd] === 2) };
640
+ var peg$f48 = function(cmd, optional, req1, req2) {
632
641
  return {
633
642
  kind: 'RegularCommand',
634
643
  loc: location(),
@@ -640,8 +649,8 @@ function peg$parse(input, options) {
640
649
  },
641
650
  }
642
651
  };
643
- var peg$f48 = function(cmd) { return (has_arguments[cmd] === 1) };
644
- var peg$f49 = function(cmd, optional, req) {
652
+ var peg$f49 = function(cmd) { return (has_arguments[cmd] === 1) };
653
+ var peg$f50 = function(cmd, optional, req) {
645
654
  let m
646
655
  if (req.kind === 'Block') {
647
656
  switch (cmd) {
@@ -691,7 +700,7 @@ function peg$parse(input, options) {
691
700
  }
692
701
  }
693
702
  };
694
- var peg$f50 = function(cmd, optional) {
703
+ var peg$f51 = function(cmd, optional) {
695
704
  return {
696
705
  kind: 'RegularCommand',
697
706
  loc: location(),
@@ -703,7 +712,7 @@ function peg$parse(input, options) {
703
712
  }
704
713
  }
705
714
  };
706
- var peg$f51 = function(v) {
715
+ var peg$f52 = function(v) {
707
716
  return basicTextConversions({
708
717
  kind: 'Text', // this isn't really correct but I don't need these right now
709
718
  loc: location(),
@@ -712,7 +721,7 @@ function peg$parse(input, options) {
712
721
  mode: math.on ? 'math' : 'text',
713
722
  })
714
723
  };
715
- var peg$f52 = function(v) {
724
+ var peg$f53 = function(v) {
716
725
  return basicTextConversions({
717
726
  kind: 'Text',
718
727
  loc: location(),
@@ -2034,7 +2043,7 @@ function peg$parse(input, options) {
2034
2043
  s5 = null;
2035
2044
  }
2036
2045
  peg$savedPos = s0;
2037
- s0 = peg$f17(s3);
2046
+ s0 = peg$f23(s3);
2038
2047
  } else {
2039
2048
  peg$currPos = s0;
2040
2049
  s0 = peg$FAILED;
@@ -2178,7 +2187,7 @@ function peg$parse(input, options) {
2178
2187
  }
2179
2188
  if (s1 !== peg$FAILED) {
2180
2189
  peg$savedPos = s0;
2181
- s1 = peg$f23(s1);
2190
+ s1 = peg$f24(s1);
2182
2191
  }
2183
2192
  s0 = s1;
2184
2193
 
@@ -2213,7 +2222,7 @@ function peg$parse(input, options) {
2213
2222
  }
2214
2223
  if (s1 !== peg$FAILED) {
2215
2224
  peg$savedPos = s0;
2216
- s1 = peg$f23(s1);
2225
+ s1 = peg$f24(s1);
2217
2226
  }
2218
2227
  s0 = s1;
2219
2228
 
@@ -2254,7 +2263,7 @@ function peg$parse(input, options) {
2254
2263
  }
2255
2264
  if (s1 !== peg$FAILED) {
2256
2265
  peg$savedPos = s0;
2257
- s1 = peg$f24(s1);
2266
+ s1 = peg$f25(s1);
2258
2267
  }
2259
2268
  s0 = s1;
2260
2269
 
@@ -2268,7 +2277,7 @@ function peg$parse(input, options) {
2268
2277
  s1 = peg$parseVariableName();
2269
2278
  if (s1 !== peg$FAILED) {
2270
2279
  peg$savedPos = s0;
2271
- s1 = peg$f25(s1);
2280
+ s1 = peg$f26(s1);
2272
2281
  }
2273
2282
  s0 = s1;
2274
2283
 
@@ -2400,7 +2409,7 @@ function peg$parse(input, options) {
2400
2409
  }
2401
2410
  if (s7 !== peg$FAILED) {
2402
2411
  peg$savedPos = peg$currPos;
2403
- s8 = peg$f26(s2, s4, s6);
2412
+ s8 = peg$f27(s2, s4, s6);
2404
2413
  if (s8) {
2405
2414
  s8 = undefined;
2406
2415
  } else {
@@ -2408,7 +2417,7 @@ function peg$parse(input, options) {
2408
2417
  }
2409
2418
  if (s8 !== peg$FAILED) {
2410
2419
  peg$savedPos = s0;
2411
- s0 = peg$f27(s2, s4, s6);
2420
+ s0 = peg$f28(s2, s4, s6);
2412
2421
  } else {
2413
2422
  peg$currPos = s0;
2414
2423
  s0 = peg$FAILED;
@@ -2502,7 +2511,7 @@ function peg$parse(input, options) {
2502
2511
  }
2503
2512
  if (s5 !== peg$FAILED) {
2504
2513
  peg$savedPos = s0;
2505
- s0 = peg$f28(s2, s4);
2514
+ s0 = peg$f29(s2, s4);
2506
2515
  } else {
2507
2516
  peg$currPos = s0;
2508
2517
  s0 = peg$FAILED;
@@ -2561,7 +2570,7 @@ function peg$parse(input, options) {
2561
2570
  }
2562
2571
  if (s4 !== peg$FAILED) {
2563
2572
  peg$savedPos = s0;
2564
- s0 = peg$f29(s3);
2573
+ s0 = peg$f30(s3);
2565
2574
  } else {
2566
2575
  peg$currPos = s0;
2567
2576
  s0 = peg$FAILED;
@@ -2623,7 +2632,7 @@ function peg$parse(input, options) {
2623
2632
  }
2624
2633
  if (s3 !== peg$FAILED) {
2625
2634
  peg$savedPos = s0;
2626
- s0 = peg$f30(s2);
2635
+ s0 = peg$f31(s2);
2627
2636
  } else {
2628
2637
  peg$currPos = s0;
2629
2638
  s0 = peg$FAILED;
@@ -2643,7 +2652,7 @@ function peg$parse(input, options) {
2643
2652
 
2644
2653
  s0 = peg$currPos;
2645
2654
  peg$savedPos = peg$currPos;
2646
- s1 = peg$f31();
2655
+ s1 = peg$f32();
2647
2656
  if (s1) {
2648
2657
  s1 = undefined;
2649
2658
  } else {
@@ -2677,7 +2686,7 @@ function peg$parse(input, options) {
2677
2686
  }
2678
2687
  if (s2 !== peg$FAILED) {
2679
2688
  peg$savedPos = peg$currPos;
2680
- s3 = peg$f32(s2);
2689
+ s3 = peg$f33(s2);
2681
2690
  if (s3) {
2682
2691
  s3 = undefined;
2683
2692
  } else {
@@ -2729,7 +2738,7 @@ function peg$parse(input, options) {
2729
2738
  }
2730
2739
  if (s5 !== peg$FAILED) {
2731
2740
  peg$savedPos = peg$currPos;
2732
- s6 = peg$f33(s2, s4);
2741
+ s6 = peg$f34(s2, s4);
2733
2742
  if (s6) {
2734
2743
  s6 = undefined;
2735
2744
  } else {
@@ -2737,7 +2746,7 @@ function peg$parse(input, options) {
2737
2746
  }
2738
2747
  if (s6 !== peg$FAILED) {
2739
2748
  peg$savedPos = s0;
2740
- s0 = peg$f34(s2, s4);
2749
+ s0 = peg$f35(s2, s4);
2741
2750
  } else {
2742
2751
  peg$currPos = s0;
2743
2752
  s0 = peg$FAILED;
@@ -2816,7 +2825,7 @@ function peg$parse(input, options) {
2816
2825
  }
2817
2826
  if (s4 !== peg$FAILED) {
2818
2827
  peg$savedPos = s0;
2819
- s0 = peg$f35(s3);
2828
+ s0 = peg$f36(s3);
2820
2829
  } else {
2821
2830
  peg$currPos = s0;
2822
2831
  s0 = peg$FAILED;
@@ -2866,7 +2875,7 @@ function peg$parse(input, options) {
2866
2875
  s3 = peg$parseArgument();
2867
2876
  if (s3 !== peg$FAILED) {
2868
2877
  peg$savedPos = s0;
2869
- s0 = peg$f36(s1, s3);
2878
+ s0 = peg$f37(s1, s3);
2870
2879
  } else {
2871
2880
  peg$currPos = s0;
2872
2881
  s0 = peg$FAILED;
@@ -2932,7 +2941,7 @@ function peg$parse(input, options) {
2932
2941
  }
2933
2942
  if (s4 !== peg$FAILED) {
2934
2943
  peg$savedPos = s0;
2935
- s0 = peg$f28(s2, s4);
2944
+ s0 = peg$f29(s2, s4);
2936
2945
  } else {
2937
2946
  peg$currPos = s0;
2938
2947
  s0 = peg$FAILED;
@@ -3011,7 +3020,7 @@ function peg$parse(input, options) {
3011
3020
  }
3012
3021
  if (s5 !== peg$FAILED) {
3013
3022
  peg$savedPos = s0;
3014
- s0 = peg$f28(s2, s4);
3023
+ s0 = peg$f29(s2, s4);
3015
3024
  } else {
3016
3025
  peg$currPos = s0;
3017
3026
  s0 = peg$FAILED;
@@ -3064,7 +3073,7 @@ function peg$parse(input, options) {
3064
3073
  s4 = peg$parseRegularValue();
3065
3074
  if (s4 !== peg$FAILED) {
3066
3075
  peg$savedPos = s0;
3067
- s0 = peg$f37(s2, s4);
3076
+ s0 = peg$f38(s2, s4);
3068
3077
  } else {
3069
3078
  peg$currPos = s0;
3070
3079
  s0 = peg$FAILED;
@@ -3114,7 +3123,7 @@ function peg$parse(input, options) {
3114
3123
  }
3115
3124
  if (s2 !== peg$FAILED) {
3116
3125
  peg$savedPos = s0;
3117
- s0 = peg$f38(s2);
3126
+ s0 = peg$f39(s2);
3118
3127
  } else {
3119
3128
  peg$currPos = s0;
3120
3129
  s0 = peg$FAILED;
@@ -3150,7 +3159,7 @@ function peg$parse(input, options) {
3150
3159
  s3 = peg$parseBlock();
3151
3160
  if (s3 !== peg$FAILED) {
3152
3161
  peg$savedPos = peg$currPos;
3153
- s4 = peg$f39(s2, s3);
3162
+ s4 = peg$f40(s2, s3);
3154
3163
  if (s4) {
3155
3164
  s4 = undefined;
3156
3165
  } else {
@@ -3166,7 +3175,7 @@ function peg$parse(input, options) {
3166
3175
  s6 = peg$parseArgument();
3167
3176
  if (s6 !== peg$FAILED) {
3168
3177
  peg$savedPos = s0;
3169
- s0 = peg$f40(s2, s3, s5, s6);
3178
+ s0 = peg$f41(s2, s3, s5, s6);
3170
3179
  } else {
3171
3180
  peg$currPos = s0;
3172
3181
  s0 = peg$FAILED;
@@ -3228,7 +3237,7 @@ function peg$parse(input, options) {
3228
3237
  s6 = peg$parseArgument();
3229
3238
  if (s6 !== peg$FAILED) {
3230
3239
  peg$savedPos = s0;
3231
- s0 = peg$f41(s2, s5, s6);
3240
+ s0 = peg$f42(s2, s5, s6);
3232
3241
  } else {
3233
3242
  peg$currPos = s0;
3234
3243
  s0 = peg$FAILED;
@@ -3323,7 +3332,7 @@ function peg$parse(input, options) {
3323
3332
  }
3324
3333
  if (s4 !== peg$FAILED) {
3325
3334
  peg$savedPos = peg$currPos;
3326
- s5 = peg$f42(s4);
3335
+ s5 = peg$f43(s4);
3327
3336
  if (s5) {
3328
3337
  s5 = undefined;
3329
3338
  } else {
@@ -3359,7 +3368,7 @@ function peg$parse(input, options) {
3359
3368
  s10 = peg$parseVerbatimFieldValue();
3360
3369
  if (s10 !== peg$FAILED) {
3361
3370
  peg$savedPos = s0;
3362
- s0 = peg$f43(s4, s6, s9, s10);
3371
+ s0 = peg$f44(s4, s6, s9, s10);
3363
3372
  } else {
3364
3373
  peg$currPos = s0;
3365
3374
  s0 = peg$FAILED;
@@ -3466,7 +3475,7 @@ function peg$parse(input, options) {
3466
3475
  }
3467
3476
  if (s4 !== peg$FAILED) {
3468
3477
  peg$savedPos = peg$currPos;
3469
- s5 = peg$f44(s4);
3478
+ s5 = peg$f45(s4);
3470
3479
  if (s5) {
3471
3480
  s5 = undefined;
3472
3481
  } else {
@@ -3500,7 +3509,7 @@ function peg$parse(input, options) {
3500
3509
  s9 = peg$parseVerbatimFieldValue();
3501
3510
  if (s9 !== peg$FAILED) {
3502
3511
  peg$savedPos = s0;
3503
- s0 = peg$f45(s4, s6, s9);
3512
+ s0 = peg$f46(s4, s6, s9);
3504
3513
  } else {
3505
3514
  peg$currPos = s0;
3506
3515
  s0 = peg$FAILED;
@@ -3603,7 +3612,7 @@ function peg$parse(input, options) {
3603
3612
  }
3604
3613
  if (s4 !== peg$FAILED) {
3605
3614
  peg$savedPos = peg$currPos;
3606
- s5 = peg$f46(s4);
3615
+ s5 = peg$f47(s4);
3607
3616
  if (s5) {
3608
3617
  s5 = undefined;
3609
3618
  } else {
@@ -3622,7 +3631,7 @@ function peg$parse(input, options) {
3622
3631
  s9 = peg$parseArgument();
3623
3632
  if (s9 !== peg$FAILED) {
3624
3633
  peg$savedPos = s0;
3625
- s0 = peg$f47(s4, s6, s8, s9);
3634
+ s0 = peg$f48(s4, s6, s8, s9);
3626
3635
  } else {
3627
3636
  peg$currPos = s0;
3628
3637
  s0 = peg$FAILED;
@@ -3725,7 +3734,7 @@ function peg$parse(input, options) {
3725
3734
  }
3726
3735
  if (s4 !== peg$FAILED) {
3727
3736
  peg$savedPos = peg$currPos;
3728
- s5 = peg$f48(s4);
3737
+ s5 = peg$f49(s4);
3729
3738
  if (s5) {
3730
3739
  s5 = undefined;
3731
3740
  } else {
@@ -3742,7 +3751,7 @@ function peg$parse(input, options) {
3742
3751
  s8 = peg$parseArgument();
3743
3752
  if (s8 !== peg$FAILED) {
3744
3753
  peg$savedPos = s0;
3745
- s0 = peg$f49(s4, s6, s8);
3754
+ s0 = peg$f50(s4, s6, s8);
3746
3755
  } else {
3747
3756
  peg$currPos = s0;
3748
3757
  s0 = peg$FAILED;
@@ -3848,7 +3857,7 @@ function peg$parse(input, options) {
3848
3857
  }
3849
3858
  s6 = peg$parse__();
3850
3859
  peg$savedPos = s0;
3851
- s0 = peg$f50(s4, s5);
3860
+ s0 = peg$f51(s4, s5);
3852
3861
  } else {
3853
3862
  peg$currPos = s0;
3854
3863
  s0 = peg$FAILED;
@@ -3927,7 +3936,7 @@ function peg$parse(input, options) {
3927
3936
  }
3928
3937
  if (s5 !== peg$FAILED) {
3929
3938
  peg$savedPos = s0;
3930
- s0 = peg$f51(s3);
3939
+ s0 = peg$f52(s3);
3931
3940
  } else {
3932
3941
  peg$currPos = s0;
3933
3942
  s0 = peg$FAILED;
@@ -3958,7 +3967,7 @@ function peg$parse(input, options) {
3958
3967
  }
3959
3968
  if (s2 !== peg$FAILED) {
3960
3969
  peg$savedPos = s0;
3961
- s0 = peg$f52(s2);
3970
+ s0 = peg$f53(s2);
3962
3971
  } else {
3963
3972
  peg$currPos = s0;
3964
3973
  s0 = peg$FAILED;
@@ -4394,6 +4403,8 @@ function peg$parse(input, options) {
4394
4403
  }
4395
4404
 
4396
4405
  function normalizeWhitespace(textArr) {
4406
+ if (typeof textArr === 'string') textArr = Array.from(textArr)
4407
+
4397
4408
  return textArr.reduce((prev, curr) => {
4398
4409
  if (/\s/.test(curr)) {
4399
4410
  if (/\s/.test(prev[prev.length - 1])) {
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,58 @@ 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
+ this.quoted = /^"[^"]+"(?=$|[^\w])/;
15
+ }
16
+ convert(text) {
17
+ this.input = text;
18
+ this.result = '';
19
+ this.sentenceStart = true;
20
+ let m;
21
+ while (this.input) {
22
+ if (m = this.input.match(this.quoted)) { // "Hello There"
23
+ this.add(m[0], true);
24
+ }
25
+ else if (m = this.input.match(this.acronym)) { // U.S.
26
+ this.add(m[0], true);
27
+ }
28
+ else if (m = this.input.match(/^[a-z]+n't\b/i)) { // isn't
29
+ this.add(m[0]);
30
+ }
31
+ else if (m = this.input.match(/^[\w-]+/)) { // gallium-nitride
32
+ this.add(m[0]);
33
+ }
34
+ else {
35
+ this.add(this.input[0]);
36
+ }
37
+ }
38
+ return this.result;
39
+ }
40
+ add(word, keep = false) {
41
+ const parts = word.split('-');
42
+ const result = [];
43
+ if (this.sentenceStart || keep)
44
+ result.push(parts.shift());
45
+ for (word of parts) {
46
+ if (!word.match(/[a-z][A-Z]/))
47
+ word = word.toLowerCase();
48
+ result.push(word);
49
+ }
50
+ word = result.join('-');
51
+ this.result += word;
52
+ this.input = this.input.substr(word.length);
53
+ if (!word.match(/^\s+$/)) {
54
+ this.sentenceStart = !!word.match(/^[.?!]$/);
55
+ }
56
+ }
57
+ }
58
+ const sentenceCaser = new SentenceCaser;
59
+ function toSentenceCase(text) {
60
+ return sentenceCaser.convert(text);
61
+ }
62
+ exports.toSentenceCase = toSentenceCase;
11
63
  class ParserError extends Error {
12
64
  constructor(message, node) {
13
65
  super(message); // 'Error' breaks prototype chain here
@@ -1284,7 +1336,7 @@ class Parser {
1284
1336
  else {
1285
1337
  this.preserve(0, 1);
1286
1338
  }
1287
- let sentenceCased = text.toLowerCase().replace(/(([?!]\s*|^)(['"¡¿“‘„«\s]+)?[^\s])/g, x => x.toUpperCase());
1339
+ let sentenceCased = toSentenceCase(text);
1288
1340
  for (const { start, end } of this.field.preserveRanges) {
1289
1341
  sentenceCased = sentenceCased.substring(0, start) + text.substring(start, end) + sentenceCased.substring(end);
1290
1342
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retorquere/bibtex-parser",
3
- "version": "6.1.2",
3
+ "version": "6.3.0",
4
4
  "description": "BibTeX parser",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -9,7 +9,7 @@
9
9
  "start": "tsc -d",
10
10
  "poststart": "npm run docs",
11
11
  "pretest": "npm start",
12
- "test": "./test/tap",
12
+ "test": "tap test/tap --no-timeout --no-coverage",
13
13
  "snap": "npm test --snapshot",
14
14
  "snap:big": "npm test --snapshot --big",
15
15
  "minitest": "peggy grammar.peggy && tsc -d && node i.js",
@@ -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",