awoken-bible-reference
Version:
Bible verse reference parser, generator and manipulator
1 lines • 49.4 kB
JavaScript
var AwokenRef;!function(){var e={864:function(e){"undefined"!=typeof self&&self,e.exports=function(e){var r={};function t(n){if(r[n])return r[n].exports;var s=r[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,t),s.l=!0,s.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){"use strict";function n(e){if(!(this instanceof n))return new n(e);this._=e}var s=n.prototype;function o(e,r){for(var t=0;t<e;t++)r(t)}function i(e,r,t){return function(e,r){o(r.length,(function(t){e(r[t],t,r)}))}((function(t,n,s){r=e(r,t,n,s)}),t),r}function a(e,r){return i((function(r,t,n,s){return r.concat([e(t,n,s)])}),[],r)}function c(e,r){var t={v:0,buf:r};return o(e,(function(){var e;t={v:t.v<<1|(e=t.buf,e[0]>>7),buf:function(e){var r=i((function(e,r,t,n){return e.concat(t===n.length-1?Buffer.from([r,0]).readUInt16BE(0):n.readUInt16BE(t))}),[],e);return Buffer.from(a((function(e){return(e<<1&65535)>>8}),r))}(t.buf)}})),t}function u(){return"undefined"!=typeof Buffer}function f(){if(!u())throw new Error("Buffer global does not exist; please use webpack if you need to parse Buffers in the browser.")}function h(e){f();var r=i((function(e,r){return e+r}),0,e);if(r%8!=0)throw new Error("The bits ["+e.join(", ")+"] add up to "+r+" which is not an even number of bytes; the total should be divisible by 8");var t,s=r/8,o=(t=function(e){return e>48},i((function(e,r){return e||(t(r)?r:e)}),null,e));if(o)throw new Error(o+" bit range requested exceeds 48 bit (6 byte) Number max.");return new n((function(r,t){var n=s+t;return n>r.length?y(t,s.toString()+" bytes"):w(n,i((function(e,r){var t=c(r,e.buf);return{coll:e.coll.concat(t.v),buf:t.buf}}),{coll:[],buf:r.slice(t,n)},e).coll)}))}function l(e,r){return new n((function(t,n){return f(),n+r>t.length?y(n,r+" bytes for "+e):w(n+r,t.slice(n,n+r))}))}function d(e,r){if("number"!=typeof(t=r)||Math.floor(t)!==t||r<0||r>6)throw new Error(e+" requires integer length in range [0, 6].");var t}function p(e){return d("uintBE",e),l("uintBE("+e+")",e).map((function(r){return r.readUIntBE(0,e)}))}function v(e){return d("uintLE",e),l("uintLE("+e+")",e).map((function(r){return r.readUIntLE(0,e)}))}function b(e){return d("intBE",e),l("intBE("+e+")",e).map((function(r){return r.readIntBE(0,e)}))}function m(e){return d("intLE",e),l("intLE("+e+")",e).map((function(r){return r.readIntLE(0,e)}))}function g(e){return e instanceof n}function k(e){return"[object Array]"==={}.toString.call(e)}function _(e){return u()&&Buffer.isBuffer(e)}function w(e,r){return{status:!0,index:e,value:r,furthest:-1,expected:[]}}function y(e,r){return k(r)||(r=[r]),{status:!1,index:-1,value:null,furthest:e,expected:r}}function x(e,r){if(!r)return e;if(e.furthest>r.furthest)return e;var t=e.furthest===r.furthest?function(e,r){if(function(){if(void 0!==n._supportsSet)return n._supportsSet;var e="undefined"!=typeof Set;return n._supportsSet=e,e}()&&Array.from){for(var t=new Set(e),s=0;s<r.length;s++)t.add(r[s]);var o=Array.from(t);return o.sort(),o}for(var i={},a=0;a<e.length;a++)i[e[a]]=!0;for(var c=0;c<r.length;c++)i[r[c]]=!0;var u=[];for(var f in i)({}).hasOwnProperty.call(i,f)&&u.push(f);return u.sort(),u}(e.expected,r.expected):r.expected;return{status:e.status,index:e.index,value:e.value,furthest:r.furthest,expected:t}}var E={};function I(e,r){if(_(e))return{offset:r,line:-1,column:-1};e in E||(E[e]={});for(var t=E[e],n=0,s=0,o=0,i=r;i>=0;){if(i in t){n=t[i].line,0===o&&(o=t[i].lineStart);break}("\n"===e.charAt(i)||"\r"===e.charAt(i)&&"\n"!==e.charAt(i+1))&&(s++,0===o&&(o=i+1)),i--}var a=n+s,c=r-o;return t[r]={line:a,lineStart:o},{offset:r,line:a+1,column:c+1}}function B(e){if(!g(e))throw new Error("not a parser: "+e)}function O(e,r){return"string"==typeof e?e.charAt(r):e[r]}function S(e){if("number"!=typeof e)throw new Error("not a number: "+e)}function P(e){if("function"!=typeof e)throw new Error("not a function: "+e)}function A(e){if("string"!=typeof e)throw new Error("not a string: "+e)}function J(e,r){return new Array(r+1).join(e)}function C(e,r,t){var n=r-e.length;return n<=0?e:J(t,n)+e}function L(e,r,t,n){return{from:e-r>0?e-r:0,to:e+t>n?n:e+t}}function j(e,r){var t,n,s,o,c,u=r.index,f=u.offset,h=1;if(f===e.length)return"Got the end of the input";if(_(e)){var l=f-f%8,d=f-l,p=L(l,40,40,e.length),v=a((function(e){return a((function(e){return C(e.toString(16),2,"0")}),e)}),function(e,r){var t=e.length,n=[],s=0;if(t<=8)return[e.slice()];for(var o=0;o<t;o++)n[s]||n.push([]),n[s].push(e[o]),(o+1)%8==0&&s++;return n}(e.slice(p.from,p.to).toJSON().data));o=function(e){return 0===e.from&&1===e.to?{from:e.from,to:e.to}:{from:e.from/8,to:Math.floor(e.to/8)}}(p),n=l/8,t=3*d,d>=4&&(t+=1),h=2,s=a((function(e){return e.length<=4?e.join(" "):e.slice(0,4).join(" ")+" "+e.slice(4).join(" ")}),v),(c=(8*(o.to>0?o.to-1:o.to)).toString(16).length)<2&&(c=2)}else{var b=e.split(/\r\n|[\n\r\u2028\u2029]/);t=u.column-1,n=u.line-1,o=L(n,2,3,b.length),s=b.slice(o.from,o.to),c=o.to.toString().length}var m=n-o.from;return _(e)&&(c=(8*(o.to>0?o.to-1:o.to)).toString(16).length)<2&&(c=2),i((function(r,n,s){var i,a=s===m,u=a?"> ":" ";return i=_(e)?C((8*(o.from+s)).toString(16),c,"0"):C((o.from+s+1).toString(),c," "),[].concat(r,[u+i+" | "+n],a?[" "+J(" ",c)+" | "+C("",t," ")+J("^",h)]:[])}),[],s).join("\n")}function R(e,r){return["\n","-- PARSING FAILED "+J("-",50),"\n\n",j(e,r),"\n\n",(t=r.expected,1===t.length?"Expected:\n\n"+t[0]:"Expected one of the following: \n\n"+t.join(", ")),"\n"].join("");var t}function M(e){return void 0!==e.flags?e.flags:[e.global?"g":"",e.ignoreCase?"i":"",e.multiline?"m":"",e.unicode?"u":"",e.sticky?"y":""].join("")}function T(){for(var e=[].slice.call(arguments),r=e.length,t=0;t<r;t+=1)B(e[t]);return n((function(t,n){for(var s,o=new Array(r),i=0;i<r;i+=1){if(!(s=x(e[i]._(t,n),s)).status)return s;o[i]=s.value,n=s.index}return x(w(n,o),s)}))}function N(){var e=[].slice.call(arguments);if(0===e.length)throw new Error("seqMap needs at least one argument");var r=e.pop();return P(r),T.apply(null,e).map((function(e){return r.apply(null,e)}))}function D(){var e=[].slice.call(arguments),r=e.length;if(0===r)return U("zero alternates");for(var t=0;t<r;t+=1)B(e[t]);return n((function(r,t){for(var n,s=0;s<e.length;s+=1)if((n=x(e[s]._(r,t),n)).status)return n;return n}))}function H(e,r){return V(e,r).or(q([]))}function V(e,r){return B(e),B(r),N(e,r.then(e).many(),(function(e,r){return[e].concat(r)}))}function G(e){A(e);var r="'"+e+"'";return n((function(t,n){var s=n+e.length,o=t.slice(n,s);return o===e?w(s,o):y(n,r)}))}function K(e,r){!function(e){if(!(e instanceof RegExp))throw new Error("not a regexp: "+e);for(var r=M(e),t=0;t<r.length;t++){var n=r.charAt(t);if("i"!==n&&"m"!==n&&"u"!==n&&"s"!==n)throw new Error('unsupported regexp flag "'+n+'": '+e)}}(e),arguments.length>=2?S(r):r=0;var t=function(e){return RegExp("^(?:"+e.source+")",M(e))}(e),s=""+e;return n((function(e,n){var o=t.exec(e.slice(n));if(o){if(0<=r&&r<=o.length){var i=o[0],a=o[r];return w(n+i.length,a)}return y(n,"valid match group (0 to "+o.length+") in "+s)}return y(n,s)}))}function q(e){return n((function(r,t){return w(t,e)}))}function U(e){return n((function(r,t){return y(t,e)}))}function Z(e){if(g(e))return n((function(r,t){var n=e._(r,t);return n.index=t,n.value="",n}));if("string"==typeof e)return Z(G(e));if(e instanceof RegExp)return Z(K(e));throw new Error("not a string, regexp, or parser: "+e)}function F(e){return B(e),n((function(r,t){var n=e._(r,t),s=r.slice(t,n.index);return n.status?y(t,'not "'+s+'"'):w(t,null)}))}function z(e){return P(e),n((function(r,t){var n=O(r,t);return t<r.length&&e(n)?w(t+1,n):y(t,"a character/byte matching "+e)}))}function W(e,r){arguments.length<2&&(r=e,e=void 0);var t=n((function(e,n){return t._=r()._,t._(e,n)}));return e?t.desc(e):t}function Q(){return U("fantasy-land/empty")}s.parse=function(e){if("string"!=typeof e&&!_(e))throw new Error(".parse must be called with a string or Buffer as its argument");var r,t=this.skip(ee)._(e,0);return r=t.status?{status:!0,value:t.value}:{status:!1,index:I(e,t.furthest),expected:t.expected},delete E[e],r},s.tryParse=function(e){var r=this.parse(e);if(r.status)return r.value;var t=R(e,r),n=new Error(t);throw n.type="ParsimmonError",n.result=r,n},s.assert=function(e,r){return this.chain((function(t){return e(t)?q(t):U(r)}))},s.or=function(e){return D(this,e)},s.trim=function(e){return this.wrap(e,e)},s.wrap=function(e,r){return N(e,this,r,(function(e,r){return r}))},s.thru=function(e){return e(this)},s.then=function(e){return B(e),T(this,e).map((function(e){return e[1]}))},s.many=function(){var e=this;return n((function(r,t){for(var n=[],s=void 0;;){if(!(s=x(e._(r,t),s)).status)return x(w(t,n),s);if(t===s.index)throw new Error("infinite loop detected in .many() parser --- calling .many() on a parser which can accept zero characters is usually the cause");t=s.index,n.push(s.value)}}))},s.tieWith=function(e){return A(e),this.map((function(r){if(function(e){if(!k(e))throw new Error("not an array: "+e)}(r),r.length){A(r[0]);for(var t=r[0],n=1;n<r.length;n++)A(r[n]),t+=e+r[n];return t}return""}))},s.tie=function(){return this.tieWith("")},s.times=function(e,r){var t=this;return arguments.length<2&&(r=e),S(e),S(r),n((function(n,s){for(var o=[],i=void 0,a=void 0,c=0;c<e;c+=1){if(a=x(i=t._(n,s),a),!i.status)return a;s=i.index,o.push(i.value)}for(;c<r&&(a=x(i=t._(n,s),a),i.status);c+=1)s=i.index,o.push(i.value);return x(w(s,o),a)}))},s.result=function(e){return this.map((function(){return e}))},s.atMost=function(e){return this.times(0,e)},s.atLeast=function(e){return N(this.times(e),this.many(),(function(e,r){return e.concat(r)}))},s.map=function(e){P(e);var r=this;return n((function(t,n){var s=r._(t,n);return s.status?x(w(s.index,e(s.value)),s):s}))},s.contramap=function(e){P(e);var r=this;return n((function(t,n){var s=r.parse(e(t.slice(n)));return s.status?w(n+t.length,s.value):s}))},s.promap=function(e,r){return P(e),P(r),this.contramap(e).map(r)},s.skip=function(e){return T(this,e).map((function(e){return e[0]}))},s.mark=function(){return N(X,this,X,(function(e,r,t){return{start:e,value:r,end:t}}))},s.node=function(e){return N(X,this,X,(function(r,t,n){return{name:e,value:t,start:r,end:n}}))},s.sepBy=function(e){return H(this,e)},s.sepBy1=function(e){return V(this,e)},s.lookahead=function(e){return this.skip(Z(e))},s.notFollowedBy=function(e){return this.skip(F(e))},s.desc=function(e){k(e)||(e=[e]);var r=this;return n((function(t,n){var s=r._(t,n);return s.status||(s.expected=e),s}))},s.fallback=function(e){return this.or(q(e))},s.ap=function(e){return N(e,this,(function(e,r){return e(r)}))},s.chain=function(e){var r=this;return n((function(t,n){var s=r._(t,n);return s.status?x(e(s.value)._(t,s.index),s):s}))},s.concat=s.or,s.empty=Q,s.of=q,s["fantasy-land/ap"]=s.ap,s["fantasy-land/chain"]=s.chain,s["fantasy-land/concat"]=s.concat,s["fantasy-land/empty"]=s.empty,s["fantasy-land/of"]=s.of,s["fantasy-land/map"]=s.map;var X=n((function(e,r){return w(r,I(e,r))})),Y=n((function(e,r){return r>=e.length?y(r,"any character/byte"):w(r+1,O(e,r))})),$=n((function(e,r){return w(e.length,e.slice(r))})),ee=n((function(e,r){return r<e.length?y(r,"EOF"):w(r,null)})),re=K(/[0-9]/).desc("a digit"),te=K(/[0-9]*/).desc("optional digits"),ne=K(/[a-z]/i).desc("a letter"),se=K(/[a-z]*/i).desc("optional letters"),oe=K(/\s*/).desc("optional whitespace"),ie=K(/\s+/).desc("whitespace"),ae=G("\r"),ce=G("\n"),ue=G("\r\n"),fe=D(ue,ce,ae).desc("newline"),he=D(fe,ee);n.all=$,n.alt=D,n.any=Y,n.cr=ae,n.createLanguage=function(e){var r={};for(var t in e)({}).hasOwnProperty.call(e,t)&&function(t){r[t]=W((function(){return e[t](r)}))}(t);return r},n.crlf=ue,n.custom=function(e){return n(e(w,y))},n.digit=re,n.digits=te,n.empty=Q,n.end=he,n.eof=ee,n.fail=U,n.formatError=R,n.index=X,n.isParser=g,n.lazy=W,n.letter=ne,n.letters=se,n.lf=ce,n.lookahead=Z,n.makeFailure=y,n.makeSuccess=w,n.newline=fe,n.noneOf=function(e){return z((function(r){return e.indexOf(r)<0})).desc("none of '"+e+"'")},n.notFollowedBy=F,n.of=q,n.oneOf=function(e){for(var r=e.split(""),t=0;t<r.length;t++)r[t]="'"+r[t]+"'";return z((function(r){return e.indexOf(r)>=0})).desc(r)},n.optWhitespace=oe,n.Parser=n,n.range=function(e,r){return z((function(t){return e<=t&&t<=r})).desc(e+"-"+r)},n.regex=K,n.regexp=K,n.sepBy=H,n.sepBy1=V,n.seq=T,n.seqMap=N,n.seqObj=function(){for(var e,r={},t=0,s=(e=arguments,Array.prototype.slice.call(e)),o=s.length,i=0;i<o;i+=1){var a=s[i];if(!g(a)){if(k(a)&&2===a.length&&"string"==typeof a[0]&&g(a[1])){var c=a[0];if(Object.prototype.hasOwnProperty.call(r,c))throw new Error("seqObj: duplicate key "+c);r[c]=!0,t++;continue}throw new Error("seqObj arguments must be parsers or [string, parser] array pairs.")}}if(0===t)throw new Error("seqObj expects at least one named parser, found zero");return n((function(e,r){for(var t,n={},i=0;i<o;i+=1){var a,c;if(k(s[i])?(a=s[i][0],c=s[i][1]):(a=null,c=s[i]),!(t=x(c._(e,r),t)).status)return t;a&&(n[a]=t.value),r=t.index}return x(w(r,n),t)}))},n.string=G,n.succeed=q,n.takeWhile=function(e){return P(e),n((function(r,t){for(var n=t;n<r.length&&e(O(r,n));)n++;return w(n,r.slice(t,n))}))},n.test=z,n.whitespace=ie,n["fantasy-land/empty"]=Q,n["fantasy-land/of"]=q,n.Binary={bitSeq:h,bitSeqObj:function(e){f();var r={},t=0,n=a((function(e){if(k(e)){var n=e;if(2!==n.length)throw new Error("["+n.join(", ")+"] should be length 2, got length "+n.length);if(A(n[0]),S(n[1]),Object.prototype.hasOwnProperty.call(r,n[0]))throw new Error("duplicate key in bitSeqObj: "+n[0]);return r[n[0]]=!0,t++,n}return S(e),[null,e]}),e);if(t<1)throw new Error("bitSeqObj expects at least one named pair, got ["+e.join(", ")+"]");var s=a((function(e){return e[0]}),n);return h(a((function(e){return e[1]}),n)).map((function(e){return i((function(e,r){return null!==r[0]&&(e[r[0]]=r[1]),e}),{},a((function(r,t){return[r,e[t]]}),s))}))},byte:function(e){if(f(),S(e),e>255)throw new Error("Value specified to byte constructor ("+e+"=0x"+e.toString(16)+") is larger in value than a single byte.");var r=(e>15?"0x":"0x0")+e.toString(16);return n((function(t,n){var s=O(t,n);return s===e?w(n+1,s):y(n,r)}))},buffer:function(e){return l("buffer",e).map((function(e){return Buffer.from(e)}))},encodedString:function(e,r){return l("string",r).map((function(r){return r.toString(e)}))},uintBE:p,uint8BE:p(1),uint16BE:p(2),uint32BE:p(4),uintLE:v,uint8LE:v(1),uint16LE:v(2),uint32LE:v(4),intBE:b,int8BE:b(1),int16BE:b(2),int32BE:b(4),intLE:m,int8LE:m(1),int16LE:m(2),int32LE:m(4),floatBE:l("floatBE",4).map((function(e){return e.readFloatBE(0)})),floatLE:l("floatLE",4).map((function(e){return e.readFloatLE(0)})),doubleBE:l("doubleBE",8).map((function(e){return e.readDoubleBE(0)})),doubleLE:l("doubleLE",8).map((function(e){return e.readDoubleLE(0)}))},e.exports=n}])}},r={};function t(n){var s=r[n];if(void 0!==s)return s.exports;var o=r[n]={exports:{}};return e[n].call(o.exports,o,o.exports,t),o.exports}t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,{a:r}),r},t.d=function(e,r){for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)};var n={};!function(){"use strict";t.d(n,{AwokenRef:function(){return Pe}});var e=t(864),r=t.n(e);function s(e,r){return e.book[r.book][r.chapter].cumulative_verse+r.verse-1}function o(e,r){var t;for(t=1;t<e.order.length&&!(e.order[t].chapters[0].cumulative_verse>r);++t);--t;var n,s=e.order[t];for(n=1;n<s.chapters.length&&!(s.chapters[n].cumulative_verse>r);++n);return--n,{book:s.id,chapter:n+1,verse:r-s.chapters[n].cumulative_verse+1}}function i(e,r){return r.is_range?s(e,r.end)-s(e,r.start)+1:1}function a(e,r,t){if(0===t||0===r.length)return[];if(1===r.length){var n=r[0];if(i(e,n)<=t)return r;var c=n;return 1==t?[c.start]:[{is_range:!0,start:c.start,end:o(e,s(e,c.start)+t-1)}]}for(var u=[],f=0,h=0;h<r.length&&f<t;++h){var l=a(e,[r[h]],t-f);f+=i(e,l[0]),u.push(l[0])}return u}function c(e){this.versification;var r=m(this,e);r=r.sort(((e,r)=>e.min-r.min));var t=[],n=null;for(var s of r)null!=n?s.min>n.max+1?(t.push(n),n=s):s.max>n.max&&(n.max=s.max):n=s;return n&&t.push(n),t.map((e=>k(this,e)))}function u(e){return{segments:g(this,e)}}function f(e,r){for(var t=g(this,e),n=g(this,r),s=0,o=0,i=[];s<t.length&&o<n.length;){var a=_(t[s],n[o]);null!==a?(i.push(k(this,a)),t[s].min=a.max+1,n[o].min=a.max+1,t[s].min>=t[s].max&&++s,n[o].min>=n[o].max&&++o):t[s].max<n[o].max?++s:++o}return i}function h(e,r){var t=g(this,e),n=g(this,r),[s,o]=t.length>n.length?[n,t]:[t,n];for(var i of s){for(var a=0,c=o.length-1;a<c-1;){for(var u=a+Math.ceil((c-a)/2);a<c-1&&o[u].min<i.min;)u=(a=u)+Math.ceil((c-a)/2);c=u}for(var f=a;f<o.length&&!(i.max<o[f].min);++f)if(_(i,o[f]))return!0}return!1}function l(e,r){for(var t=g(this,e),n=g(this,r),s=0,o=0;o<n.length;){for(;t[s].max<n[o].min;)if(++s>=t.length)return!1;for(;o<n.length&&n[o].min<=t[s].max;){if(t[s].min>n[o].min||n[o].max>t[s].max)return!1;++o}}return!0}function d(e,r){var t="length"in e?e:[e],n="length"in r?r:[r];return c.bind(this)([...t,...n])}function p(e,r){for(var t=g(this,e),n=g(this,r),s=[],o=0,i=0;o<t.length&&i<n.length;){var a=_(t[o],n[i]);a?(t[o].min<a.min&&s.push(k(this,{min:t[o].min,max:a.min-1})),t[o].min=a.max+1,n[i].min=a.max+1,t[o].min>t[o].max&&++o,n[i].min>n[i].max&&++i):t[o].min<n[i].min?(s.push(k(this,t[o])),++o):++i}for(;o<t.length;)s.push(k(this,t[o])),++o;return s}function v(e,r){var t=m(this,e),n=s(this.versification,r),o=0;for(var i of t){if(n>=i.min&&n<=i.max)return o+(n-i.min);o+=i.max-i.min+1}return-1}function b(e,r){var t=m(this,e),n=0;for(var s of t){var i=n+(s.max-s.min);if(r>=n&&r<=i)return o(this.versification,s.min+r-n);n=i+1}}function m(e,r){return("length"in r?r:[r]).map((r=>{if(r.is_range)return{min:s(e.versification,r.start),max:s(e.versification,r.end)};var t=s(e.versification,r);return{min:t,max:t}}))}function g(e,r){if("segments"in r)return r.segments;var t="length"in r?r:[r];return m(e,c.bind(e)(t))}function k(e,r){return r.min===r.max?o(e.versification,r.min):{is_range:!0,start:o(e.versification,r.min),end:o(e.versification,r.max)}}function _(e,r){var t=Math.max(e.min,r.min),n=Math.min(r.max,e.max);return t<=n?{min:t,max:n}:null}function w(e,r){return H(this.versification,e,r)}function y(e,r){return V(this.versification,e,r)}function x(e,r){return Array.from(B.bind(this)(e,r))}function E(e,r){return Array.from(O.bind(this)(e,r))}function I(e){return Array.from(S.bind(this)(e))}function B(e,r){return void 0===r&&(r=!1),"length"in e||(e=[e]),G(this.versification,e,r)}function O(e,r){return void 0===r&&(r=!1),"length"in e||(e=[e]),K(this.versification,e,r)}function S(e){return"length"in e||(e=[e]),function*(e,r){for(var t of K(e,r,!1))if(t.is_range)for(var n=t.start.verse;n<=t.end.verse;++n)yield{book:t.start.book,chapter:t.start.chapter,verse:n};else yield t}(this.versification,e)}function P(e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},t=e.is_range?e.end:e,n=this.versification.book[t.book],s=null==n?void 0:n.chapters[t.chapter-1];if(!n||!s)throw new Error("Invalid input reference to nextVerse!");if(t.verse+1<s.verse_count)return{book:t.book,chapter:t.chapter,verse:t.verse+1};if(r.constrain_chapter)return null;var o=J.bind(this)(e,r.constrain_book);return o?o.start:null}function A(e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},t=e.is_range?e.end:e;if(t.verse>1)return{book:t.book,chapter:t.chapter,verse:t.verse-1};if(r.constrain_chapter)return null;var n=C.bind(this)(e,r.constrain_book);return n?n.end:null}function J(e,r){var t=e.is_range?e.end:e,n=this.versification.book[t.book];if(void 0===n)throw new Error("Invalid input reference to nextChapter!");return t.chapter<n.chapters.length?H(this.versification,t.book,t.chapter+1):r?null:n.index+1<this.versification.order.length?H(this.versification,this.versification.order[n.index+1].id,1):null}function C(e,r){var t=e.is_range?e.start:e,n=t.book,s=0;if(t.chapter<=1){if(r)return null;var o=this.versification.book[t.book];if(void 0===o)throw new Error("Invalid input reference to previousChapter");if(0===o.index)return null;var i=this.versification.order[o.index-1];n=i.id,s=i.chapters.length}else s=t.chapter-1;return H(this.versification,n,s)}function L(e){var r=e.is_range?e.end:e,t=this.versification.book[r.book];return t.index+1<this.versification.order.length?H(this.versification,this.versification.order[t.index+1].id):null}function j(e){var r=e.is_range?e.start:e,t=this.versification.book[r.book];return t.index>0?H(this.versification,this.versification.order[t.index-1].id):null}function R(e){if(!e.is_range)return!1;var r=e.start.book;return e.end.book==r&&1===e.start.chapter&&1===e.start.verse&&e.end.chapter===this.versification.book[r].chapters.length&&e.end.verse===this.versification.book[r][e.end.chapter].verse_count}function M(e){if(!e.is_range)return!1;var r=e.start.book;return e.end.book==r&&e.start.chapter===e.end.chapter&&1===e.start.verse&&e.end.verse===this.versification.book[r][e.start.chapter].verse_count}function T(e){var r={};for(var t of B.bind(this)(e)){var n=t.is_range?t.start.book:t.book;r[n]?r[n].references.push(t):r[n]={book:n,references:[t]}}return Object.values(r).sort(((e,r)=>this.versification.book[e.book].index-this.versification.book[r.book].index))}function N(e){var r={};for(var t of O.bind(this)(e)){var n=void 0,s=void 0;t.is_range?(n=t.start.book,s=t.start.chapter):(n=t.book,s=t.chapter);var o="".concat(n,"_").concat(s);r[o]?r[o].references.push(t):r[o]={book:n,chapter:s,references:[t]}}return Object.values(r).sort(((e,r)=>{var t=this.versification.book[e.book].index-this.versification.book[r.book].index;return 0===t?e.chapter-r.chapter:t}))}function D(e,r){r||(r={}),"length"in e||(e=[e]);var t={books:[],chapters:[],verses:[]};for(var n of G(this.versification,e,!0)){var s=R.bind(this)(n);if((s||r.consolidate)&&t.books.push(H(this.versification,n.start.book)),!s||r.disperse)for(var o of K(this.versification,[n],!0)){var i=M.bind(this)(o);(i||r.consolidate)&&t.chapters.push(H(this.versification,o.start.book,o.start.chapter)),i&&!r.disperse||(t.verses=t.verses.concat(I.bind(this)(o)))}}return t.books=x.bind(this)(c.bind(this)(t.books)),t.chapters=E.bind(this)(c.bind(this)(t.chapters)),t.verses=I.bind(this)(c.bind(this)(t.verses)),t}function H(e,r,t){var n=e.book[r];if(null==n)throw new Error("Specified book id does not exist");if(t){if(t>n.chapters.length)throw new Error("Specified chapter index is too high");return{is_range:!0,start:{book:r,chapter:t,verse:1},end:{book:r,chapter:t,verse:n.chapters[t-1].verse_count}}}return{is_range:!0,start:{book:r,chapter:1,verse:1},end:{book:r,chapter:n.chapters.length,verse:n.chapters[n.chapters.length-1].verse_count}}}function V(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:r,n=e.book[t],s=n.chapters[n.chapters.length-1];return{is_range:!0,start:{book:r,chapter:1,verse:1},end:{book:t,chapter:n.chapters.length,verse:s.verse_count}}}function*G(e,r,t){for(var n of r)if(n.is_range)if(n.start.book!=n.end.book){var s=e.book[n.start.book].chapters.length,o=e.book[n.start.book].chapters[s-1].verse_count;yield{is_range:!0,start:n.start,end:{book:n.start.book,chapter:s,verse:o}};for(var i=e.book[n.start.book].index+1;i<e.book[n.end.book].index;++i)yield H(e,e.order[i].id);yield{is_range:!0,start:{book:n.end.book,chapter:1,verse:1},end:n.end}}else yield n;else t?yield{is_range:!0,start:n,end:n}:yield n}function*K(e,r,t){for(var n of G(e,r,t))if(n.is_range)if(n.start.chapter!=n.end.chapter){var s=n.start.book,o=e.book[s],i=o.chapters[n.start.chapter-1].verse_count;yield{is_range:!0,start:n.start,end:{book:s,chapter:n.start.chapter,verse:i}};for(var a=n.start.chapter+1;a<n.end.chapter;++a)yield H(e,o.id,a);yield{is_range:!0,start:{book:s,chapter:n.end.chapter,verse:1},end:n.end}}else yield n;else yield n}var q=function(e){for(var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],t={order:[],book:{},rangeAliases:[]},n=0,s=0;s<e.length;++s){var o=e[s],i=[];for(var a of o.verse_counts)i.push({verse_count:a,cumulative_verse:n}),n+=a;for(var c={id:o.id,osisId:o.osisId,name:o.name,index:s,aliases:o.aliases,chapters:i},u=0;u<i.length;++u)c[u+1]=i[u];t.order.push(c),t.book[c.id]=c}return t.rangeAliases=r.map((e=>"refs"in e?e:{pattern:e.pattern,refs:e.books.map((e=>V(t,e[0],e[1])))})),t}([{id:"GEN",osisId:"Gen",name:"Genesis",aliases:["Gn","Ge"],verse_counts:[31,25,24,26,32,22,24,22,29,32,32,20,18,24,21,16,27,33,38,18,34,24,20,67,34,35,46,22,35,43,55,32,20,31,29,43,36,30,23,23,57,38,34,34,28,34,31,22,33,26]},{id:"EXO",osisId:"Exod",name:"Exodus",aliases:["Exod","Ex"],verse_counts:[22,25,22,31,23,30,25,32,35,29,10,51,22,31,27,36,16,27,25,26,36,31,33,18,40,37,21,43,46,38,18,35,23,35,35,38,29,31,43,38]},{id:"LEV",osisId:"Lev",name:"Leviticus",aliases:["Lv","Le"],verse_counts:[17,16,17,35,19,30,38,36,24,20,47,8,59,57,33,34,16,30,37,27,24,33,44,23,55,46,34]},{id:"NUM",osisId:"Num",name:"Numbers",aliases:["Nm","Nu","Nb"],verse_counts:[54,34,51,49,31,27,89,26,23,36,35,16,33,45,41,50,13,32,22,29,35,41,30,25,18,65,23,31,40,16,54,42,56,29,34,13]},{id:"DEU",osisId:"Deut",name:"Deuteronomy",aliases:["Deut","Dt","De"],verse_counts:[46,37,29,49,33,25,26,20,29,22,32,32,18,29,23,22,20,22,21,20,23,30,25,22,19,19,26,68,29,20,30,52,29,12]},{id:"JOS",osisId:"Josh",name:"Joshua",aliases:["Josh","Jo","Jsh"],verse_counts:[18,24,17,24,15,27,26,35,27,43,23,24,33,15,63,10,18,28,51,9,45,34,16,33]},{id:"JDG",osisId:"Judg",name:"Judges",aliases:["Judg","Jgs","Jg","Jdgs"],verse_counts:[36,23,31,24,31,40,25,35,57,18,40,15,25,20,20,31,13,31,30,48,25]},{id:"RUT",osisId:"Ruth",name:"Ruth",aliases:["Ru","Rth"],verse_counts:[22,23,18,22]},{id:"1SA",osisId:"1Sam",name:"1 Samuel",aliases:["1 Sam","1 Sm"],verse_counts:[28,36,21,22,12,21,17,22,27,27,15,25,23,52,35,23,58,30,24,42,15,23,29,22,44,25,12,25,11,31,13]},{id:"2SA",osisId:"2Sam",name:"2 Samuel",aliases:["2 Sam","2 Sm"],verse_counts:[27,32,39,12,25,23,29,18,13,19,27,31,39,33,37,23,29,33,43,26,22,51,39,25]},{id:"1KI",osisId:"1Kgs",name:"1 Kings",aliases:["1 Kgs","1 Kin","1 Kngs"],verse_counts:[53,46,28,34,18,38,51,66,28,29,43,33,34,31,34,34,24,46,21,43,29,53]},{id:"2KI",osisId:"2Kgs",name:"2 Kings",aliases:["2 Kgs","2 Kin","2 Kngs"],verse_counts:[18,25,27,44,27,33,20,29,37,36,21,21,25,29,38,20,41,37,37,21,26,20,37,20,30]},{id:"1CH",osisId:"1Chr",name:"1 Chronicles",aliases:["1 Chr","1 Chron"],verse_counts:[54,55,24,43,26,81,40,40,44,14,47,40,14,17,29,43,27,17,19,8,30,19,32,31,31,32,34,21,30]},{id:"2CH",osisId:"2Chr",name:"2 Chronicles",aliases:["2 Chr","2 Chron"],verse_counts:[17,18,17,22,14,42,22,18,31,19,23,16,22,15,19,14,19,34,11,37,20,12,21,27,28,23,9,27,36,27,21,33,25,33,27,23]},{id:"EZR",osisId:"Ezra",name:"Ezra",aliases:["Ezr"],verse_counts:[11,70,13,24,17,22,28,36,15,44]},{id:"NEH",osisId:"Neh",name:"Nehemiah",aliases:["Ne"],verse_counts:[11,20,32,23,19,19,73,18,38,39,36,47,31]},{id:"EST",osisId:"Esth",name:"Esther",aliases:["Esth","Es"],verse_counts:[22,23,15,17,14,14,10,17,32,3]},{id:"JOB",osisId:"Job",name:"Job",aliases:["Jb"],verse_counts:[22,13,26,21,27,30,21,22,35,22,20,25,28,22,35,22,16,21,29,29,34,30,17,25,6,14,23,28,25,31,40,22,33,37,16,33,24,41,30,24,34,17]},{id:"PSA",osisId:"Ps",name:"Psalm",aliases:["Psalms","Ps","Pss","Psm","Pslm"],verse_counts:[6,12,8,8,12,10,17,9,20,18,7,8,6,7,5,11,15,50,14,9,13,31,6,10,22,12,14,9,11,12,24,11,22,22,28,12,40,22,13,17,13,11,5,26,17,11,9,14,20,23,19,9,6,7,23,13,11,11,17,12,8,12,11,10,13,20,7,35,36,5,24,20,28,23,10,12,20,72,13,19,16,8,18,12,13,17,7,18,52,17,16,15,5,23,11,13,12,9,9,5,8,28,22,35,45,48,43,13,31,7,10,10,9,8,18,19,2,29,176,7,8,9,4,8,5,6,5,6,8,8,3,18,3,3,21,26,9,8,24,13,10,7,12,15,21,10,20,14,9,6]},{id:"PRO",osisId:"Prov",name:"Proverbs",aliases:["Prov","Prv","Pr"],verse_counts:[33,22,35,27,23,35,27,36,18,32,31,28,25,35,33,33,28,24,29,30,31,29,35,34,28,28,27,28,27,33,31]},{id:"ECC",osisId:"Eccl",name:"Ecclesiastes",aliases:["Eccl","Eccles","Ec","Eccle","Qoheleth","Qoh","Kohelet","Koh"],verse_counts:[18,26,22,16,20,12,29,17,18,20,10,14]},{id:"SNG",osisId:"Song",name:"Song of Solomon",aliases:["Song","Song of Songs","SOS","SongOfSolomon","SongOfSongs","Song of Sol","Sg","Canticles","Cant"],verse_counts:[17,17,11,16,16,13,13,14]},{id:"ISA",osisId:"Isa",name:"Isaiah",aliases:["Is"],verse_counts:[31,22,26,6,30,13,25,22,21,34,16,6,22,32,9,14,14,7,25,6,17,25,18,23,12,21,13,29,24,33,9,20,24,17,10,22,38,22,8,31,29,25,28,28,25,13,15,22,26,11,23,15,12,17,13,12,21,14,21,22,11,12,19,12,25,24]},{id:"JER",osisId:"Jer",name:"Jeremiah",aliases:["Je","Jr"],verse_counts:[19,37,25,31,31,30,34,22,26,25,23,17,27,22,21,21,27,23,15,18,14,30,40,10,38,24,22,17,32,24,40,44,26,22,19,32,21,28,18,16,18,22,13,30,5,28,7,47,39,46,64,34]},{id:"LAM",osisId:"Lam",name:"Lamentations",aliases:["La"],verse_counts:[22,22,66,22,22]},{id:"EZK",osisId:"Ezek",name:"Ezekiel",aliases:["Ezek","Ez","Eze"],verse_counts:[28,10,27,17,17,14,27,18,11,22,25,28,23,23,8,63,24,32,14,49,32,31,49,27,17,21,36,26,21,26,18,32,33,31,15,38,28,23,29,49,26,20,27,31,25,24,23,35]},{id:"DAN",osisId:"Dan",name:"Daniel",aliases:["Dn","Da"],verse_counts:[21,49,30,37,31,28,28,27,27,21,45,13]},{id:"HOS",osisId:"Hos",name:"Hosea",aliases:["Ho"],verse_counts:[11,23,5,19,15,11,16,14,17,15,12,14,16,9]},{id:"JOL",osisId:"Joel",name:"Joel",aliases:["Jl","Joe"],verse_counts:[20,32,21]},{id:"AMO",osisId:"Amos",name:"Amos",aliases:["Am"],verse_counts:[15,16,15,13,27,14,17,14,15]},{id:"OBA",osisId:"Obad",name:"Obadiah",aliases:["Obad","Ob"],verse_counts:[21]},{id:"JON",osisId:"Jonah",name:"Jonah",aliases:["Jnh"],verse_counts:[17,10,10,11]},{id:"MIC",osisId:"Mic",name:"Micah",aliases:["Mi","Mc","Mch"],verse_counts:[16,13,12,13,15,16,20]},{id:"NAM",osisId:"Nah",name:"Nahum",aliases:["Na","Nah"],verse_counts:[15,13,19]},{id:"HAB",osisId:"Hab",name:"Habakkuk",aliases:["Hb"],verse_counts:[17,20,19]},{id:"ZEP",osisId:"Zeph",name:"Zephaniah",aliases:["Zeph","Zp"],verse_counts:[18,15,20]},{id:"HAG",osisId:"Hag",name:"Haggai",aliases:["Hg","Hagg","Hgg"],verse_counts:[15,23]},{id:"ZEC",osisId:"Zech",name:"Zechariah",aliases:["Zech","Zec","Zc","Zch","Zah"],verse_counts:[21,13,10,14,11,15,14,23,17,12,17,14,9,21]},{id:"MAL",osisId:"Mal",name:"Malachi",aliases:["Ml"],verse_counts:[14,17,18,6]},{id:"MAT",osisId:"Matt",name:"Matthew",aliases:["Matt","Mt"],verse_counts:[25,23,17,25,48,34,29,34,38,42,30,50,58,36,39,28,27,35,30,34,46,46,39,51,46,75,66,20]},{id:"MRK",osisId:"Mark",name:"Mark",aliases:["Mk","Mar","Mr"],verse_counts:[45,28,35,41,43,56,37,38,50,52,33,44,37,72,47,20]},{id:"LUK",osisId:"Luke",name:"Luke",aliases:["Lk","Lu","Lc","Luc"],verse_counts:[80,52,38,44,39,49,50,56,62,42,54,59,35,35,32,31,37,43,48,47,38,71,56,53]},{id:"JHN",osisId:"John",name:"John",aliases:["Jn"],verse_counts:[51,25,36,54,47,71,53,59,41,42,57,50,38,31,27,33,26,40,42,31,25]},{id:"ACT",osisId:"Acts",name:"Acts",aliases:["Ac"],verse_counts:[26,47,26,37,42,15,60,40,43,48,30,25,52,28,41,40,34,28,41,38,40,30,35,27,27,32,44,31]},{id:"ROM",osisId:"Rom",name:"Romans",aliases:["Ro","Rm"],verse_counts:[32,29,31,25,21,23,25,39,33,21,36,21,14,23,33,27]},{id:"1CO",osisId:"1Cor",name:"1 Corinthians",aliases:["1 Cor"],verse_counts:[31,16,23,21,13,20,40,13,27,33,34,31,13,40,58,24]},{id:"2CO",osisId:"2Cor",name:"2 Corinthians",aliases:["2 Cor"],verse_counts:[24,17,18,18,21,18,16,24,15,18,33,21,14]},{id:"GAL",osisId:"Gal",name:"Galatians",aliases:["Ga","Gl"],verse_counts:[24,21,29,31,26,18]},{id:"EPH",osisId:"Eph",name:"Ephesians",aliases:["Ephes"],verse_counts:[23,22,21,32,33,24]},{id:"PHP",osisId:"Phil",name:"Philippians",aliases:["Phil","Phl","Pp"],verse_counts:[30,30,21,23]},{id:"COL",osisId:"Col",name:"Colossians",aliases:[],verse_counts:[29,23,25,18]},{id:"1TH",osisId:"1Thess",name:"1 Thessalonians",aliases:["1 Thess","1 Thes","1 Te","1 Ts","1 Tess"],verse_counts:[10,20,13,18,28]},{id:"2TH",osisId:"2Thess",name:"2 Thessalonians",aliases:["2 Thess","2 Thes","2 Te","2 Ts","2 Tess"],verse_counts:[12,17,18]},{id:"1TI",osisId:"1Tim",name:"1 Timothy",aliases:["1 Tim","1 Tm","1 Ti"],verse_counts:[20,15,16,16,25,21]},{id:"2TI",osisId:"2Tim",name:"2 Timothy",aliases:["2 Tim","2 Tm","2 Ti"],verse_counts:[18,26,17,22]},{id:"TIT",osisId:"Titus",name:"Titus",aliases:["Ti","Tt"],verse_counts:[16,15,15]},{id:"PHM",osisId:"Phlm",name:"Philemon",aliases:["Phlm","Philem","Pm"],verse_counts:[25]},{id:"HEB",osisId:"Heb",name:"Hebrews",aliases:["Hbr","Hebr","He"],verse_counts:[14,18,19,16,14,20,28,13,28,39,40,29,25]},{id:"JAS",osisId:"Jas",name:"James",aliases:["Jm"],verse_counts:[27,26,18,17,20]},{id:"1PE",osisId:"1Pet",name:"1 Peter",aliases:["1 Pet","1 Pt","1 Pe","1 Petr"],verse_counts:[25,25,22,19,14]},{id:"2PE",osisId:"2Pet",name:"2 Peter",aliases:["2 Pet","2 Pt","2 Pe","2 Petr"],verse_counts:[21,22,18]},{id:"1JN",osisId:"1John",name:"1 John",aliases:["1 Jn","1 Jo","1 Joh"],verse_counts:[10,29,24,21,21]},{id:"2JN",osisId:"2John",name:"2 John",aliases:["2 Jn","2 Jo","2 Joh"],verse_counts:[13]},{id:"3JN",osisId:"3John",name:"3 John",aliases:["3 Jn","3 Jo","3 Joh"],verse_counts:[14]},{id:"JUD",osisId:"Jude",name:"Jude",aliases:["Jde","Jd"],verse_counts:[25]},{id:"REV",osisId:"Rev",name:"Revelation",aliases:["Apoc","Rv"],verse_counts:[20,29,22,11,14,17,17,13,21,11,19,17,18,20,8,21,18,24,21,15,27,21]}],[{pattern:/gospels?/i,books:[["MAT","JHN"]]},{pattern:/torah|pentateuch|law|(five )?books of moses/i,books:[["GEN","DEU"]]},{pattern:/old test[ae]ment|tanakh/i,books:[["GEN","MAL"]]},{pattern:/new test[ae]ment/i,books:[["MAT","REV"]]},{pattern:/ketuvim/i,books:[["JOS","JDG"],["1SA","2KI"],["ISA","JER"],["EZK"],["HOS","MAL"]]},{pattern:/nevi'?im/i,books:[["RUT"],["1CH","SNG"],["LAM"],["DAN"]]}]),U=q,Z=r().regex(/[ \t]*/),F=r().regex(/[0-9]+/).skip(Z).map((e=>Number(e))),z=r().alt(r().string("1st").map((e=>1)),r().string("2nd").map((e=>2)),r().string("3rd").map((e=>3)),r().string("First").map((()=>1)),r().string("Second").map((()=>2)),r().string("Third").map((()=>3)),r().oneOf("123").map((e=>parseInt(e))),r().oneOf("I").times(1,3).map((e=>e.length))),W=r().oneOf(":v.").skip(Z),Q=r().oneOf(",").skip(Z),X=r().optWhitespace.then(r().oneOf("-")).skip(Z),Y=r().seq(F,X.then(F).fallback(null)).chain((e=>{var[t,n]=e;return n&&n<=t?r().fail("End of range must be higher than start"):r().succeed({start:t,end:n})}));function $(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:U,t={},n=function(e){[e.name,...e.aliases].map((r=>t[r.toLowerCase()]=e.id))};for(var s of e.order)n(s);var o=r().regex(/([0-9A-Z]{3})\.?/i).chain((t=>(t=t.toUpperCase().substring(0,3),e.book[t]?r().succeed(t):r().fail("Invalid book ID: ".concat(t))))).desc("USFM book identifier (eg: 'GEN', 'REV')"),i=r().alt(r().regexp(/[Ss]ong\sof\s[Ss](ongs|olomon|ol)/).chain((e=>r().succeed("SNG"))),r().seq(z,Z,r().letters).chain((e=>{var n=e[0]+" "+e[2].toLowerCase(),s=t[n];return s?r().succeed(s):r().fail("Invalid book name: "+e)})),r().regexp(/[A-Z]+/i).chain((e=>{var n=t[e.toLowerCase()];return n?r().succeed(n):r().fail("Invalid book name: "+e)}))).desc("Book name (eg, 'Genesis', '2 Kings')"),a=e.rangeAliases.map((e=>{var{pattern:t,refs:n}=e;return r().regexp(t).chain((e=>r().succeed(n)))})),c=r().alt(...a),u=r().alt(i,o).skip(r().regexp(/\.? */)),f=r().alt(r().seqMap(F.skip(W),F,X,F.skip(W),F,((e,r,t,n,s)=>({kind:"chapter_range",c1:e,v1:r,c2:n,v2:s}))),Y.notFollowedBy(W).map((e=>({kind:"full_chapter",range:e}))),r().seqMap(F,W.then(Y.notFollowedBy(W).sepBy1(Q)),((e,r)=>({kind:"verse",chapter:e,verses:r})))).notFollowedBy(r().regex(/[a-z]/i));function h(r,t){switch(t.kind){case"full_chapter":var n=t.range.start,s=t.range.end?t.range.end:t.range.start,o=1;return void 0!==e.book[r][s]&&(o=e.book[r][s].verse_count),[{is_range:!0,start:{book:r,chapter:n,verse:1},end:{book:r,chapter:s,verse:o}}];case"verse":var i=t.chapter,a=[];for(var c of t.verses)c.end?a.push({is_range:!0,start:{book:r,chapter:i,verse:c.start},end:{book:r,chapter:i,verse:c.end}}):a.push({book:r,chapter:i,verse:c.start});return a;case"chapter_range":return[{is_range:!0,start:{book:r,chapter:t.c1,verse:t.v1},end:{book:r,chapter:t.c2,verse:t.v2}}]}}var l=r().alt(r().seq(u,r().seq(F,W.then(F).fallback(null)).fallback(null),X,u,f.sepBy(Q)).chain((t=>{var[n,s,o,i,a]=t,c=[],u={book:n,chapter:1,verse:1};if(s){var[f,l]=s;u.chapter=f,null!==l&&(u.verse=l)}var d={book:i,chapter:e.book[i].chapters.length,verse:0};if(a.length){var p=a[0];switch(p.kind){case"full_chapter":if(p.range.end)return r().fail("Double range encountered");d.chapter=p.range.start,d.verse=e.book[i][d.chapter].verse_count,c.push({is_range:!0,start:u,end:d}),a.shift();break;case"verse":if(p.verses[0].end)return r().fail("Double range encountered");d.chapter=p.chapter,d.verse=p.verses[0].start,c.push({is_range:!0,start:u,end:d}),p.verses.shift();break;default:return r().fail("Double range encountered")}}else d.verse=e.book[i][d.chapter].verse_count,c.push({is_range:!0,start:u,end:d});for(var v of a||[])c=c.concat(h(i,v));return r().succeed(c)})),r().seqMap(u,f.sepBy(Q),((r,t)=>{if(0==t.length){var n=e.book[r].chapters.length;return[{is_range:!0,start:{book:r,chapter:1,verse:1},end:{book:r,chapter:n,verse:e.book[r][n].verse_count}}]}var s=[];for(var o of t)s=s.concat(h(r,o));return s})),r().seq(z,X.then(z),Z.then(r().letters)).chain((n=>{var[s,o,i]=n;if(s===o)return r().fail("Numbered book range must have different start to end");var a=s+" "+i.toLowerCase(),c=t[a];if(!c)return r().fail("Invalid book name: ".concat(s," ").concat(i.toLowerCase()));var u=o+" "+i.toLowerCase(),f=t[u];return f?r().succeed(V(e,c,f)):r().fail("Invalid book name: ".concat(o," ").concat(i.toLowerCase()))})),c),d=l.sepBy1(Z.then(r().oneOf(";_,")).then(Z)).map((e=>e.reduce(((e,r)=>e.concat(r)),[])));return{Book:u,BibleRef:d}}var ee=$();function re(e){var r=this.versification.book,t=[],n=null,s=[],o="",i=0;function a(){var r=parseInt(e.substring(i));return r?(i+="".concat(r).length,r):null}var c=w.bind(this);e:for(;i<e.length;){var u=e.substring(i,i+3).toUpperCase();if(i+=3,!r[u])throw new Error("Failed to parse url BibleRef, wanted book id, got: "+u);if(n=null,"_"!==(e.charAt(i)||"_")){"-"===e.charAt(i)&&(++i,o="-");r:for(;;){if("-"===o){var f=e.substring(i,i+3).toUpperCase();if(r[f]){i+=3;var h=n?{book:u,chapter:n,verse:s.shift()}:{book:u,chapter:s.shift()||1,verse:1},l=a(),d=l?c(f,l).end:c(f).end;if(l&&"v"===e.charAt(i)&&(++i,d.verse=a(),!d.verse))throw new Error("Expected integer after 'v' seperator in closing cross-book range");"_"===e.charAt(i)&&++i,o="",t.push({is_range:!0,start:h,end:d});continue e}}s.push(a());var p=e.charAt(i++)||"_";if(""!==o||"v"!==p)if(","===p||"_"===p){switch(o){case"":t.push(n?{book:u,chapter:n,verse:s.shift()}:c(u,s.shift()));break;case"-":n?t.push({is_range:!0,start:{book:u,chapter:n,verse:s.shift()},end:{book:u,chapter:n,verse:s.shift()}}):t.push({is_range:!0,start:{book:u,chapter:s.shift(),verse:1},end:c(u,s.shift()).end});break;case"-v":t.push({is_range:!0,start:{book:u,chapter:n,verse:s.shift()},end:{book:u,chapter:s.shift(),verse:s.shift()}});break;default:if((o+=p).length>2)throw new Error("Invalid bible ref url input");continue r}if(o="","_"===p)continue e}else o+=p;else n=s.shift()}}else++i,t.push(c(u))}return t}function te(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function ne(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?te(Object(t),!0).forEach((function(r){se(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):te(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function se(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var oe,ie={book_format:"name",verse_separator:":",strip_whitespace:!1,compact:!1,combine_ranges:!1,complete_refs:!1,lowercase:!1},ae={osis:{book_format:"osis",book_separator:".",verse_separator:".",complete_refs:!0,strip_whitespace:!0,ref_separator:", "},url:{book_format:"usfm",book_separator:"",verse_separator:"v",strip_whitespace:!0,compact:!0,ref_separator:"_",lowercase:!0},compact:{compact:!0},lowercase:{lowercase:!0},combined:{combine_ranges:!0},complete:{complete_refs:!0}};function ce(e,r,t){var n;switch(t.book_format){case"name":n=e.book[r].name;break;case"usfm":n=r;break;case"osis":n=e.book[r].osisId;break;default:throw new Error("Invalid output book format specified")}return t.lowercase?n.toLowerCase():n}function ue(e,r){return"".concat(e.chapter).concat(r.verse_separator).concat(e.verse)}function fe(e){var r=ne({},ie);if("string"==typeof e)for(var t of e.split(":")){if(!(t in ae))throw new Error("Invalid format preset name specified: '".concat(t,"'"));r=ne(ne({},r),ae[t])}else void 0!==e&&(r=ne(ne({},r),e));return r.book_separator||(r.book_separator=r.strip_whitespace?"":" "),r.ref_separator||(r.ref_separator=r.strip_whitespace?";":"; "),r}function he(e,r,t){var n=fe(t);return function(e,r){return e.strip_whitespace?r.replace(/ /g,""):r}(n,ce(e,r.book,n)+n.book_separator+ue(r,n))}function le(e,r,t){var n=fe(t),s=e.book[r.start.book],o=n.strip_whitespace?"-":" - ";return r.start.book!==r.end.book||n.complete_refs?n.compact&&!n.complete_refs&&1===r.start.verse&&r.end.verse===e.book[r.end.book].chapters[r.end.chapter-1].verse_count?1===r.start.chapter&&r.end.chapter===e.book[r.end.book].chapters.length?ce(e,r.start.book,n)+o+ce(e,r.end.book,n):ce(e,r.start.book,n)+"".concat(n.book_separator).concat(r.start.chapter)+o+ce(e,r.end.book,n)+"".concat(n.book_separator).concat(r.end.chapter):he(e,r.start,n)+o+he(e,r.end,n):r.start.chapter!==r.end.chapter?n.compact&&1===r.start.verse&&r.end.verse===s.chapters[r.end.chapter-1].verse_count?1===r.start.chapter&&r.end.chapter===s.chapters.length?ce(e,r.start.book,n):ce(e,r.start.book,n)+"".concat(n.book_separator).concat(r.start.chapter).concat(o).concat(r.end.chapter):ce(e,r.start.book,n)+n.book_separator+ue(r.start,n)+o+ue(r.end,n):r.start.verse!==r.end.verse?n.compact&&1===r.start.verse&&r.end.verse===s.chapters[r.end.chapter-1].verse_count?ce(e,r.start.book,n)+n.book_separator+r.start.chapter:he(e,r.start,n)+"-"+r.end.verse:he(e,r.start,n)}function de(e,r){var t=e.book[r.book],n=[];return null==t?n.push({ref:r,kind:oe.BadBook,is_warning:!1,message:"The specified book does not exist",got:r.book}):t.chapters.length<r.chapter?n.push({ref:r,kind:oe.BadChapter,is_warning:!1,message:"".concat(t.name," has only ").concat(t.chapters.length," chapters"),max_value:t.chapters.length,got:r.chapter}):t[r.chapter].verse_count<r.verse&&n.push({ref:r,kind:oe.BadVerse,is_warning:!1,message:"".concat(t.name," ").concat(r.chapter," has only ").concat(t[r.chapter].verse_count," verses"),max_value:t[r.chapter].verse_count,got:r.verse}),n}function pe(e,r,t){void 0===t&&(t=!0);var n=[];if(void 0===r.is_range)n=n.concat(de(e,r));else{n=(n=n.concat(de(e,r.start))).concat(de(e,r.end));var s=e.book[r.start.book],o=e.book[r.end.book];s&&o&&o.index<s.index?n.push({ref:r,kind:oe.BackwardsRange,is_warning:!1,message:"Range is backwards (".concat(o.name," comes before ").concat(s.name,")"),component:"book"}):r.start.book===r.end.book&&(r.end.chapter<r.start.chapter?n.push({ref:r,kind:oe.BackwardsRange,is_warning:!1,message:"Chapter range is backwards",component:"chapter"}):r.end.chapter===r.start.chapter&&(r.end.verse<r.start.verse?n.push({ref:r,kind:oe.BackwardsRange,is_warning:!1,message:"Verse range is backwards",component:"verse"}):r.end.verse===r.start.verse&&t&&n.push({ref:r,kind:oe.RangeOfOne,is_warning:!0,message:"Range contains only a single verse"})))}return n}function ve(e,r){switch(r.kind){case oe.BadBook:throw new Error("Cannot fix an 'unknown book' error");case oe.BadChapter:r.ref.chapter=r.max_value,r.ref.verse=e.book[r.ref.book][r.ref.chapter].verse_count;break;case oe.BadVerse:r.ref.verse=r.max_value;break;case oe.BackwardsRange:var t=r.ref.start;r.ref.start=r.ref.end,r.ref.end=t;break;case oe.RangeOfOne:var n=r.ref;n.book=n.start.book,n.chapter=n.start.chapter,n.verse=n.start.verse,delete n.is_range,delete n.start,delete n.end}}function be(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function me(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?be(Object(t),!0).forEach((function(r){ge(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):be(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function ge(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function ke(e){var r=this._parsers.BibleRef.parse(e);return!1===r.status?me(me({},r),{},{input:e}):r}function _e(e){var r=this.parse(e);if(!0===r.status)return r.value;throw r}function we(e,r){return"length"in e?function(e,r,t){if(0==r.length)return"";var n=fe(t);n.combine_ranges&&(r=c.bind({versification:e})(r));var s=null,o=null,i=[],a="",u=n.strip_whitespace?",":", ",f=n.strip_whitespace?"-":" - ";function h(r){a.length>0&&i.push(a),a="",r.is_range?(a=le(e,r,n),r.start.book===r.end.book&&(s=r.start.book),r.start.chapter===r.end.chapter&&(o=r.start.chapter)):(a=he(e,r,n),s=r.book,o=r.chapter)}for(var l of r)if(l.is_range)l.start.book!==l.end.book||l.start.book!==s||n.complete_refs?h(l):l.start.chapter===l.end.chapter&&l.start.chapter===o?a+=","+l.start.verse+(l.start.verse===l.end.verse?"":"-"+l.end.verse):a+=u+ue(l.start,n)+f+ue(l.end,n);else{if(l.book!==s||n.complete_refs){h(l);continue}if(l.chapter!=o){a+=u+ue(l,n),o=l.chapter;continue}a+=","+l.verse}return i.push(a),i.join(n.ref_separator)}(this.versification,e,r):e.is_range?le(this.versification,e,r):he(this.versification,e,r)}function ye(e){return e.sort(((e,r)=>{var t=e.is_range?e.start:e,n=r.is_range?r.start:r,o=s(this.versification,t),i=s(this.versification,n);return o==i?e.is_range&&!r.is_range?1:!e.is_range&&r.is_range?-1:0:o-i}))}function xe(e){return s(this.versification,e)}function Ee(e){return o(this.versification,e)}function Ie(e,r){var t="length"in e?e:[e];return a(this.versification,t,r)}function Be(e){return"length"in e?e.map((e=>i(this.versification,e))).reduce(((e,r)=>e+r),0):i(this.versification,e)}function Oe(e,r){return"length"in e?e.map((e=>pe(this.versification,e,r))).reduce(((e,r)=>e.concat(r)),[]):pe(this.versification,e,r)}function Se(e,r){return function(e,r,t){for(var n=pe(e,r,t),s=0;s<5&&n.length;++s){for(var o of n)ve(e,o);n=pe(e,r,t)}if(n.length)throw new Error("Max fix passes exceeded");return r}(this.versification,e,r)}!function(e){e.BadBook="BADBOOK",e.BadVerse="BADVERSE",e.BadChapter="BADCHPT",e.BackwardsRange="BACKWARDSRANGE",e.RangeOfOne="RANGEOFONE"}(oe||(oe={}));var Pe=function(e){return this.versification=e,this._parsers=$(e),this.parse=ke,this.parseOrThrow=_e,this.parseUrlEncoded=re,this.format=we,this.sort=ye,this.toVidx=xe,this.fromVidx=Ee,this.firstNVerses=Ie,this.countVerses=Be,this.validate=Oe,this.repair=Se,this.makeRange=w,this.makeBookRange=y,this.splitByBook=x,this.splitByChapter=E,this.splitByVerse=I,this.groupByBook=T,this.groupByChapter=N,this.groupByLevel=D,this.iterateByBook=B,this.iterateByChapter=O,this.iterateByVerse=S,this.nextVerse=P,this.previousVerse=A,this.nextChapter=J,this.previousChapter=C,this.nextBook=L,this.previousBook=j,this.createIntersectionSet=u,this.combineRanges=c,this.getIntersection=f,this.intersects=h,this.getUnion=d,this.getDifference=p,this.contains=l,this.indexOf=v,this.verseAtIndex=b,this};Pe.versification=U,Pe._parsers=ee,Pe.parse=ke.bind(Pe),Pe.parseOrThrow=_e.bind(Pe),Pe.parseUrlEncoded=re.bind(Pe),Pe.parseBookName=function(e){var r=this._parsers.Book.parse(e);return!0===r.status?r.value:null}.bind(Pe),Pe.format=we.bind(Pe),Pe.sort=ye.bind(Pe),Pe.toVidx=xe.bind(Pe),Pe.fromVidx=Ee.bind(Pe),Pe.firstNVerses=Ie.bind(Pe),Pe.countVerses=Be.bind(Pe),Pe.validate=Oe.bind(Pe),Pe.repair=Se.bind(Pe),Pe.makeRange=w.bind(Pe),Pe.makeBookRange=y.bind(Pe),Pe.splitByBook=x.bind(Pe),Pe.splitByChapter=E.bind(Pe),Pe.splitByVerse=I.bind(Pe),Pe.iterateByBook=B.bind(Pe),Pe.iterateByChapter=O.bind(Pe),Pe.iterateByVerse=S.bind(Pe),Pe.groupByBook=T.bind(Pe),Pe.groupByChapter=N.bind(Pe),Pe.groupByLevel=D.bind(Pe),Pe.nextVerse=P.bind(Pe),Pe.previousVerse=A.bind(Pe),Pe.nextChapter=J.bind(Pe),Pe.previousChapter=C.bind(Pe),Pe.nextBook=L.bind(Pe),Pe.previousBook=j.bind(Pe),Pe.isFullBook=R.bind(Pe),Pe.isFullChapter=M.bind(Pe),Pe.combineRanges=c.bind(Pe),Pe.createIntersectionSet=u.bind(Pe),Pe.getIntersection=f.bind(Pe),Pe.intersects=h.bind(Pe),Pe.getUnion=d.bind(Pe),Pe.getDifference=p.bind(Pe),Pe.contains=l.bind(Pe),Pe.indexOf=v.bind(Pe),Pe.verseAtIndex=b.bind(Pe)}(),AwokenRef=n.AwokenRef}();