UNPKG

bible-ref-parse

Version:

Identifies and parses Bible references (like John 3:16) in over 40 languages.

1 lines 102 kB
const root=this;class bcv_parser{static initClass(){this.prototype.s="",this.prototype.entities=[],this.prototype.passage=null,this.prototype.regexps={},this.prototype.options={consecutive_combination_strategy:"combine",osis_compaction_strategy:"b",book_sequence_strategy:"ignore",invalid_sequence_strategy:"ignore",sequence_combination_strategy:"combine",punctuation_strategy:"us",invalid_passage_strategy:"ignore",non_latin_digits_strategy:"ignore",passage_existence_strategy:"bcv",zero_chapter_strategy:"error",zero_verse_strategy:"error",single_chapter_1_strategy:"chapter",book_alone_strategy:"ignore",book_range_strategy:"ignore",captive_end_digits_strategy:"delete",end_range_digits_strategy:"verse",include_apocrypha:!1,ps151_strategy:"c",versification_system:"default",case_sensitive:"none"}}constructor(){for(var e of(this.options={},Object.keys(bcv_parser.prototype.options||{}))){var t=bcv_parser.prototype.options[e];this.options[e]=t}this.versification_system(this.options.versification_system)}parse(e){return this.reset(),this.s=e,e=this.replace_control_characters(e),[e,this.passage.books]=Array.from(this.match_books(e)),[this.entities]=Array.from(this.match_passages(e)),this}parse_with_context(e,t){let s;return this.reset(),[t,this.passage.books]=Array.from(this.match_books(this.replace_control_characters(t))),[s,t]=Array.from(this.match_passages(t)),this.reset(),this.s=e,e=this.replace_control_characters(e),[e,this.passage.books]=Array.from(this.match_books(e)),this.passage.books.push({value:"",parsed:[],start_index:0,type:"context",context:t}),e=""+(this.passage.books.length-1)+"/9"+e,[this.entities]=Array.from(this.match_passages(e)),this}reset(){return this.s="",this.entities=[],this.passage?(this.passage.books=[],this.passage.indices={}):(this.passage=new bcv_passage,this.passage.options=this.options,this.passage.translations=this.translations)}set_options(e){for(var t of Object.keys(e||{})){var s=e[t];"include_apocrypha"===t||"versification_system"===t||"case_sensitive"===t?this[t](s):this.options[t]=s}return this}include_apocrypha(e){if(null==e||!0!==e&&!1!==e)return this;for(var t of(this.options.include_apocrypha=e,this.regexps.books=this.regexps.get_books(e,this.options.case_sensitive),Object.keys(this.translations||{}))){var s;if("aliases"!==t&&"alternates"!==t)if(null==this.translations[t].chapters&&(this.translations[t].chapters={}),null==this.translations[t].chapters.Ps&&(this.translations[t].chapters.Ps=bcv_utils.shallow_clone_book_data(this.translations.default.chapters.Ps)),!0===e)s=null!=this.translations[t].chapters.Ps151?bcv_utils.get_book_verse_count(this.translations[t].chapters.Ps151,1):bcv_utils.get_book_verse_count(this.translations.default.chapters.Ps151,1),bcv_utils.set_book_verse_count(this.translations[t].chapters.Ps,151,s);else 151===bcv_utils.get_book_chapter_count(this.translations[t].chapters.Ps)&&bcv_utils.delete_book_verse_count(this.translations[t].chapters.Ps,151)}return this}versification_system(e){let t,s;if(null==e||null==this.translations[e])return this;if(null!=this.translations.alternates.default)if("default"===e)for(t of(null!=this.translations.alternates.default.order&&(this.translations.default.order=bcv_utils.shallow_clone(this.translations.alternates.default.order)),Object.keys(this.translations.alternates.default.chapters||{})))s=this.translations.alternates.default.chapters[t],this.translations.default.chapters[t]=bcv_utils.shallow_clone_book_data(s);else this.versification_system("default");if(null==this.translations.alternates.default&&(this.translations.alternates.default={order:null,chapters:{}}),"default"!==e&&null!=this.translations[e].order&&(null==this.translations.alternates.default.order&&(this.translations.alternates.default.order=bcv_utils.shallow_clone(this.translations.default.order)),this.translations.default.order=bcv_utils.shallow_clone(this.translations[e].order)),"default"!==e&&null!=this.translations[e].chapters)for(t of Object.keys(this.translations[e].chapters||{}))s=this.translations[e].chapters[t],null==this.translations.alternates.default.chapters[t]&&(this.translations.alternates.default.chapters[t]=bcv_utils.shallow_clone_book_data(this.translations.default.chapters[t])),this.translations.default.chapters[t]=bcv_utils.shallow_clone_book_data(s);return this.options.versification_system=e,this.include_apocrypha(this.options.include_apocrypha),this}case_sensitive(e){return null==e||"none"!==e&&"books"!==e||e===this.options.case_sensitive||(this.options.case_sensitive=e,this.regexps.books=this.regexps.get_books(this.options.include_apocrypha,e)),this}translation_info(e){let t;null==e&&(e="default"),null!=e&&null!=(null!=this.translations.aliases[e]?this.translations.aliases[e].alias:void 0)&&(e=this.translations.aliases[e].alias),null!=e&&null!=this.translations[e]||(e="default");const s=this.options.versification_system;e!==s&&this.versification_system(e);const r={alias:e,books:[],chapters:{},order:bcv_utils.shallow_clone(this.translations.default.order)};for(t of Object.keys(this.translations.default.chapters||{})){var a=this.translations.default.chapters[t];r.chapters[t]=bcv_utils.shallow_clone_book_data(a)}for(t of Object.keys(r.order||{})){var n=r.order[t];r.books[n-1]=t}return e!==s&&this.versification_system(s),r}replace_control_characters(e){return e=(e=(e=e.replace(this.regexps.control," ")).replace(/\uFF1A/g,":")).replace(/\uFF1B/g,";"),"replace"===this.options.non_latin_digits_strategy&&(e=(e=(e=(e=(e=(e=(e=(e=(e=(e=e.replace(/[٠۰߀०০੦૦୦0౦೦൦๐໐༠၀႐០᠐᥆᧐᪀᪐᭐᮰᱀᱐꘠꣐꤀꧐꩐꯰0]/g,"0")).replace(/[١۱߁१১੧૧୧௧౧೧൧๑໑༡၁႑១᠑᥇᧑᪁᪑᭑᮱᱁᱑꘡꣑꤁꧑꩑꯱1]/g,"1")).replace(/[٢۲߂२২੨૨୨௨౨೨൨๒໒༢၂႒២᠒᥈᧒᪂᪒᭒᮲᱂᱒꘢꣒꤂꧒꩒꯲2]/g,"2")).replace(/[٣۳߃३৩੩૩୩௩౩೩൩๓໓༣၃႓៣᠓᥉᧓᪃᪓᭓᮳᱃᱓꘣꣓꤃꧓꩓꯳3]/g,"3")).replace(/[٤۴߄४৪੪૪୪௪౪೪൪๔໔༤၄႔៤᠔᥊᧔᪄᪔᭔᮴᱄᱔꘤꣔꤄꧔꩔꯴4]/g,"4")).replace(/[٥۵߅५৫੫૫୫௫౫೫൫๕໕༥၅႕៥᠕᥋᧕᪅᪕᭕᮵᱅᱕꘥꣕꤅꧕꩕꯵5]/g,"5")).replace(/[٦۶߆६৬੬૬୬௬౬೬൬๖໖༦၆႖៦᠖᥌᧖᪆᪖᭖᮶᱆᱖꘦꣖꤆꧖꩖꯶6]/g,"6")).replace(/[٧۷߇७৭੭૭୭௭౭೭൭๗໗༧၇႗៧᠗᥍᧗᪇᪗᭗᮷᱇᱗꘧꣗꤇꧗꩗꯷7]/g,"7")).replace(/[٨۸߈८৮੮૮୮௮౮೮൮๘໘༨၈႘៨᠘᥎᧘᪈᪘᭘᮸᱈᱘꘨꣘꤈꧘꩘꯸8]/g,"8")).replace(/[٩۹߉९৯੯૯୯௯౯೯൯๙໙༩၉႙៩᠙᥏᧙᪉᪙᭙᮹᱉᱙꘩꣙꤉꧙꩙꯹9]/g,"9")),e}match_books(e){const t=[];for(var s of Array.from(this.regexps.books)){var r=!1;if(e=e.replace(s.regexp,(function(e,a,n){r=!0,t.push({value:n,parsed:s.osis,type:"book"});const o=null!=s.extra?`/${s.extra}`:"";return`${a}${t.length-1}${o}`})),!0===r&&/^[\s\x1f\d:.,;\-\u2013\u2014]+$/.test(e))break}return[e=e.replace(this.regexps.translations,(function(e){return t.push({value:e,parsed:e.toLowerCase(),type:"translation"}),`${t.length-1}`})),this.get_book_indices(t,e)]}get_book_indices(e,t){let s,r=0;const a=new RegExp("([\\x1f\\x1e])(\\d+)(?:/\\d+)?\\1","g");for(;s=a.exec(t);)e[s[2]].start_index=s.index+r,r+=e[s[2]].value.length-s[0].length;return e}match_passages(e){let t,s=[],r={};for(;t=this.regexps.escaped_passage.exec(e);){let _;var[a,n,o]=Array.from(t),i=n.length;if(t.index+=a.length-i,/\s[2-9]\d\d\s*$|\s\d{4,}\s*$/.test(n)&&(n=n.replace(/\s+\d+\s*$/,"")),/[\d\x1f\x1e)]$/.test(n)||(n=this.replace_match_end(n)),"delete"===this.options.captive_end_digits_strategy){var u=t.index+n.length;e.length>u&&/^\w/.test(e.substr(u,1))&&(n=n.replace(/[\s*]+\d+$/,"")),n=n.replace(/(\x1e[)\]]?)[\s*]*\d+$/,"$1")}var l=""===(n=n.replace(/[A-Z]+/g,(e=>e.toLowerCase()))).substr(0,1)?0:n.split("")[0].length,c={value:grammar.parse(n,{punctuation_strategy:this.options.punctuation_strategy}),type:"base",start_index:this.passage.books[o].start_index-l,match:n};"full"===this.options.book_alone_strategy&&"include"===this.options.book_range_strategy&&"b"===c.value[0].type&&(1===c.value.length||c.value.length>1&&"translation_sequence"===c.value[1].type)&&0===l&&(1===this.passage.books[o].parsed.length||this.passage.books[o].parsed.length>1&&"translation"===this.passage.books[o].parsed[1].type)&&/^[234]/.test(this.passage.books[o].parsed[0])&&this.create_book_range(e,c,o),[_,r]=Array.from(this.passage.handle_obj(c)),s=s.concat(_);var p=this.adjust_regexp_end(_,i,n.length);p>0&&(this.regexps.escaped_passage.lastIndex-=p)}return[s,r]}adjust_regexp_end(e,t,s){let r=0;return e.length>0?r=t-e[e.length-1].indices[1]-1:t!==s&&(r=t-s),r}replace_match_end(e){let t,s=e.length;for(;t=this.regexps.match_end_split.exec(e);)s=t.index+t[0].length;return s<e.length&&(e=e.substr(0,s)),e}create_book_range(e,t,s){const r=[bcv_parser.prototype.regexps.first,bcv_parser.prototype.regexps.second,bcv_parser.prototype.regexps.third],a=parseInt(this.passage.books[s].parsed[0].substr(0,1),10);for(let i=1,u=a,l=1<=u;l?i<u:i>u;l?i++:i--){var n=i===a-1?bcv_parser.prototype.regexps.range_and:bcv_parser.prototype.regexps.range_only,o=e.match(new RegExp(`(?:^|\\W)(${r[i-1]}\\s*${n}\\s*)\\x1f${s}\\x1f`,"i"));if(null!=o)return this.add_book_range_object(t,o,i)}return!1}add_book_range_object(e,t,s){const{length:r}=t[1];if(e.value[0]={type:"b_range_pre",value:[{type:"b_pre",value:s.toString(),indices:[t.index,t.index+r]},e.value[0]],indices:[0,e.value[0].indices[1]+r]},e.value[0].value[1].indices[0]+=r,e.value[0].value[1].indices[1]+=r,e.start_index-=r,e.match=t[1]+e.match,1!==e.value.length)return(()=>{const t=[];for(let s=1,a=e.value.length,n=1<=a;n?s<a:s>a;n?s++:s--)null!=e.value[s].value&&(null!=(null!=e.value[s].value[0]?e.value[s].value[0].indices:void 0)&&(e.value[s].value[0].indices[0]+=r,e.value[s].value[0].indices[1]+=r),e.value[s].indices[0]+=r,t.push(e.value[s].indices[1]+=r));return t})()}osis(){const e=[];for(var t of Array.from(this.parsed_entities()))t.osis.length>0&&e.push(t.osis);return e.join(",")}osis_and_translations(){const e=[];for(var t of Array.from(this.parsed_entities()))t.osis.length>0&&e.push([t.osis,t.translations.join(",")]);return e}osis_and_indices(){const e=[];for(var t of Array.from(this.parsed_entities()))if(t.osis.length>0){const s={osis:t.osis,translations:t.translations,indices:t.indices};null!=t.osises&&(s.osises=t.osises),e.push(s)}return e}parsed_entities(){let e=[];for(let d=0,x=this.entities.length,b=0<=x;b?d<x:d>x;b?d++:d--){var t=this.entities[d];if(t.type&&"translation_sequence"===t.type&&e.length>0&&d===e[e.length-1].entity_id+1&&(e[e.length-1].indices[1]=t.absolute_indices[1]),null!=t.passages&&!("b"===t.type&&"ignore"===this.options.book_alone_strategy||"b_range"===t.type&&"ignore"===this.options.book_range_strategy||"context"===t.type)){var s=[],r=null;if(null!=t.passages[0].translations)for(var a of Array.from(t.passages[0].translations)){var n=(null!=a.osis?a.osis.length:void 0)>0?a.osis:"";null==r&&(r=a.alias),s.push(n)}else s=[""],r="default";for(var o=[],i=[],{length:u}=t.passages,l=0,c=l,p=u,_=0<=p;_?l<p:l>p;_?l++:l--,c=l){var g=t.passages[c];null==g.type&&(g.type=t.type),!1===g.valid.valid&&("ignore"===this.options.invalid_sequence_strategy&&"sequence"===t.type&&this.snap_sequence("ignore",t,o,c,u),"ignore"===this.options.invalid_passage_strategy)||("b"!==g.type&&"b_range"!==g.type||"ignore"!==this.options.book_sequence_strategy||"sequence"!==t.type?("b_range_start"!==g.type&&"range_end_b"!==g.type||"ignore"!==this.options.book_range_strategy||this.snap_range(t,c),null==g.absolute_indices&&(g.absolute_indices=t.absolute_indices),"separate-chapters"===this.options.consecutive_combination_strategy&&g.start.c!==g.end.c?o.push({osis:g.valid.valid?this.to_osis(g.start,g.end,r):"",osises:this.get_osises_by_chapter({osis:"",start:g.start,end:g.end},r),type:g.type,indices:g.absolute_indices,translations:s,start:g.start,end:g.end,enclosed_indices:g.enclosed_absolute_indices,entity_id:d,entities:[g]}):o.push({osis:g.valid.valid?this.to_osis(g.start,g.end,r):"",type:g.type,indices:g.absolute_indices,translations:s,start:g.start,end:g.end,enclosed_indices:g.enclosed_absolute_indices,entity_id:d,entities:[g]})):this.snap_sequence("book",t,o,c,u))}if(0!==o.length||0!==i.length){if("combine"!==this.options.consecutive_combination_strategy&&"separate-chapters"!==this.options.consecutive_combination_strategy||(o.length>1&&(o=this.combine_consecutive_passages(o,r)),o=o.concat(i).sort(((e,t)=>e.indices[0]-t.indices[0]))),"separate-chapters"===this.options.consecutive_combination_strategy)for(h of Array.from(o)){if(0===h.osis.length)continue;const e=this.get_osises_by_chapter(h,r);e.length>1&&(h.osises=e)}if("separate"===this.options.sequence_combination_strategy)e=e.concat(o);else{if("separate-chapters"===this.options.consecutive_combination_strategy&&"sequence"===t.type){const t=this.group_osises_by_semicolon(o);if(t.length>1){for(const r of Array.from(t)){if(0===r.length)continue;if(r.length>1){for(h of Array.from(r)){if(0===h.osis.length)continue;const t={osis:h.osis,indices:h.indices,translations:s,entity_id:d,entities:[h]};null!=h.osises&&(t.osises=h.osises),e.push(t)}continue}const t=r.length-1,a=[r[0].indices[0],r[t].indices[1]];null!=r[t].enclosed_indices&&r[t].enclosed_indices[1]>=0&&(a[1]=r[t].enclosed_indices[1]);const n=[];let o=[];for(h of Array.from(r))h.osis.length>0&&n.push(h.osis),null!=h.osises&&(o=o.concat(h.osises));const i={osis:n.join(","),indices:a,translations:s,entity_id:d,entities:r};o.length>0&&(i.osises=o),e.push(i)}continue}}var h,f=[],v=o.length-1;for(h of(null!=o[v].enclosed_indices&&o[v].enclosed_indices[1]>=0&&(t.absolute_indices[1]=o[v].enclosed_indices[1]),Array.from(o)))h.osis.length>0&&f.push(h.osis);let r=[];if("separate-chapters"===this.options.consecutive_combination_strategy)for(h of Array.from(o))null!=h.osises&&(r=r.concat(h.osises));const a={osis:f.join(","),indices:t.absolute_indices,translations:s,entity_id:d,entities:o};r.length>0&&(a.osises=r),e.push(a)}}}}return e}to_osis(e,t,s){let r;null==t.c&&null==t.v&&e.b===t.b&&null==e.c&&null==e.v&&"first_chapter"===this.options.book_alone_strategy&&(t.c=1);const a={start:"",end:""};if(null==e.c&&(e.c=1),null==e.v&&(e.v=1),null==t.c&&(this.options.passage_existence_strategy.indexOf("c")>=0||null!=this.passage.translations[s].chapters[t.b]&&1===bcv_utils.get_book_chapter_count(this.passage.translations[s].chapters[t.b])?t.c=bcv_utils.get_book_chapter_count(this.passage.translations[s].chapters[t.b]):t.c=999),null==t.v){const e=bcv_utils.get_book_verse_count(this.passage.translations[s].chapters[t.b],t.c);null!=e&&this.options.passage_existence_strategy.indexOf("v")>=0?t.v=e:t.v=999}return this.options.include_apocrypha&&"b"===this.options.ps151_strategy&&(151===e.c&&"Ps"===e.b||151===t.c&&"Ps"===t.b)&&this.fix_ps151(e,t,s),"b"===this.options.osis_compaction_strategy&&1===e.c&&1===e.v&&(999===t.c&&999===t.v||t.c===bcv_utils.get_book_chapter_count(this.passage.translations[s].chapters[t.b])&&this.options.passage_existence_strategy.indexOf("c")>=0&&(999===t.v||t.v===bcv_utils.get_book_verse_count(this.passage.translations[s].chapters[t.b],t.c)&&this.options.passage_existence_strategy.indexOf("v")>=0))?(a.start=e.b,a.end=t.b):this.options.osis_compaction_strategy.length<=2&&1===e.v&&(999===t.v||t.v===bcv_utils.get_book_verse_count(this.passage.translations[s].chapters[t.b],t.c)&&this.options.passage_existence_strategy.indexOf("v")>=0)?(a.start=e.b+"."+e.c.toString(),a.end=t.b+"."+t.c.toString()):(a.start=e.b+"."+e.c.toString()+"."+e.v.toString(),a.end=t.b+"."+t.c.toString()+"."+t.v.toString()),r=a.start===a.end?a.start:a.start+"-"+a.end,null!=e.extra&&(r=e.extra+","+r),null!=t.extra&&(r+=","+t.extra),r}get_osises_by_chapter(e,t){if(null==e||null==e.start||null==e.end)return[];if(null==e.start.b||null==e.end.b||null==e.start.c||null==e.end.c)return null!=e.osis&&e.osis.length>0?[e.osis]:[];if(e.start.b!==e.end.b||e.start.c===e.end.c)return null!=e.osis&&e.osis.length>0?[e.osis]:[];const s=[];for(let r=e.start.c,a=e.end.c,n=e.start.c<=a;n?r<=a:r>=a;n?r++:r--){const a=r===e.start.c?e.start.v:1,n=r===e.end.c?e.end.v:bcv_utils.get_book_verse_count(this.translations[t].chapters[e.start.b],r),o={b:e.start.b,c:r,v:"bcv"===e.start.type?a:null,type:e.start.type},i={b:e.end.b,c:r,v:"bcv"===e.start.type?n:null,type:e.start.type};s.push(this.to_osis(o,i,t))}return s}get_separator_between(e,t){if(null==this.s||null==e||null==t)return"";const s=e[1],r=t[0];return r<=s?"":this.s.slice(s,r)}has_semicolon_separator(e,t){const s=this.get_separator_between(e.indices,t.indices);return/[;;]/.test(s)}group_osises_by_semicolon(e){const t=[];let s=[];for(const r of Array.from(e))0!==s.length&&this.has_semicolon_separator(s[s.length-1],r)?(t.push(s),s=[r]):s.push(r);return s.length>0&&t.push(s),t}fix_ps151(e,t,s){return"default"!==s&&null==(null!=this.translations[s]?this.translations[s].chapters.Ps151:void 0)&&this.passage.promote_book_to_translation("Ps151",s),151===e.c&&"Ps"===e.b?151===t.c&&"Ps"===t.b?(e.b="Ps151",e.c=1,t.b="Ps151",t.c=1):(e.extra=this.to_osis({b:"Ps151",c:1,v:e.v},{b:"Ps151",c:1,v:bcv_utils.get_book_verse_count(this.passage.translations[s].chapters.Ps151,1)},s),e.b="Prov",e.c=1,e.v=1):(t.extra=this.to_osis({b:"Ps151",c:1,v:1},{b:"Ps151",c:1,v:t.v},s),t.c=150,t.v=bcv_utils.get_book_verse_count(this.passage.translations[s].chapters.Ps,150))}combine_consecutive_passages(e,t){const s=[];let r={};const a=e.length-1;let n=-1,o=!1;for(let c=0,p=a,_=0<=p;_?c<=p:c>=p;_?c++:c--){var i=e[c];if(i.osis.length>0){var u=s.length-1,l=!1;if(u>=0&&this.has_semicolon_separator(s[u],i)){s.push(i),r={b:i.end.b,c:i.end.c,v:i.end.v};continue}i.enclosed_indices[0]!==n&&(n=i.enclosed_indices[0]),n>=0&&(c===a||e[c+1].enclosed_indices[0]!==i.enclosed_indices[0])&&(l=!0,o=!0),this.is_verse_consecutive(r,i.start,t)?(s[u].end=i.end,s[u].is_enclosed_last=l,s[u].indices[1]=i.indices[1],s[u].enclosed_indices[1]=i.enclosed_indices[1],s[u].osis=this.to_osis(s[u].start,i.end,t)):s.push(i),r={b:i.end.b,c:i.end.c,v:i.end.v}}else s.push(i),r={}}return o&&this.snap_enclosed_indices(s),s}snap_enclosed_indices(e){for(var t of Array.from(e))null!=t.is_enclosed_last&&(t.enclosed_indices[0]<0&&t.is_enclosed_last&&(t.indices[1]=t.enclosed_indices[1]),delete t.is_enclosed_last);return e}is_verse_consecutive(e,t,s){if(null==e.b)return!1;const r=null!=this.passage.translations[s].order?this.passage.translations[s].order:this.passage.translations.default.order;if(e.b===t.b){if(e.c===t.c){if(e.v===t.v-1)return!0}else if(1===t.v&&e.c===t.c-1&&e.v===bcv_utils.get_book_verse_count(this.passage.translations[s].chapters[e.b],e.c))return!0}else if(1===t.c&&1===t.v&&r[e.b]===r[t.b]-1&&e.c===bcv_utils.get_book_chapter_count(this.passage.translations[s].chapters[e.b])&&e.v===bcv_utils.get_book_verse_count(this.passage.translations[s].chapters[e.b],e.c))return!0;return!1}snap_range(e,t){let s,r,a;"b_range_start"===e.type||"sequence"===e.type&&"b_range_start"===e.passages[t].type?(s=1,r="end",a="b_range_start"):(s=0,r="start",a="range_end_b");const n="end"===r?"start":"end";for(var o of Object.keys(e.passages[t][n]||{}))e.passages[t][n][o]=e.passages[t][r][o];if("sequence"===e.type){t>=e.value.length&&(t=e.value.length-1);const s=this.passage.pluck(a,e.value[t]);if(null!=s){const r=this.snap_range(s,0);0===t?e.absolute_indices[0]=r.absolute_indices[0]:e.absolute_indices[1]=r.absolute_indices[1]}}else e.original_type=e.type,e.type=e.value[s].type,e.absolute_indices=[e.value[s].absolute_indices[0],e.value[s].absolute_indices[1]];return e}snap_sequence(e,t,s,r,a){const n=t.passages[r];return n.absolute_indices[0]===t.absolute_indices[0]&&r<a-1&&this.get_snap_sequence_i(t.passages,r,a)!==r?(t.absolute_indices[0]=t.passages[r+1].absolute_indices[0],this.remove_absolute_indices(t.passages,r+1)):n.absolute_indices[1]===t.absolute_indices[1]&&r>0?t.absolute_indices[1]=s.length>0?s[s.length-1].indices[1]:t.passages[r-1].absolute_indices[1]:"book"===e&&r<a-1&&!this.starts_with_book(t.passages[r+1])&&(t.passages[r+1].absolute_indices[0]=n.absolute_indices[0]),t}get_snap_sequence_i(e,t,s){for(let r=t+1,a=r,n=s,o=r<=n;o?a<n:a>n;o?a++:a--){if(this.starts_with_book(e[a]))return a;if(e[a].valid.valid)return t}return t}starts_with_book(e){return"b"===e.type.substr(0,1)||("range"===e.type||"ff"===e.type)&&"b"===e.start.type.substr(0,1)}remove_absolute_indices(e,t){if(e[t].enclosed_absolute_indices[0]<0)return!1;const[s,r]=Array.from(e[t].enclosed_absolute_indices);for(var a of Array.from(e.slice(t))){if(a.enclosed_absolute_indices[0]!==s||a.enclosed_absolute_indices[1]!==r)break;a.enclosed_absolute_indices=[-1,-1]}return!0}}bcv_parser.initClass(),this.bcv_parser=bcv_parser;class bcv_passage{static initClass(){this.prototype.books=[],this.prototype.indices={},this.prototype.options={},this.prototype.translations={}}handle_array(e,t,s){for(var r of(null==t&&(t=[]),null==s&&(s={}),Array.from(e)))if(null!=r){if("stop"===r.type)break;[t,s]=Array.from(this.handle_obj(r,t,s))}return[t,s]}handle_obj(e,t,s){return null!=e.type&&null!=this[e.type]?this[e.type](e,t,s):[t,s]}b(e,t,s){let r;e.start_context=bcv_utils.shallow_clone(s),e.passages=[];const a=[];for(r of Array.from(this.books[e.value].parsed)){var n=this.validate_ref(e.start_context.translations,{b:r}),o={start:{b:r},end:{b:r},valid:n};0===e.passages.length&&n.valid?e.passages.push(o):a.push(o)}return 0===e.passages.length&&e.passages.push(a.shift()),a.length>0&&(e.passages[0].alternates=a),null!=e.start_context.translations&&(e.passages[0].translations=e.start_context.translations),null==e.absolute_indices&&(e.absolute_indices=this.get_absolute_indices(e.indices)),t.push(e),s={b:e.passages[0].start.b},null!=e.start_context.translations&&(s.translations=e.start_context.translations),[t,s]}b_range(e,t,s){return this.range(e,t,s)}b_range_pre(e,t,s){let r,a;e.start_context=bcv_utils.shallow_clone(s),e.passages=[];const n=this.pluck("b",e.value);r=this.b(n,[],s),[a]=Array.from(r[0]),s=r[1],null==e.absolute_indices&&(e.absolute_indices=this.get_absolute_indices(e.indices));const o={b:e.value[0].value+a.passages[0].start.b.substr(1),type:"b"};return e.passages=[{start:o,end:a.passages[0].end,valid:a.passages[0].valid}],null!=e.start_context.translations&&(e.passages[0].translations=e.start_context.translations),t.push(e),[t,s]}b_range_start(e,t,s){return this.range(e,t,s)}base(e,t,s){return this.indices=this.calculate_indices(e.match,e.start_index),this.handle_array(e.value,t,s)}bc(e,t,s){e.start_context=bcv_utils.shallow_clone(s),e.passages=[],this.reset_context(s,["b","c","v"]);const r=this.pluck("c",e.value).value,a=[];for(var n of Array.from(this.books[this.pluck("b",e.value).value].parsed)){var o="c",i=this.validate_ref(e.start_context.translations,{b:n,c:r}),u={start:{b:n},end:{b:n},valid:i};(i.messages.start_chapter_not_exist_in_single_chapter_book||i.messages.start_chapter_1)&&(u.valid=this.validate_ref(e.start_context.translations,{b:n,v:r}),i.messages.start_chapter_not_exist_in_single_chapter_book&&(u.valid.messages.start_chapter_not_exist_in_single_chapter_book=1),u.start.c=1,u.end.c=1,o="v"),u.start[o]=r,[u.start.c,u.start.v]=Array.from(this.fix_start_zeroes(u.valid,u.start.c,u.start.v)),null==u.start.v&&delete u.start.v,u.end[o]=u.start[o],0===e.passages.length&&u.valid.valid?e.passages.push(u):a.push(u)}return 0===e.passages.length&&e.passages.push(a.shift()),a.length>0&&(e.passages[0].alternates=a),null!=e.start_context.translations&&(e.passages[0].translations=e.start_context.translations),null==e.absolute_indices&&(e.absolute_indices=this.get_absolute_indices(e.indices)),this.set_context_from_object(s,["b","c","v"],e.passages[0].start),t.push(e),[t,s]}bc_title(e,t,s){let r,a;if(e.start_context=bcv_utils.shallow_clone(s),r=this.bc(this.pluck("bc",e.value),[],s),[a]=Array.from(r[0]),s=r[1],"Ps"!==a.passages[0].start.b.substr(0,2)&&null!=a.passages[0].alternates)for(let e=0,t=a.passages[0].alternates.length,s=0<=t;s?e<t:e>t;s?e++:e--)if("Ps"===a.passages[0].alternates[e].start.b.substr(0,2)){a.passages[0]=a.passages[0].alternates[e];break}if("Ps"!==a.passages[0].start.b.substr(0,2))return t.push(a),[t,s];this.books[this.pluck("b",a.value).value].parsed=["Ps"];let n=this.pluck("title",e.value);return null==n&&(n=this.pluck("v",e.value)),e.value[1]={type:"v",value:[{type:"integer",value:1,indices:n.indices}],indices:n.indices},e.type="bcv",this.bcv(e,t,e.start_context)}bcv(e,t,s){e.start_context=bcv_utils.shallow_clone(s),e.passages=[],this.reset_context(s,["b","c","v"]);const r=this.pluck("bc",e.value);let a=this.pluck("c",r.value).value,n=this.pluck("v",e.value).value;const o=[];for(var i of Array.from(this.books[this.pluck("b",r.value).value].parsed)){var u=this.validate_ref(e.start_context.translations,{b:i,c:a,v:n});[a,n]=Array.from(this.fix_start_zeroes(u,a,n));var l={start:{b:i,c:a,v:n},end:{b:i,c:a,v:n},valid:u};0===e.passages.length&&u.valid?e.passages.push(l):o.push(l)}return 0===e.passages.length&&e.passages.push(o.shift()),o.length>0&&(e.passages[0].alternates=o),null!=e.start_context.translations&&(e.passages[0].translations=e.start_context.translations),null==e.absolute_indices&&(e.absolute_indices=this.get_absolute_indices(e.indices)),this.set_context_from_object(s,["b","c","v"],e.passages[0].start),t.push(e),[t,s]}bv(e,t,s){let r;e.start_context=bcv_utils.shallow_clone(s);const[a,n]=Array.from(e.value);let o={indices:e.indices,value:[{type:"bc",value:[a,{type:"c",value:[{type:"integer",value:1}]}]},n]};return r=this.bcv(o,[],s),[o]=Array.from(r[0]),s=r[1],e.passages=o.passages,null==e.absolute_indices&&(e.absolute_indices=this.get_absolute_indices(e.indices)),t.push(e),[t,s]}c(e,t,s){e.start_context=bcv_utils.shallow_clone(s);let r="integer"===e.type?e.value:this.pluck("integer",e.value).value;const a=this.validate_ref(e.start_context.translations,{b:s.b,c:r});return!a.valid&&a.messages.start_chapter_not_exist_in_single_chapter_book?this.v(e,t,s):([r]=Array.from(this.fix_start_zeroes(a,r)),e.passages=[{start:{b:s.b,c:r},end:{b:s.b,c:r},valid:a}],null!=e.start_context.translations&&(e.passages[0].translations=e.start_context.translations),t.push(e),s.c=r,this.reset_context(s,["v"]),null==e.absolute_indices&&(e.absolute_indices=this.get_absolute_indices(e.indices)),[t,s])}c_psalm(e,t,s){e.type="bc";const r=parseInt(this.books[e.value].value.match(/^\d+/)[0],10);return e.value=[{type:"b",value:e.value,indices:e.indices},{type:"c",value:[{type:"integer",value:r,indices:e.indices}],indices:e.indices}],this.bc(e,t,s)}c_title(e,t,s){if(e.start_context=bcv_utils.shallow_clone(s),"Ps"!==s.b)return this.c(e.value[0],t,s);const r=this.pluck("title",e.value);return e.value[1]={type:"v",value:[{type:"integer",value:1,indices:r.indices}],indices:r.indices},e.type="cv",this.cv(e,t,e.start_context)}cv(e,t,s){e.start_context=bcv_utils.shallow_clone(s);let r=this.pluck("c",e.value).value,a=this.pluck("v",e.value).value;const n=this.validate_ref(e.start_context.translations,{b:s.b,c:r,v:a});return[r,a]=Array.from(this.fix_start_zeroes(n,r,a)),e.passages=[{start:{b:s.b,c:r,v:a},end:{b:s.b,c:r,v:a},valid:n}],null!=e.start_context.translations&&(e.passages[0].translations=e.start_context.translations),t.push(e),s.c=r,s.v=a,null==e.absolute_indices&&(e.absolute_indices=this.get_absolute_indices(e.indices)),[t,s]}cb_range(e,t,s){e.type="range";const[r,a,n]=Array.from(e.value);return e.value=[{type:"bc",value:[r,a],indices:e.indices},n],n.indices[1]=e.indices[1],this.range(e,t,s)}context(e,t,s){for(var r of(e.start_context=bcv_utils.shallow_clone(s),e.passages=[],Object.keys(this.books[e.value].context||{})))s[r]=this.books[e.value].context[r];return t.push(e),[t,s]}cv_psalm(e,t,s){e.start_context=bcv_utils.shallow_clone(s),e.type="bcv";const[r,a]=Array.from(e.value),n=this.c_psalm(r,[],e.start_context),[o]=Array.from(n[0]);return e.value=[o,a],this.bcv(e,t,s)}ff(e,t,s){let r;return e.start_context=bcv_utils.shallow_clone(s),e.value.push({type:"integer",indices:e.indices,value:999}),r=this.range(e,[],e.start_context),[e]=Array.from(r[0]),s=r[1],e.value[0].indices=e.value[1].indices,e.value[0].absolute_indices=e.value[1].absolute_indices,e.value.pop(),null!=e.passages[0].valid.messages.end_verse_not_exist&&delete e.passages[0].valid.messages.end_verse_not_exist,null!=e.passages[0].valid.messages.end_chapter_not_exist&&delete e.passages[0].valid.messages.end_chapter_not_exist,null!=e.passages[0].end.original_c&&delete e.passages[0].end.original_c,t.push(e),[t,s]}integer_title(e,t,s){return e.start_context=bcv_utils.shallow_clone(s),"Ps"!==s.b?this.integer(e.value[0],t,s):(e.value[0]={type:"c",value:[e.value[0]],indices:[e.value[0].indices[0],e.value[0].indices[1]]},e.value[1].type="v",e.value[1].original_type="title",e.value[1].value=[{type:"integer",value:1,indices:e.value[1].value.indices}],e.type="cv",this.cv(e,t,e.start_context))}integer(e,t,s){return null!=s.v?this.v(e,t,s):this.c(e,t,s)}next_v(e,t,s){let r,a;e.start_context=bcv_utils.shallow_clone(s);let n=this.pluck_last_recursively("integer",e.value);if(null==n&&(n={value:1}),e.value.push({type:"integer",indices:e.indices,value:n.value+1}),r=this.range(e,[],e.start_context),[a]=Array.from(r[0]),s=r[1],null!=a.passages[0].valid.messages.end_verse_not_exist&&null==a.passages[0].valid.messages.start_verse_not_exist&&null==a.passages[0].valid.messages.start_chapter_not_exist&&null!=s.c){let t;e.value.pop(),e.value.push({type:"cv",indices:e.indices,value:[{type:"c",value:[{type:"integer",value:s.c+1,indices:e.indices}],indices:e.indices},{type:"v",value:[{type:"integer",value:1,indices:e.indices}],indices:e.indices}]}),t=this.range(e,[],e.start_context),[a]=Array.from(t[0]),s=t[1]}return a.value[0].indices=a.value[1].indices,a.value[0].absolute_indices=a.value[1].absolute_indices,a.value.pop(),null!=a.passages[0].valid.messages.end_verse_not_exist&&delete a.passages[0].valid.messages.end_verse_not_exist,null!=a.passages[0].valid.messages.end_chapter_not_exist&&delete a.passages[0].valid.messages.end_chapter_not_exist,null!=a.passages[0].end.original_c&&delete a.passages[0].end.original_c,t.push(a),[t,s]}sequence(e,t,s){for(var r of(e.start_context=bcv_utils.shallow_clone(s),e.passages=[],Array.from(e.value))){var a,n;for(var o of(a=this.handle_array(r,[],s),[n]=Array.from(a[0]),s=a[1],Array.from(n.passages)))null==o.type&&(o.type=n.type),null==o.absolute_indices&&(o.absolute_indices=n.absolute_indices),null!=n.start_context.translations&&(o.translations=n.start_context.translations),o.enclosed_absolute_indices="sequence_post_enclosed"===n.type?n.absolute_indices:[-1,-1],e.passages.push(o)}return null==e.absolute_indices&&(e.passages.length>0&&"sequence"===e.type?e.absolute_indices=[e.passages[0].absolute_indices[0],e.passages[e.passages.length-1].absolute_indices[1]]:e.absolute_indices=this.get_absolute_indices(e.indices)),t.push(e),[t,s]}sequence_post_enclosed(e,t,s){return this.sequence(e,t,s)}v(e,t,s){let r,a="integer"===e.type?e.value:this.pluck("integer",e.value).value;e.start_context=bcv_utils.shallow_clone(s);const n=null!=s.c?s.c:1,o=this.validate_ref(e.start_context.translations,{b:s.b,c:n,v:a});return[r,a]=Array.from(this.fix_start_zeroes(o,0,a)),e.passages=[{start:{b:s.b,c:n,v:a},end:{b:s.b,c:n,v:a},valid:o}],null!=e.start_context.translations&&(e.passages[0].translations=e.start_context.translations),null==e.absolute_indices&&(e.absolute_indices=this.get_absolute_indices(e.indices)),t.push(e),s.v=a,[t,s]}range(e,t,s){let r,a;e.start_context=bcv_utils.shallow_clone(s);let[n,o]=Array.from(e.value);if(r=this.handle_obj(n,[],s),[n]=Array.from(r[0]),s=r[1],"v"===o.type&&("bc"===n.type&&!__guard__(__guard__(__guard__(null!=n.passages?n.passages[0]:void 0,(e=>e.valid)),(e=>e.messages)),(e=>e.start_chapter_not_exist_in_single_chapter_book))||"c"===n.type)&&"verse"===this.options.end_range_digits_strategy)return e.value[0]=n,this.range_change_integer_end(e,t);a=this.handle_obj(o,[],s),[o]=Array.from(a[0]),s=a[1],e.value=[n,o],e.indices=[n.indices[0],o.indices[1]],delete e.absolute_indices;const i={b:n.passages[0].start.b,c:n.passages[0].start.c,v:n.passages[0].start.v,type:n.type},u={b:o.passages[0].end.b,c:o.passages[0].end.c,v:o.passages[0].end.v,type:o.type};o.passages[0].valid.messages.start_chapter_is_zero&&(u.c=0),o.passages[0].valid.messages.start_verse_is_zero&&(u.v=0);const l=this.validate_ref(e.start_context.translations,i,u);if(!l.valid)return this.range_handle_invalid(l,e,n,i,o,u,t);{const[s,r]=Array.from(this.range_handle_valid(l,e,n,i,o,u,t));if(s)return r}return null==e.absolute_indices&&(e.absolute_indices=this.get_absolute_indices(e.indices)),e.passages=[{start:i,end:u,valid:l}],null!=e.start_context.translations&&(e.passages[0].translations=e.start_context.translations),"b"===i.type?"b"===u.type?e.type="b_range":e.type="b_range_start":"b"===u.type&&(e.type="range_end_b"),t.push(e),[t,s]}range_change_end(e,t,s){let r;const[a,n]=Array.from(e.value);return"integer"===n.type?(n.original_value=n.value,n.value=s):"v"===n.type?(r=this.pluck("integer",n.value),r.original_value=r.value,r.value=s):"cv"===n.type&&(r=this.pluck("c",n.value),r.original_value=r.value,r.value=s),this.handle_obj(e,t,e.start_context)}range_change_integer_end(e,t){const[s,r]=Array.from(e.value);return null==e.original_type&&(e.original_type=e.type),null==e.original_value&&(e.original_value=[s,r]),e.type="integer"===s.type?"cv":s.type+"v","integer"===s.type&&(e.value[0]={type:"c",value:[s],indices:s.indices}),"integer"===r.type&&(e.value[1]={type:"v",value:[r],indices:r.indices}),this.handle_obj(e,t,e.start_context)}range_check_new_end(e,t,s,r){let a=0,n=null;if(r.messages.end_chapter_before_start?n="c":r.messages.end_verse_before_start&&(n="v"),null!=n&&(a=this.range_get_new_end_value(t,s,r,n)),a>0){const t={b:s.b,c:s.c,v:s.v};t[n]=a;this.validate_ref(e,t).valid||(a=0)}return a}range_end_b(e,t,s){return this.range(e,t,s)}range_get_new_end_value(e,t,s,r){let a=0;return"c"===r&&s.messages.end_chapter_is_zero||"v"===r&&s.messages.end_verse_is_zero||(e[r]>=10&&t[r]<10&&e[r]-10*Math.floor(e[r]/10)<t[r]?a=t[r]+10*Math.floor(e[r]/10):e[r]>=100&&t[r]<100&&e[r]-100<t[r]&&(a=t[r]+100)),a}range_handle_invalid(e,t,s,r,a,n,o){if(!1===e.valid&&(e.messages.end_chapter_before_start||e.messages.end_verse_before_start)&&("integer"===a.type||"v"===a.type)||!1===e.valid&&e.messages.end_chapter_before_start&&"cv"===a.type){const s=this.range_check_new_end(t.start_context.translations,r,n,e);if(s>0)return this.range_change_end(t,o,s)}if("verse"===this.options.end_range_digits_strategy&&null==r.v&&("integer"===a.type||"v"===a.type)){const e="v"===a.type?this.pluck("integer",a.value):a.value;if(this.validate_ref(t.start_context.translations,{b:r.b,c:r.c,v:e}).valid)return this.range_change_integer_end(t,o)}return null==t.original_type&&(t.original_type=t.type),t.type="sequence",[t.original_value,t.value]=Array.from([[s,a],[[s],[a]]]),this.sequence(t,o,t.start_context)}range_handle_valid(e,t,s,r,a,n,o){if(e.messages.end_chapter_not_exist&&"verse"===this.options.end_range_digits_strategy&&null==r.v&&("integer"===a.type||"v"===a.type)&&this.options.passage_existence_strategy.indexOf("v")>=0){const e="v"===a.type?this.pluck("integer",a.value):a.value;if(this.validate_ref(t.start_context.translations,{b:r.b,c:r.c,v:e}).valid)return[!0,this.range_change_integer_end(t,o)]}return this.range_validate(e,r,n,t),[!1,null]}range_validate(e,t,s,r){return e.messages.end_chapter_not_exist||e.messages.end_chapter_not_exist_in_single_chapter_book?(s.original_c=s.c,s.c=e.messages.end_chapter_not_exist?e.messages.end_chapter_not_exist:e.messages.end_chapter_not_exist_in_single_chapter_book,null!=s.v&&(s.v=this.validate_ref(r.start_context.translations,{b:s.b,c:s.c,v:999}).messages.end_verse_not_exist,delete e.messages.end_verse_is_zero)):e.messages.end_verse_not_exist&&(s.original_v=s.v,s.v=e.messages.end_verse_not_exist),e.messages.end_verse_is_zero&&"allow"!==this.options.zero_verse_strategy&&(s.v=e.messages.end_verse_is_zero),e.messages.end_chapter_is_zero&&(s.c=e.messages.end_chapter_is_zero),[t.c,t.v]=Array.from(this.fix_start_zeroes(e,t.c,t.v)),!0}translation_sequence(e,t,s){e.start_context=bcv_utils.shallow_clone(s);const r=[];for(var a of(r.push({translation:this.books[e.value[0].value].parsed}),Array.from(e.value[1])))null!=(a=this.books[this.pluck("translation",a).value].parsed)&&r.push({translation:a});for(var n of Array.from(r))null!=this.translations.aliases[n.translation]?(n.alias=this.translations.aliases[n.translation].alias,n.osis=this.translations.aliases[n.translation].osis||n.translation.toUpperCase()):(n.alias="default",n.osis=n.translation.toUpperCase());return t.length>0&&(s=this.translation_sequence_apply(t,r)),null==e.absolute_indices&&(e.absolute_indices=this.get_absolute_indices(e.indices)),t.push(e),this.reset_context(s,["translations"]),[t,s]}translation_sequence_apply(e,t){let s,r=0;for(let t=e.length-1,s=t,a=t<=0;a?s<=0:s>=0;a?s++:s--)if(null!=e[s].original_type&&(e[s].type=e[s].original_type),null!=e[s].original_value&&(e[s].value=e[s].original_value),"translation_sequence"===e[s].type){r=s+1;break}if(r<e.length){let a;e[r].start_context.translations=t,[a,s]=Array.from(this.handle_array(e.slice(r),[],e[r].start_context))}else s=bcv_utils.shallow_clone(e[e.length-1].start_context);return s}pluck(e,t){for(var s of Array.from(t))if(null!=s&&null!=s.type&&s.type===e)return"c"===e||"v"===e?this.pluck("integer",s.value):s;return null}pluck_last_recursively(e,t){for(let a=t.length-1;a>=0;a--){var s=t[a];if(null!=s&&null!=s.type){if(s.type===e)return this.pluck(e,[s]);var r=this.pluck_last_recursively(e,s.value);if(null!=r)return r}}return null}set_context_from_object(e,t,s){return(()=>{const r=[];for(var a of Array.from(t))null!=s[a]&&r.push(e[a]=s[a]);return r})()}reset_context(e,t){return Array.from(t).map((t=>delete e[t]))}fix_start_zeroes(e,t,s){return e.messages.start_chapter_is_zero&&"upgrade"===this.options.zero_chapter_strategy&&(t=e.messages.start_chapter_is_zero),e.messages.start_verse_is_zero&&"upgrade"===this.options.zero_verse_strategy&&(s=e.messages.start_verse_is_zero),[t,s]}calculate_indices(e,t){let s,r="book";const a=[];let n=0;t=parseInt(t,10);let o=[e];for(var i of["",""]){var u=[];for(s of Array.from(o))u=u.concat(s.split(i));o=u}for(s of Array.from(o)){var l;r="book"===r?"rest":"book";var c=s.length;0!==c&&("book"===r?(s=s.replace(/\/\d+$/,""),l=n+c,a.length>0&&a[a.length-1].index===t?a[a.length-1].end=l:a.push({start:n,end:l,index:t}),n+=c+2,t=this.books[s].start_index+this.books[s].value.length-n,a.push({start:l+1,end:l+1,index:t})):(l=n+c-1,a.length>0&&a[a.length-1].index===t?a[a.length-1].end=l:a.push({start:n,end:l,index:t}),n+=c))}return a}get_absolute_indices(...e){const[t,s]=Array.from(e[0]);let r=null,a=null;for(var n of Array.from(this.indices))if(null===r&&n.start<=t&&t<=n.end&&(r=t+n.index),n.start<=s&&s<=n.end){a=s+n.index+1;break}return[r,a]}validate_ref(e,t,s){null!=e&&e.length>0||(e=[{translation:"default",osis:"",alias:"default"}]);let r=!1;const a={};for(var n of Array.from(e))if(null==n.alias&&(n.alias="default"),null!=n.alias){null==this.translations.aliases[n.alias]&&(n.alias="default",null==a.translation_unknown&&(a.translation_unknown=[]),a.translation_unknown.push(n));var[o]=Array.from(this.validate_start_ref(n.alias,t,a));s&&([o]=Array.from(this.validate_end_ref(n.alias,t,s,o,a))),!0===o&&(r=!0)}else null==a.translation_invalid&&(a.translation_invalid=[]),a.translation_invalid.push(n);return{valid:r,messages:a}}validate_start_ref(e,t,s){let r,a,n=!0;"default"!==e&&null==(null!=this.translations[e]?this.translations[e].chapters[t.b]:void 0)&&this.promote_book_to_translation(t.b,e);const o=null!=(null!=this.translations[e]?this.translations[e].order:void 0)?e:"default";if(null!=t.v&&(t.v=parseInt(t.v,10)),null!=this.translations[o].order[t.b]){if(null==t.c&&(t.c=1),t.c=parseInt(t.c,10),isNaN(t.c))return n=!1,s.start_chapter_not_numeric=!0,[n,s];0===t.c&&(s.start_chapter_is_zero=1,"error"===this.options.zero_chapter_strategy?n=!1:t.c=1),null!=t.v&&0===t.v&&(s.start_verse_is_zero=1,"error"===this.options.zero_verse_strategy?n=!1:"upgrade"===this.options.zero_verse_strategy&&(t.v=1)),r=bcv_utils.get_book_chapter_count(this.translations[e].chapters[t.b]),a=bcv_utils.get_book_verse_count(this.translations[e].chapters[t.b],t.c),t.c>0&&null!=a?null!=t.v?isNaN(t.v)?(n=!1,s.start_verse_not_numeric=!0):t.v>a&&this.options.passage_existence_strategy.indexOf("v")>=0&&(n=!1,s.start_verse_not_exist=a):1===t.c&&"verse"===this.options.single_chapter_1_strategy&&1===r&&(s.start_chapter_1=1):1!==t.c&&1===r?(n=!1,s.start_chapter_not_exist_in_single_chapter_book=1):t.c>0&&this.options.passage_existence_strategy.indexOf("c")>=0&&(n=!1,s.start_chapter_not_exist=r)}else null==t.b?(n=!1,s.start_book_not_defined=!0):(this.options.passage_existence_strategy.indexOf("b")>=0&&(n=!1),s.start_book_not_exist=!0);return[n,s]}validate_end_ref(e,t,s,r,a){const n=null!=(null!=this.translations[e]?this.translations[e].order:void 0)?e:"default";let o,i;return null!=s.c&&(s.c=parseInt(s.c,10),isNaN(s.c)?(r=!1,a.end_chapter_not_numeric=!0):0===s.c&&(a.end_chapter_is_zero=1,"error"===this.options.zero_chapter_strategy?r=!1:s.c=1)),null!=s.v&&(s.v=parseInt(s.v,10),isNaN(s.v)?(r=!1,a.end_verse_not_numeric=!0):0===s.v&&(a.end_verse_is_zero=1,"error"===this.options.zero_verse_strategy?r=!1:"upgrade"===this.options.zero_verse_strategy&&(s.v=1))),null!=this.translations[n].order[s.b]?(o=bcv_utils.get_book_chapter_count(this.translations[e].chapters[s.b]),null==s.c&&1===o&&(s.c=1),null!=this.translations[n].order[t.b]&&this.translations[n].order[t.b]>this.translations[n].order[s.b]&&(this.options.passage_existence_strategy.indexOf("b")>=0&&(r=!1),a.end_book_before_start=!0),t.b!==s.b||null==s.c||isNaN(s.c)||(null==t.c&&(t.c=1),!isNaN(parseInt(t.c,10))&&t.c>s.c?(r=!1,a.end_chapter_before_start=!0):t.c!==s.c||null==s.v||isNaN(s.v)||(null==t.v&&(t.v=1),!isNaN(parseInt(t.v,10))&&t.v>s.v&&(r=!1,a.end_verse_before_start=!0))),null==s.c||isNaN(s.c)||(i=bcv_utils.get_book_verse_count(this.translations[e].chapters[s.b],s.c),null==i&&(1===o?a.end_chapter_not_exist_in_single_chapter_book=1:s.c>0&&this.options.passage_existence_strategy.indexOf("c")>=0&&(a.end_chapter_not_exist=o))),null==s.v||isNaN(s.v)||(null==s.c&&(s.c=o),i=bcv_utils.get_book_verse_count(this.translations[e].chapters[s.b],s.c),null!=i&&s.v>i&&this.options.passage_existence_strategy.indexOf("v")>=0&&(a.end_verse_not_exist=i))):(r=!1,a.end_book_not_exist=!0),[r,a]}promote_book_to_translation(e,t){if(null==this.translations[t]&&(this.translations[t]={}),null==this.translations[t].chapters&&(this.translations[t].chapters={}),null==this.translations[t].chapters[e])return this.translations[t].chapters[e]=bcv_utils.shallow_clone_book_data(this.translations.default.chapters[e])}}function __guard__(e,t){return null!=e?t(e):void 0}bcv_passage.initClass();const bcv_utils={shallow_clone(e){if(null==e)return e;const t={};for(const s of Object.keys(e||{})){const r=e[s];t[s]=r}return t},shallow_clone_array(e){if(null==e)return e;const t=[];for(let s=0,r=e.length,a=0<=r;a?s<=r:s>=r;a?s++:s--)void 0!==e[s]&&(t[s]=e[s]);return t},shallow_clone_book_data(e){if(null==e)return e;if(Array.isArray(e))return this.shallow_clone_array(e);const t=this.shallow_clone(e);return null!=e.versesCount&&(t.versesCount=this.shallow_clone(e.versesCount)),t},get_book_chapter_count:e=>null==e?0:Array.isArray(e)?e.length:null!=e.chaptersCount?e.chaptersCount:Object.keys(e.versesCount||{}).length,get_book_verse_count:(e,t)=>null==e||null==t?null:Array.isArray(e)?e[t-1]:null==e.versesCount?null:null!=e.versesCount[t]?e.versesCount[t]:e.versesCount[String(t)],set_book_verse_count:(e,t,s)=>Array.isArray(e)?(e[t-1]=s,e):(null==e.versesCount&&(e.versesCount={}),e.versesCount[String(t)]=s,(null==e.chaptersCount||t>e.chaptersCount)&&(e.chaptersCount=t),e),delete_book_verse_count(e,t){if(null==e)return e;if(Array.isArray(e))return e.length===t?e.pop():delete e[t-1],e;if(null!=e.versesCount&&delete e.versesCount[String(t)],e.chaptersCount===t)for(;e.chaptersCount>0&&null==this.get_book_verse_count(e,e.chaptersCount);)e.chaptersCount-=1;return e}};bcv_parser.prototype.regexps.translations=RegExp("(?:(?:BYSB))\\b","gi"),bcv_parser.prototype.translations={aliases:{default:{osis:"",alias:"default"}},alternates:{},default:{order:{Gen:1,Exod:2,Lev:3,Num:4,Deut:5,Josh:6,Judg:7,Ruth:8,"1Sam":9,"2Sam":10,"1Kgs":11,"2Kgs":12,"1Chr":13,"2Chr":14,Ezra:15,Neh:16,Esth:17,Job:18,Ps:19,Prov:20,Eccl:21,Song:22,Isa:23,Jer:24,Lam:25,Ezek:26,Dan:27,Hos:28,Joel:29,Amos:30,Obad:31,Jonah:32,Mic:33,Nah:34,Hab:35,Zeph:36,Hag:37,Zech:38,Mal:39,Matt:40,Mark:41,Luke:42,John:43,Acts:44,Rom:45,"1Cor":46,"2Cor":47,Gal:48,Eph:49,Phil:50,Col:51,"1Thess":52,"2Thess":53,"1Tim":54,"2Tim":55,Titus:56,Phlm:57,Heb:58,Jas:59,"1Pet":60,"2Pet":61,"1John":62,"2John":63,"3John":64,Jude:65,Rev:66,Tob:67,Jdt:68,GkEsth:69,Wis:70,Sir:71,Bar:72,PrAzar:73,Sus:74,Bel:75,SgThree:76,EpJer:77,"1Macc":78,"2Macc":79,"3Macc":80,"4Macc":81,"1Esd":82,"2Esd":83,PrMan:84},chapters:{Gen:{chaptersCount:50,versesCount:{1:31,2:25,3:24,4:26,5:32,6:22,7:24,8:22,9:29,10:32,11:32,12:20,13:18,14:24,15:21,16:16,17:27,18:33,19:38,20:18,21:34,22:24,23:20,24:67,25:34,26:35,27:46,28:22,29:35,30:43,31:54,32:33,33:20,34:31,35:29,36:43,37:36,38:30,39:23,40:23,41:57,42:38,43:34,44:34,45:28,46:34,47:31,48:22,49:33,50:26}},Exod:{chaptersCount:40,versesCount:{1:22,2:25,3:22,4:31,5:23,6:30,7:29,8:28,9:35,10:29,11:10,12:51,13:22,14:31,15:27,16:36,17:16,18:27,19:25,20:26,21:37,22:30,23:33,24:18,25:40,26:37,27:21,28:43,29:46,30:38,31:18,32:35,33:23,34:35,35:35,36:38,37:29,38:31,39:43,40:38}},Lev:{chaptersCount:27,versesCount:{1:17,2:16,3:17,4:35,5:26,6:23,7:38,8:36,9:24,10:20,11:47,12:8,13:59,14:57,15:33,16:34,17:16,18:30,19:37,20:27,21:24,22:33,23:44,24:23,25:55,26:46,27:34}},Num:{chaptersCount:36,versesCount:{1:54,2:34,3:51,4:49,5:31,6:27,7:89,8:26,9:23,10:36,11:35,12:16,13:33,14:45,15:41,16:35,17:28,18:32,19:22,20:29,21:35,22:41,23:30,24:25,25:18,26:65,27:23,28:31,29:39,30:17,31:54,32:42,33:56,34:29,35:34,36:13}},Deut:{chaptersCount:34,versesCount:{1:46,2:37,3:29,4:49,5:33,6:25,7:26,8:20,9:29,10:22,11:32,12:31,13:19,14:29,15:23,16:22,17:20,18:22,19:21,20:20,21:23,22:29,23:26,24:22,25:19,26:19,27:26,28:69,29:28,30:20,31:30,32:52,33:29,34:12}},Josh:{chaptersCount:24,versesCount:{1:18,2:24,3:17,4:24,5:15,6:27,7:26,8:35,9:27,10:43,11:23,12:24,13:33,14:15,15:63,16:10,17:18,18:28,19:51,20:9,21:45,22:34,23:16,24:33}},Judg:{chaptersCount:21,versesCount:{1:36,2:23,3:31,4:24,5:31,6:40,7:25,8:35,9:57,10:18,11:40,12:15,13:25,14:20,15:20,16:31,17:13,18:31,19:30,20:48,21:25}},Ruth:{chaptersCount:4,versesCount:{1:22,2:23,3:18,4:22}},"1Sam":{chaptersCount:31,versesCount:{1:28,2:36,3:21,4:22,5:12,6:21,7:17,8:22,9:27,10:27,11:15,12:25,13:23,14:52,15:35,16:23,17:58,18:30,19:24,20:42,21:16,22:23,23:28,24:23,25:44,26:25,27:12,28:25,29:11,30:31,31:13}},"2Sam":{chaptersCount:24,versesCount:{1:27,2:32,3:39,4:12,5:25,6:23,7:29,8:18,9:13,10:19,11:27,12:31,13:39,14:33,15:37,16:23,17:29,18:32,19:44,20:26,21:22,22:51,23:39,24:25}},"1Kgs":{chaptersCount:22,versesCount:{1:53,2:46,3:28,4:20,5:32,6:38,7:51,8:66,9:28,10:29,11:43,12:33,13:34,14:31,15:34,16:34,17:24,18:46,19:21,20:43,21:29,22:54}},"2Kgs":{chaptersCount:25,versesCount:{1:18,2:25,3:27,4:44,5:27,6:33,7:20,8:29,9:37,10:36,11:20,12:22,13:25,14:29,15:38,16:20,17:41,18:37,19:37,20:21,21:26,22:20,23:37,24:20,25:30}},"1Chr":{chaptersCount:29,versesCount:{1:54,2:55,3:24,4:43,5:41,6:66,7:40,8:40,9:44,10:14,11:47,12:41,13:14,14:17,15:29,16:43,17:27,18:17,19:19,20:8,21:30,22:19,23:32,24:31,25:31,26:32,27:34,28:21,29:30}},"2Chr":{chaptersCount:36,versesCount:{1:18,2:17,3:17,4:22,5:14,6:42,7:22,8:18,9:31,10:19,11:23,12:16,13:23,14:14,15:19,16:14,17:19,18:34,19:11,20:37,21:20,22:12,23:21,24:27,25:28,26:23,27:9,28:27,29:36,30:27,31:21,32:33,33:25,34:33,35:27,36:23}},Ezra:{chaptersCount:10,versesCount:{1:11,2:70,3:13,4:24,5:17,6:22,7:28,8:36,9:15,10:44}},Neh:{chaptersCount:13,versesCount:{1:11,2:20,3:38,4:17,5:19,6:19,7:73,8:18,9:37,10:40,11:36,12:47,13:31}},Esth:{chaptersCount:10,versesCount:{1:22,2:23,3:15,4:17,5:14,6:14,7:10,8:17,9:32,10:3}},Job:{chaptersCount:42,versesCount:{1:22,2:13,3:26,4:21,5:27,6:30,7:21,8:22,9:35,10:22,11:20,12:25,13:28,14:22,15:35,16:22,17:16,18:21,19:29,20:29,21:32,22:30,23:17,24:25,25:6,26:14,27:23,28:28,29:25,30:31,31:40,32:22,33:33,34:37,35:16,36:33,37:24,38:41,39:30,40:32,41:26,42:17}},Ps:{chaptersCount:150,versesCount:{1:6,2:12,3:9,4:9,5:13,6:11,7:18,8:10,9:21,10:18,11:7,12:9,13:6,14:7,15:5,16:11,17:15,18:51,19:15,20:10,21:14,22:32,23:6,24:10,25:22,26:12,27:14,28:9,29:11,30:13,31:25,32:11,33:22,34:23,35:28,36:13,37:40,38:23,39:14,40:18,41:14,42:12,43:5,44:27,45:18,46:12,47:10,48:15,49:19,50:23,51:21,52:11,53:7,54:9,55:24,56:14,57:12,58:12,59:18,60:14,61:9,62:13,63:12,64:11,65:14,66:20,67:8,68:36,69:37,70:6,71:24,72:20,73:28,74:23,75:11,76:13,77:21,78:72,79:13,80:20,81:17,82:8,83:19,84:13,85:14,86:17,87:7,88:19,89:53,90:17,91:16,92:16,93:5,94:23,95:11,96:13,97:12,98:9,99:9,100:5,101:8,102:29,103:22,104:35,105:45,106:48,107:43,108:14,109:31,110:7,111:10,112:10,113:9,114:8,115:18,116:19,117:2,118:29,119:176,120:7,121:8,122:9,123:4,124:8,125:5,126:6,127:5,128:6,129:8,130:8,131:3,132:18,133:3,134:3,135:21,136:26,137:9,138:8,139:24,140:14,141:10,142:8,143:12,144:15,145:21,146:10,147:20,148:14,149:9,150:6}},Prov:{chaptersCount:31,versesCount:{1:33,2:22,3:35,4:27,5:23,6:35,7:27,8:36,9:18,10:31,11:31,12:28,13:25,14:35,15:33,16:33,17:28,18:24,19:29,20:30,21:31,22:29,23:35,24:34,25:28,26:28,27:27,28:28,29:27,30:33,31:31}},Eccl:{chaptersCount:12,versesCount:{1:18,2:26,3:22,4:17,5:19,6:12,7:29,8:17,9:18,10:20,11:10,12:14}},Song:{chaptersCount:8,versesCount:{1:17,2:17,3:11,4:16,5:16,6:12,7:14,8:14}},Isa:{chaptersCount:66,versesCount:{1:31,2:22,3:26,4:6,5:30,6:13,7:25,8:23,9:20,10:34,11:16,12:6,13:22,14:32,15:9,16:14,17:14,18:7,19:25,20:6,21:17,22:25,23:18,24:23,25:12,26:21,27:13,28:29,29:24,30:33,31:9,32:20,33:24,34:17,35:10,36:22,37:38,38:22,39:8,40:31,41:29,42:25,43:28,44:28,45:25,46:13,47:15,48:22,49:26,50:11,51:23,52:15,53:12,54:17,55:13,56:12,57:21,58:14,59:21,60:22,61:11,62:12,63:19,64:11,65:25,66:24}},Jer:{chaptersCount:52,versesCount:{1:19,2:37,3:25,4:31,5:31,6:30,7:34,8:23,9:25,10:25,11:23,12:17,13:27,14:22,15:21,16:21,17:27,18:23,19:15,20:18,21:14,22:30,23:40,24:10,25:38,26:24,27:22,28:17,29:32,30:24,31:40,32:44,33:26,34:22,35:19,36:32,37:21,38:28,39:18,40:16,41:18,42:22,43:13