bible-ref-parse 3.2.0 → 3.3.1

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 (128) hide show
  1. package/dist/am-bcv-parser.js +191 -32
  2. package/dist/am-bcv-parser.min.js +1 -1
  3. package/dist/ar-bcv-parser.js +191 -32
  4. package/dist/ar-bcv-parser.min.js +2 -2
  5. package/dist/bb-bcv-parser.js +191 -32
  6. package/dist/bb-bcv-parser.min.js +2 -2
  7. package/dist/bg-bcv-parser.js +191 -32
  8. package/dist/bg-bcv-parser.min.js +2 -2
  9. package/dist/bn-bcv-parser.js +191 -32
  10. package/dist/bn-bcv-parser.min.js +2 -2
  11. package/dist/ceb-bcv-parser.js +191 -32
  12. package/dist/ceb-bcv-parser.min.js +2 -2
  13. package/dist/cs-bcv-parser.js +191 -32
  14. package/dist/cs-bcv-parser.min.js +2 -2
  15. package/dist/da-bcv-parser.js +191 -32
  16. package/dist/da-bcv-parser.min.js +2 -2
  17. package/dist/de-bcv-parser.js +191 -32
  18. package/dist/de-bcv-parser.min.js +2 -2
  19. package/dist/ee-bcv-parser.js +191 -32
  20. package/dist/ee-bcv-parser.min.js +3 -3
  21. package/dist/el-bcv-parser.js +191 -32
  22. package/dist/el-bcv-parser.min.js +1 -1
  23. package/dist/en-bcv-parser.js +122 -11
  24. package/dist/en-bcv-parser.min.js +2 -2
  25. package/dist/es-bcv-parser.js +191 -32
  26. package/dist/es-bcv-parser.min.js +2 -2
  27. package/dist/fa-bcv-parser.js +191 -32
  28. package/dist/fa-bcv-parser.min.js +3 -3
  29. package/dist/fi-bcv-parser.js +191 -32
  30. package/dist/fi-bcv-parser.min.js +2 -2
  31. package/dist/fr-bcv-parser.js +191 -32
  32. package/dist/fr-bcv-parser.min.js +3 -3
  33. package/dist/he-bcv-parser.js +191 -32
  34. package/dist/he-bcv-parser.min.js +1 -1
  35. package/dist/hi-bcv-parser.js +191 -32
  36. package/dist/hi-bcv-parser.min.js +2 -2
  37. package/dist/hl-bcv-parser.js +191 -32
  38. package/dist/hl-bcv-parser.min.js +2 -2
  39. package/dist/hr-bcv-parser.js +191 -32
  40. package/dist/hr-bcv-parser.min.js +2 -2
  41. package/dist/ht-bcv-parser.js +191 -32
  42. package/dist/ht-bcv-parser.min.js +2 -2
  43. package/dist/hu-bcv-parser.js +191 -32
  44. package/dist/hu-bcv-parser.min.js +2 -2
  45. package/dist/id-bcv-parser.js +191 -32
  46. package/dist/id-bcv-parser.min.js +2 -2
  47. package/dist/il-bcv-parser.js +189 -30
  48. package/dist/il-bcv-parser.min.js +2 -2
  49. package/dist/is-bcv-parser.js +191 -32
  50. package/dist/is-bcv-parser.min.js +2 -2
  51. package/dist/it-bcv-parser.js +191 -32
  52. package/dist/it-bcv-parser.min.js +3 -3
  53. package/dist/ja-bcv-parser.js +191 -32
  54. package/dist/ja-bcv-parser.min.js +3 -3
  55. package/dist/jv-bcv-parser.js +191 -32
  56. package/dist/jv-bcv-parser.min.js +2 -2
  57. package/dist/ko-bcv-parser.js +191 -32
  58. package/dist/ko-bcv-parser.min.js +2 -2
  59. package/dist/la-bcv-parser.js +191 -32
  60. package/dist/la-bcv-parser.min.js +2 -2
  61. package/dist/lu-bcv-parser.js +191 -32
  62. package/dist/lu-bcv-parser.min.js +2 -2
  63. package/dist/mg-bcv-parser.js +191 -32
  64. package/dist/mg-bcv-parser.min.js +3 -3
  65. package/dist/mk-bcv-parser.js +191 -32
  66. package/dist/mk-bcv-parser.min.js +2 -2
  67. package/dist/mq-bcv-parser.js +191 -32
  68. package/dist/mq-bcv-parser.min.js +2 -2
  69. package/dist/mr-bcv-parser.js +191 -32
  70. package/dist/mr-bcv-parser.min.js +2 -2
  71. package/dist/nd-bcv-parser.js +191 -32
  72. package/dist/nd-bcv-parser.min.js +2 -2
  73. package/dist/ne-bcv-parser.js +191 -32
  74. package/dist/ne-bcv-parser.min.js +2 -2
  75. package/dist/nl-bcv-parser.js +191 -32
  76. package/dist/nl-bcv-parser.min.js +3 -3
  77. package/dist/no-bcv-parser.js +191 -32
  78. package/dist/no-bcv-parser.min.js +2 -2
  79. package/dist/ny-bcv-parser.js +191 -32
  80. package/dist/ny-bcv-parser.min.js +2 -2
  81. package/dist/or-bcv-parser.js +191 -32
  82. package/dist/or-bcv-parser.min.js +2 -2
  83. package/dist/pa-bcv-parser.js +191 -32
  84. package/dist/pa-bcv-parser.min.js +2 -2
  85. package/dist/pl-bcv-parser.js +191 -32
  86. package/dist/pl-bcv-parser.min.js +2 -2
  87. package/dist/pt-bcv-parser.js +191 -32
  88. package/dist/pt-bcv-parser.min.js +3 -3
  89. package/dist/ro-bcv-parser.js +191 -32
  90. package/dist/ro-bcv-parser.min.js +2 -2
  91. package/dist/ru-bcv-parser.js +191 -32
  92. package/dist/ru-bcv-parser.min.js +2 -2
  93. package/dist/rw-bcv-parser.js +191 -32
  94. package/dist/rw-bcv-parser.min.js +3 -3
  95. package/dist/si-bcv-parser.js +191 -32
  96. package/dist/si-bcv-parser.min.js +2 -2
  97. package/dist/sk-bcv-parser.js +191 -32
  98. package/dist/sk-bcv-parser.min.js +3 -3
  99. package/dist/so-bcv-parser.js +191 -32
  100. package/dist/so-bcv-parser.min.js +2 -2
  101. package/dist/sq-bcv-parser.js +191 -32
  102. package/dist/sq-bcv-parser.min.js +2 -2
  103. package/dist/sr-bcv-parser.js +191 -32
  104. package/dist/sr-bcv-parser.min.js +2 -2
  105. package/dist/sv-bcv-parser.js +191 -32
  106. package/dist/sv-bcv-parser.min.js +2 -2
  107. package/dist/sw-bcv-parser.js +191 -32
  108. package/dist/sw-bcv-parser.min.js +2 -2
  109. package/dist/ta-bcv-parser.js +191 -32
  110. package/dist/ta-bcv-parser.min.js +2 -2
  111. package/dist/test/en.spec.js +7 -0
  112. package/dist/th-bcv-parser.js +191 -32
  113. package/dist/th-bcv-parser.min.js +2 -2
  114. package/dist/tl-bcv-parser.js +191 -32
  115. package/dist/tl-bcv-parser.min.js +2 -2
  116. package/dist/tr-bcv-parser.js +191 -32
  117. package/dist/tr-bcv-parser.min.js +2 -2
  118. package/dist/uk-bcv-parser.js +191 -32
  119. package/dist/uk-bcv-parser.min.js +2 -2
  120. package/dist/ur-bcv-parser.js +191 -32
  121. package/dist/ur-bcv-parser.min.js +2 -2
  122. package/dist/vi-bcv-parser.js +191 -32
  123. package/dist/vi-bcv-parser.min.js +1 -1
  124. package/dist/zh-bcv-parser.js +191 -32
  125. package/dist/zh-bcv-parser.min.js +3 -3
  126. package/dist/zu-bcv-parser.js +191 -32
  127. package/dist/zu-bcv-parser.min.js +2 -2
  128. package/package.json +1 -1
