-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbundle.js
1 lines (1 loc) · 4.35 KB
/
bundle.js
1
(()=>{var e={619:e=>{e.exports={referenceSection:"h2. External References",referenceSectionDivStart:'<div class="references">',referenceSectionDivEnd:"</div>",buttonName:"renumber-references-button",textareaId:"textarea-body",mainHeading:"h2.",formatCheckResults:{ALERT:"ALERT: ",CONFIRM:"CONFIRM",PASS:"PASS"}}},516:(e,n,t)=>{const{referenceSection:r,referenceSectionDivStart:o,referenceSectionDivEnd:i,mainHeading:s,formatCheckResults:c}=t(619),a=t(401);class u{constructor(e,n){this.orderedCitationNumber=e,this.referenceText=n}}const l="[".length,f="]".length,d="fn".length;function h(e,n,t){const r=`fn${n}.`,o=e.indexOf(r),i=o+d;let s=e.indexOf("\n",i);-1==s&&(s=e.length);const c=o+r.length;return`fn${t}. `+e.substring(c,s).trim()}function g(e,n){const t=e.indexOf(`fn${n}.`);let r=e.indexOf("\n",t+d);return-1==r&&(r=e.length),e.substring(0,t)+e.substring(r)}function m(e){const n=1==e.length?" ":"s ",t=1==e.length?" is ":" are ";return n+a(e)+t}e.exports={renumberReferences:function(e){let n=new Map;const t=/\[(?<number>\d+)\]/g;let s,c,a,f,d=0;for(;null!==(s=t.exec(e));){if(c=s.groups.number,n.has(c))a=n.get(c).orderedCitationNumber;else{a=++d,f=h(e,c,a);const t=new u(a,f);n.set(c,t)}const r=s.index+l,o=e.substring(0,r),i=e.substring(r+`${c}`.length,e.length);e=o+a+i;const g=r+`${a}`.length+l;t.lastIndex=g}e=function(e,n){for(const t of n.keys())e=g(e,t);return e}(e,n);let m,b=new Map;for(;null!==(m=/fn(?<number>\d+)\./g.exec(e));){c=m.groups.number,a=++d,f=h(e,c,a),e=g(e,c);const n=new u(a,f);b.set(c,n)}return e=function(e,n){e=e.substring(0,e.indexOf(r)),e+=`${r}\n\n${o}\n\n`;for(const t of n.values())e+=`${t.referenceText}\n\n`;return e+i}(e,new Map([...n,...b])),e},checkFormat:function(e,n){const{ALERT:t,CONFIRM:o,PASS:i}=c,a=e.indexOf(r);if(0===e.trim().length)return`${t}The text area must not be empty.`;if(-1==a||a<e.indexOf(s,a+2))return`${t}"${r}" must be the last section in the text area.`;const u=e.match(/(\bfn(?<number>\d+))/g),h=e.match(/(\bfn(?<number>\d+)\.)/g),g=e.match(/(\bfn(?<number>\d+)\.)(?![\s\S]*\1)/g),b=e.match(/(\[(?<number>\d+)\])(?![\s\S]*\1)/g);if(!g)return`${t}There are no references in the text area.`;if(null===b)return`${t}There are no citations in the text area.`;const x=g.length,p=b.length,y=h.length;if(0===n&&u.length>y)return`${o}There may be one or more incorrectly formatted references. Otherwise, the text area contains text in the format "fn[number]". Do you still wish to proceed?`;const S=g.map((e=>e.substring(d,e.length-1))),$=b.map((e=>e.substring(l,e.length-f))),v=S.filter((e=>!$.includes(e))),O=$.filter((e=>!S.includes(e)));return y>x?`${t}Please ensure there are no duplicate references (i.e "fn[number].").`:O.length>0?`${t}Citation${m(O)}unreferenced. Please ensure there are no citations without a reference.`:1!=n&&x-p>0?`${o}Reference${m(v)}uncited. Do you still wish to proceed?`:i}}},401:e=>{"use strict";var n=Function.call.bind(Object.prototype.hasOwnProperty),t=Function.call.bind(Array.prototype.join),r=Function.call.bind(String.prototype.trim),o=Array.isArray,i=Function.call.bind(Array.prototype.filter),s=Function.call.bind(Array.prototype.slice),c=Function.call.bind(Array.prototype.concat);e.exports=function(e){if(!o(e))throw new TypeError("requires an array");var a=arguments.length>1?arguments[1]:null;a||(a={});var u=n(a,"separator")?a.separator:", ",l=n(a,"finalWord")?a.finalWord:"and";l.length>0&&(l+=" ");var f=i(e,r);return 2===f.length&&l.length>0?t(f," "+l):f.length<3?t(f,u):t(c(s(f,0,-1),l+f[f.length-1]),u)}}},n={};function t(r){var o=n[r];if(void 0!==o)return o.exports;var i=n[r]={exports:{}};return e[r](i,i.exports,t),i.exports}(()=>{const e=t(516),{referenceSection:n,textareaId:r,buttonName:o,formatCheckResults:i}=t(619);function s(t){const r=t.value,o=function(n){const{ALERT:t,CONFIRM:r,PASS:o}=i;let s="",c=0;for(;s!==o;){if(s=e.checkFormat(n,c),s.substring(0,7)===t)return alert(s.substring(7)),!1;if(s.substring(0,7)===r){if(confirm(s.substring(7))){c++;continue}return!1}}return!0}(r);if(0==o)return;const s=e.renumberReferences(r),c=r.indexOf(n),a=s.indexOf(n),u=Math.abs(a-c),l=t.selectionStart+u,f=t.selectionEnd+u;t.selectionStart=0,t.selectionEnd=t.value.length,t.focus(),document.execCommand("insertText",!1,s),t.selectionStart=l,t.selectionEnd=f}window.onload=function(){document.getElementById(o).addEventListener("click",(function(){s(document.getElementById(r))}))},modules.export={renumberTextarea:s}})()})();