@@ -548,7 +548,11 @@ class bcv_parser {
548
548
  const out = [];
549
549
  for (var osis of Array.from(this.parsed_entities())) {
550
550
  if (osis.osis.length > 0) {
551
- out.push({ osis: osis.osis, translations: osis.translations, indices: osis.indices });
551
+ const entry = { osis: osis.osis, translations: osis.translations, indices: osis.indices };
552
+ if (osis.osises != null) {
553
+ entry.osises = osis.osises;
554
+ }
555
+ out.push(entry);
552
556
  }
553
557
  }
554
558
  return out;
@@ -565,6 +569,28 @@ class bcv_parser {
565
569
  if (entity.passages == null) {
566
570
  continue;
567
571
  }
572
+ if (this.options.consecutive_combination_strategy === "separate-chapters") {
573
+ const semicolon_segments = this.split_text_by_semicolon(entity.absolute_indices);
574
+ if (semicolon_segments.length > 1) {
575
+ for (const segment of Array.from(semicolon_segments)) {
576
+ const sub_parser = new bcv_parser;
577
+ sub_parser.set_options({ ...this.options });
578
+ sub_parser.parse(segment.text);
579
+ for (const sub of Array.from(sub_parser.parsed_entities())) {
580
+ if (sub.osis.length === 0) {
581
+ continue;
582
+ }
583
+ const indices = [sub.indices[0] + segment.offset, sub.indices[1] + segment.offset];
584
+ const entry = { osis: sub.osis, translations: sub.translations, indices, entity_id };
585
+ if (sub.osises != null) {
586
+ entry.osises = sub.osises;
587
+ }
588
+ out.push(entry);
589
+ }
590
+ }
591
+ continue;
592
+ }
593
+ }
568
594
  if (((entity.type === "b") && (this.options.book_alone_strategy === "ignore")) || ((entity.type === "b_range") && (this.options.book_range_strategy === "ignore")) || (entity.type === "context")) {
569
595
  continue;
570
596
  }
@@ -614,34 +640,18 @@ class bcv_parser {
614
640
  passage.absolute_indices = entity.absolute_indices;
615
641
  }
616
642
  if ((this.options.consecutive_combination_strategy === 'separate-chapters') && (passage.start.c !== passage.end.c)) {
617
- var asc2, end2;
618
- for (i = passage.start.c, end2 = passage.end.c, asc2 = passage.start.c <= end2; asc2 ? i <= end2 : i >= end2; asc2 ? i++ : i--) {
619
- var passageStartVerse = i === passage.start.c ? passage.start.v : 1;
620
- var passageEndVerse = i === passage.end.c ? passage.end.v : this.translations[translation_alias]['chapters'][passage.start.b][i - 1];
621
- var passageStart = {
622
- b: passage.start.b,
623
- c: i,
624
- v: passage.start.type === 'bcv' ? passageStartVerse : null,
625
- type: passage.start.type
626
- };
627
- var passageEnd = {
628
- b: passage.end.b,
629
- c: i,
630
- v: passage.start.type === 'bcv' ? passageEndVerse : null,
631
- type: passage.start.type
632
- };
633
- nonCombinableOsises.push({
634
- osis: passage.valid.valid ? this.to_osis(passageStart, passageEnd, translation_alias) : "",
635
- type: passage.type,
636
- indices: passage.absolute_indices,
637
- translations,
638
- start: passageStart,
639
- end: passageEnd,
640
- enclosed_indices: passage.enclosed_absolute_indices,
641
- entity_id,
642
- entities: [passage]
643
- });
644
- }
643
+ osises.push({
644
+ osis: passage.valid.valid ? this.to_osis(passage.start, passage.end, translation_alias) : "",
645
+ osises: this.get_osises_by_chapter({ osis: "", start: passage.start, end: passage.end }, translation_alias),
646
+ type: passage.type,
647
+ indices: passage.absolute_indices,
648
+ translations,
649
+ start: passage.start,
650
+ end: passage.end,
651
+ enclosed_indices: passage.enclosed_absolute_indices,
652
+ entity_id,
653
+ entities: [passage]
654
+ });
645
655
  }
646
656
  else {
647
657
  osises.push({
@@ -667,12 +677,54 @@ class bcv_parser {
667
677
  }
668
678
  osises = osises.concat(nonCombinableOsises).sort((osis1, osis2) => osis1.indices[0] - osis2.indices[0]);
669
679
  }
680
+ if (this.options.consecutive_combination_strategy === "separate-chapters") {
681
+ for (osis of Array.from(osises)) {
682
+ if (osis.osis.length === 0) {
683
+ continue;
684
+ }
685
+ const osises_by_chapter = this.get_osises_by_chapter(osis, translation_alias);
686
+ if (osises_by_chapter.length > 1) {
687
+ osis.osises = osises_by_chapter;
688
+ }
689
+ }
690
+ }
670
691
  // Add the osises array to the existing array.
671
692
  if (this.options.sequence_combination_strategy === "separate") {
672
693
  out = out.concat(osises);
673
694
  // Add the OSIS string and some data to the array.
674
695
  }
675
696
  else {
697
+ if ((this.options.consecutive_combination_strategy === "separate-chapters") && (entity.type === "sequence")) {
698
+ const groups = this.group_osises_by_semicolon(osises);
699
+ if (groups.length > 1) {
700
+ for (const group of Array.from(groups)) {
701
+ if (group.length === 0) {
702
+ continue;
703
+ }
704
+ const group_last_i = group.length - 1;
705
+ const indices = [group[0].indices[0], group[group_last_i].indices[1]];
706
+ if ((group[group_last_i].enclosed_indices != null) && (group[group_last_i].enclosed_indices[1] >= 0)) {
707
+ indices[1] = group[group_last_i].enclosed_indices[1];
708
+ }
709
+ const strings = [];
710
+ let osises_by_chapter = [];
711
+ for (osis of Array.from(group)) {
712
+ if (osis.osis.length > 0) {
713
+ strings.push(osis.osis);
714
+ }
715
+ if (osis.osises != null) {
716
+ osises_by_chapter = osises_by_chapter.concat(osis.osises);
717
+ }
718
+ }
719
+ const out_entry = { osis: strings.join(","), indices, translations, entity_id, entities: group };
720
+ if (osises_by_chapter.length > 0) {
721
+ out_entry.osises = osises_by_chapter;
722
+ }
723
+ out.push(out_entry);
724
+ }
725
+ continue;
726
+ }
727
+ }
676
728
  var osis;
677
729
  var strings = [];
678
730
  var last_i = osises.length - 1;
@@ -685,7 +737,19 @@ class bcv_parser {
685
737
  strings.push(osis.osis);
686
738
  }
687
739
  }
688
- out.push({ osis: strings.join(","), indices: entity.absolute_indices, translations, entity_id, entities: osises });
740
+ let osises_by_chapter = [];
741
+ if (this.options.consecutive_combination_strategy === "separate-chapters") {
742
+ for (osis of Array.from(osises)) {
743
+ if (osis.osises != null) {
744
+ osises_by_chapter = osises_by_chapter.concat(osis.osises);
745
+ }
746
+ }
747
+ }
748
+ const out_entry = { osis: strings.join(","), indices: entity.absolute_indices, translations, entity_id, entities: osises };
749
+ if (osises_by_chapter.length > 0) {
750
+ out_entry.osises = osises_by_chapter;
751
+ }
752
+ out.push(out_entry);
689
753
  }
690
754
  }
691
755
  return out;
@@ -765,6 +829,96 @@ class bcv_parser {
765
829
  }
766
830
  return out;
767
831
  }
832
+ get_osises_by_chapter(passage, translation) {
833
+ if ((passage == null) || (passage.start == null) || (passage.end == null)) {
834
+ return [];
835
+ }
836
+ if ((passage.start.b == null) || (passage.end.b == null) || (passage.start.c == null) || (passage.end.c == null)) {
837
+ return (passage.osis != null) && (passage.osis.length > 0) ? [passage.osis] : [];
838
+ }
839
+ if ((passage.start.b !== passage.end.b) || (passage.start.c === passage.end.c)) {
840
+ return (passage.osis != null) && (passage.osis.length > 0) ? [passage.osis] : [];
841
+ }
842
+ const out = [];
843
+ for (let c = passage.start.c, end = passage.end.c, asc = passage.start.c <= end; asc ? c <= end : c >= end; asc ? c++ : c--) {
844
+ const passageStartVerse = c === passage.start.c ? passage.start.v : 1;
845
+ const passageEndVerse = c === passage.end.c ? passage.end.v : this.translations[translation].chapters[passage.start.b][c - 1];
846
+ const passageStart = {
847
+ b: passage.start.b,
848
+ c,
849
+ v: passage.start.type === "bcv" ? passageStartVerse : null,
850
+ type: passage.start.type
851
+ };
852
+ const passageEnd = {
853
+ b: passage.end.b,
854
+ c,
855
+ v: passage.start.type === "bcv" ? passageEndVerse : null,
856
+ type: passage.start.type
857
+ };
858
+ out.push(this.to_osis(passageStart, passageEnd, translation));
859
+ }
860
+ return out;
861
+ }
862
+ get_separator_between(prev_indices, next_indices) {
863
+ if ((this.s == null) || (prev_indices == null) || (next_indices == null)) {
864
+ return "";
865
+ }
866
+ const start = prev_indices[1] + 1;
867
+ const end = next_indices[0];
868
+ if (end <= start) {
869
+ return "";
870
+ }
871
+ return this.s.slice(start, end);
872
+ }
873
+ has_semicolon_separator(prev_osis, next_osis) {
874
+ const between = this.get_separator_between(prev_osis.indices, next_osis.indices);
875
+ return /[;;]/.test(between);
876
+ }
877
+ group_osises_by_semicolon(osises) {
878
+ const out = [];
879
+ let current = [];
880
+ for (const osis of Array.from(osises)) {
881
+ if (current.length === 0) {
882
+ current.push(osis);
883
+ continue;
884
+ }
885
+ if (this.has_semicolon_separator(current[current.length - 1], osis)) {
886
+ out.push(current);
887
+ current = [osis];
888
+ }
889
+ else {
890
+ current.push(osis);
891
+ }
892
+ }
893
+ if (current.length > 0) {
894
+ out.push(current);
895
+ }
896
+ return out;
897
+ }
898
+ split_text_by_semicolon(absolute_indices) {
899
+ if ((this.s == null) || (absolute_indices == null) || (absolute_indices[0] == null) || (absolute_indices[1] == null)) {
900
+ return [];
901
+ }
902
+ const text = this.s.slice(absolute_indices[0], absolute_indices[1]);
903
+ if (!/[;;]/.test(text)) {
904
+ return [{ text, offset: absolute_indices[0] }];
905
+ }
906
+ const segments = [];
907
+ let start = 0;
908
+ for (let i = 0, end = text.length; i < end; i++) {
909
+ const ch = text[i];
910
+ if ((ch === ";") || (ch === ";")) {
911
+ if (i > start) {
912
+ segments.push({ text: text.slice(start, i), offset: absolute_indices[0] + start });
913
+ }
914
+ start = i + 1;
915
+ }
916
+ }
917
+ if (start < text.length) {
918
+ segments.push({ text: text.slice(start), offset: absolute_indices[0] + start });
919
+ }
920
+ return segments;
921
+ }
768
922
  // If we want to treat Ps151 as a book rather than a chapter, we have to do some gymnastics to make sure it returns properly.
769
923
  fix_ps151(start, end, translation) {
770
924
  // Ps151 doesn't necessarily get promoted into the translation chapter list because during the string parsing, we treat it as `Ps` rather than `Ps151`.
@@ -809,6 +963,11 @@ class bcv_parser {
809
963
  if (osis.osis.length > 0) {
810
964
  var prev_i = out.length - 1;
811
965
  var is_enclosed_last = false;
966
+ if ((prev_i >= 0) && this.has_semicolon_separator(out[prev_i], osis)) {
967
+ out.push(osis);
968
+ prev = { b: osis.end.b, c: osis.end.c, v: osis.end.v };
969
+ continue;
970
+ }
812
971
  // Record the start index of the enclosed sequence for use in future iterations.
813
972
  if (osis.enclosed_indices[0] !== enclosed_sequence_start) {
814
973
  enclosed_sequence_start = osis.enclosed_indices[0];
@@ -2549,8 +2708,8 @@ bcv_parser.prototype.regexps.pre_book = "[^A-Za-zªµºÀ-ÖØ-öø-ɏḀ-ỿⱠ
2549
2708
  bcv_parser.prototype.regexps.first = `(?:Eerste|1e|I|1)\\.?${bcv_parser.prototype.regexps.space}*`;
2550
2709
  bcv_parser.prototype.regexps.second = `(?:Tweede|2e|II|2)\\.?${bcv_parser.prototype.regexps.space}*`;
2551
2710
  bcv_parser.prototype.regexps.third = `(?:Derde|3e|III|3)\\.?${bcv_parser.prototype.regexps.space}*`;
2552
- bcv_parser.prototype.regexps.range_and = "(?:[&\\u2013\\u2014-]|(?:en|vgl|zie${bcv_parser.prototype.regexps.space}+ook)|-)";
2553
- bcv_parser.prototype.regexps.range_only = "(?:[\\u2013\\u2014-]|-)";
2711
+ bcv_parser.prototype.regexps.range_and = `(?:[&\\u2013\\u2014-]|(?:en|vgl|zie${bcv_parser.prototype.regexps.space}+ook)|-)`;
2712
+ bcv_parser.prototype.regexps.range_only = `(?:[\\u2013\\u2014-]|-)`;
2554
2713
  // Each book regexp should return two parenthesized objects: an optional preliminary character and the book itself.
2555
2714
  bcv_parser.prototype.regexps.get_books = function (include_apocrypha, case_sensitive) {
2556
2715
  const books = [