"use strict";function _interopDefault(t){return t&&"object"==typeof t&&"default"in t?t.default:t}function trimWrappers(t){return t.replace(/\[\[/g,"").replace(/\]\]/g,"").replace(/\{\{/g,"").replace(/\}\}/g,"").trim()}function trimOr(t){var e=t.indexOf("|");return-1!==e?t.substring(0,e):t}function getValue(t,e){if(!t)return null;var r=t.trim().replace(/File:/,"").replace(/\{\{\d+\}\}/g,"").replace(extraPropertyPattern,"").replace(endingPattern,"");if("y"===r||"yes"===r)return!0;if("birthPlace"==e)return t.trim();var a=r.match(linksPattern);return a?a[0].split(linkSeparatorPattern).filter(function(t){return t}):trimOr(trimWrappers(r))}function dataType(t){var e=t.globalPattern,r=t.parsePattern,a=t.parse,n=t.variable,l=t.name;return function(t){var i=t.match(e);if(!i){var s;return s={},defineProperty(s,l,[]),defineProperty(s,"sourceAfter",t),s}var o=i.map(function(t){return a(t.match(r))}),u=i.reduce(function(t,e,r){return o[r]===DO_NOT_REPLACE?t:t.replace(e,"$"+n+"_"+r)},t);return{data:defineProperty({},l,o),sourceAfter:u}}}function byDataHandler(t,e){var r=t.source,a=t.context,n=e(r),l=n.data,i=n.sourceAfter;return{context:Object.assign({},a,l),source:i}}function extractData(t){return dataTypes$1.map(function(t){return t.handler}).reduce(byDataHandler,{context:{},source:t})}function findPropertyList(t){var e=t.match(keyValueGlobalPattern);return e?e.map(function(t){var e=keyValuePattern.exec(t);if(!e)return null;var r=slicedToArray(e,3),a=r[1],n=r[2],l=camelCase(a.trim());return{key:l,value:getValue(n,l)}}).filter(function(t){return t}):[]}function fillVariable(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=r.simplifyDataValues;if("string"!=typeof t)return console.log("Warning: Something went wrong. Could not fill variables in: ("+(void 0===t?"undefined":_typeof(t))+") "+JSON.stringify(t)),{};var n=dataTypes$1.find(function(e){return t.match(e.pattern)});if(n){var l=n.pattern.exec(t),i=slicedToArray(l,2),s=i[0],o=i[1],u=e[n.name][parseInt(o,10)];return a||"string"!=typeof u?u:t.replace(s,u)}return t}function fillVariables(t,e,r){if(void 0===t)return t;if(t instanceof Date)return t;if("number"==typeof t)return t;if(Array.isArray(t))return t.map(function(t){return fillVariables(t,e,r)});if("object"===(void 0===t?"undefined":_typeof(t)))return Object.keys(t).reduce(function(a,n){return Object.assign(a,defineProperty({},n,fillVariables(t[n],e,r)))},{});var a=fillVariable(t,e,r);return a===t?t:fillVariables(a,e,r)}function handleSmallData(t,e,r){var a=r.simplifyDataValues;if("string"==typeof t&&t.match(smallDataType.pattern)){var n=t.replace(smallDataType.pattern,"").replace(/,/,"").trim(),l=smallDataType.pattern.exec(t),i=slicedToArray(l,2),s=i[1],o=e[smallDataType.name][parseInt(s,10)],u={primary:getVariableValue(n,e,{simplifyDataValues:a}),secondary:getVariableValue(o,e,{simplifyDataValues:a})};return a?u.primary:u}return null}function getVariableValue(t,e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=r.simplifyDataValues,n=handleSmallData(t,e,{simplifyDataValues:a});return n||fillVariables(t,e,{simplifyDataValues:a})}function reduceVariable(t,e,r,a){if(null===e)return null;if("boolean"==typeof e)return e;if(Array.isArray(e))return e.map(function(t){return getVariableValue(t,r,a)});if(t.match(/areaTotal/)||t.match(/population/)){var n=numberParse(e);if(!1===n&&(n=parseFloat(e,10)),!isNaN(n))return n}if(t.match(/date/i)){var l=+new Date(e);if(!isNaN(l))return new Date(e)}var i=getVariableValue(e,r,a);return Array.isArray(i)?i.map(function(t){return getVariableValue(t,r,a)}):i}function byVariableReduction(t,e){return function(r,a){var n=a.key,l=a.value,i=reduceVariable(n,l,t,e);return""===i||null===i?r:Object.assign({},r,defineProperty({},n,i))}}function extractProperties(t){var e=t.source,r=t.context,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=a.simplifyDataValues,l=void 0===n||n;return findPropertyList(e).reduce(byVariableReduction(r,{simplifyDataValues:l}),{})}function transformProperties(t){return Object.keys(t).reduce(function(e,r){var a=t[r],n=r.match(blankNamePattern);if(n){var l=n[1]||"",i=t["blank"+l+"NameSec2"],s=t["blank"+l+"InfoSec2"];return"string"!=typeof i?e:Object.assign(e,defineProperty({},camelCase(i),s))}return r.match(blankInfoPattern)?e:Object.assign(e,defineProperty({},r,a))},{})}function findOuterIndex(t){for(var e=[],r=0;r1&&void 0!==arguments[1]?arguments[1]:{},r=e.removeSmall,a=void 0!==r&&r,n=e.removeReferences;return(void 0===n||n)&&(t=t.replace(/]+)?>.*<\/ref>/g,"").replace(/]+)?\s?\/>/g,"")),a&&(t=t.replace(/.*<\/small>/g,"")),t.replace(/'''?/g,"").replace(/\|display=inline/g,"").replace(//g,",").replace(/−/g,"-").replace(//g,"^").replace(/\{\{sfn\|([^\}\}]+)\}\}/g,"").replace(/\{\{efn\|([^\}\}]+)\}\}/g,"").replace(/−/g,"-").replace(/<\/sup>/g,"").replace(/\{\{\s*nowrap\s*\|([^\n\}]+)\}\}/gi,"$1").replace(//g,"").replace(/ /g," ").replace("|''See list''","")}function transformRowSpan(t){return t.map(transformCells).reduce(function(t,e,r){for(var a=0===r?0:1,n=0;n-1){var r=t[0].substring(e+1).slice(0,-2),a=new Date(r+" GMT");if(!isNaN(a.getTime()))return{date:a};if(a=new Date(r.split("|").join("-")+" GMT"),!isNaN(a.getTime()))return{date:a}}return DO_NOT_REPLACE},variable:"LABELED_DATE",name:"labeledDates"},deathDateGlobalPattern=/\{\{death\sdate\sand\sage([^\}\}]+)\}\}/gi,deathDatePattern=/(\d+)\|(\d+)\|(\d+)\|(\d+)\|?(\d+)?\|?(\d+)?/,millisInYear$1=31536e6,deathDates={globalPattern:deathDateGlobalPattern,parsePattern:deathDatePattern,parse:function(t){var e=slicedToArray(t,7),r=e[1],a=e[2],n=e[3],l=e[4],i=e[5],s=void 0===i?0:i,o=e[6],u=void 0===o?0:o,c=new Date(r,a-1,n),f=new Date(l,s-1,u);return{date:c,age:Math.floor((Number(c)-Number(f))/millisInYear$1)}},variable:"DEATH_DATE",name:"deathDates"},URLGlobalPattern=/\{\{URL\|([^\}\}]+)\}\}/g,URLPattern=/URL\|([^\}\}]+)\}\}/,url={globalPattern:URLGlobalPattern,parsePattern:URLPattern,parse:function(t){return slicedToArray(t,2)[1]},variable:"URL",name:"urls"},websiteGlobalPattern=/\[(https?):\/\/((?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6})\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)\s+([\w\s]+)\]/g,websitePattern=/\[(https?):\/\/((?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6})\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)\s+([\w\s]+)\]/,website={globalPattern:websiteGlobalPattern,parsePattern:websitePattern,parse:function(t){var e=slicedToArray(t,5),r=e[1],a=e[2],n=e[3];return{protocol:r,hostname:a,path:n,title:e[4],url:r+"://"+a+n}},variable:"WEBSITE",name:"websites"},globalPattern$1=/\{\{Extra[^}}]+\}\}/gi,parsePattern=/\|\s?(\w+)\s+=\s+(.+)/g,propPattern=/\|\s?(\w+)\s+=\s+(.+)/,extra={globalPattern:globalPattern$1,parsePattern:parsePattern,parse:function(t){return t.reduce(function(t,e){var r=e.match(propPattern),a=slicedToArray(r,3),n=a[1],l=a[2];return t[n]=l,t},{})},variable:"EXTRA",name:"extra"},convertGlobalPattern=/\{\{convert\|([\d\.]+)\|(\w+)/g,convertPattern=/\{\{convert\|([\d\.]+)\|(\w+)/,convert={globalPattern:convertGlobalPattern,parsePattern:convertPattern,parse:function(t){var e=slicedToArray(t,3);return e[1]+" "+e[2]},variable:"CONVERT",name:"converts"},filmDatesPattern=/\{\{film\sdate([^\}\}]+)\}\}/gi,filmDatePatternGlobal=/(\d+)\|?(\d+)\|?(\d+)\|?([^\|\}]*)\|?(ref\d+=([^\|\}]*))?/g,filmDatePattern=/(\d+)\|?(\d+)\|?(\d+)\|?([^\|\}]*)\|?(ref\d+=([^\|\}]*))?/,filmDates={globalPattern:filmDatesPattern,parsePattern:filmDatePatternGlobal,parse:function(t){return t.map(function(t){var e=t.match(filmDatePattern),r=slicedToArray(e,7),a=(r[0],r[1]),n=r[2],l=r[3],i=r[4],s=(r[5],r[6]);return{date:new Date(a,n&&n-1,l),location:i,ref:s}})},variable:"FILM_DATES",name:"filmDates"},otherGlobalPattern$1=/]+)?>(.*)<\/ref>/g,otherPattern$1=/]+)?>(.*)<\/ref>/,attributeGlobalPattern=/(\w+)=(["\w]+)/g,attributePattern=/(\w+)=(["\w]+)/,ref1={globalPattern:otherGlobalPattern$1,parsePattern:otherPattern$1,parse:function(t){var e=slicedToArray(t,3),r=(e[0],e[1]),a=e[2];return{attributes:((r||"").match(attributeGlobalPattern)||[]).reduce(function(t,e){if(e){var r=e.match(attributePattern),a=slicedToArray(r,3),n=(a[0],a[1]),l=a[2];t[n]=l.replace(/"/g,"")}return t},{}),contents:a}},variable:"REF",name:"refs"},otherGlobalPattern$2=/]+)?\/>/g,otherPattern$2=/]+)?\/>/,attributeGlobalPattern$1=/(\w+)=(["\w]+)/g,attributePattern$1=/(\w+)=(["\w]+)/,ref2={globalPattern:otherGlobalPattern$2,parsePattern:otherPattern$2,parse:function(t){return{attributes:t[1].match(attributeGlobalPattern$1).reduce(function(t,e){var r=e.match(attributePattern$1),a=slicedToArray(r,3),n=(a[0],a[1]),l=a[2];return t[n]=l.replace(/"/g,""),t},{})}},variable:"REF",name:"refs"},globalPattern$2=/\{\{formatnum:\d+\}\}/gi,parsePattern$1=/\{\{formatnum:(\d+)\}\}/,formatNum={globalPattern:globalPattern$2,parsePattern:parsePattern$1,parse:function(t){var e=slicedToArray(t,2),r=e[1];return parseFloat(r)},variable:"FORMAT_NUM",name:"formatNum"},dataTypes=[instances,ref1,ref2,small,formatNum,flag,coords,marriages,birthDates,labeledDates,deathDates,unbulletedLists,website,hlist,url,convert,nbay,filmDates,other,extra,plainLists,unmarkedLists],dataTypes$1=dataTypes.map(function(t){return{handler:dataType(t),name:t.name,pattern:new RegExp("\\$"+t.variable+"_(\\d+)")}}),keyValueGlobalPattern=/\|\s*([-'\u0400-\u04FF\w\s]+)\s*=\s*([^|]+)?/g,keyValuePattern=/\|\s*([-'\u0400-\u04FF\w\s]+)\s*=\s*([^|]+)?/,numberParse=function(t){return"string"==typeof t&&(t=t.trim().replace(/ /g,""),t.match(/,/)&&t.match(/\./)?t.indexOf(",")1?parseEnglish(t):t.match(/,[0-9]{3}($|^[0-9])/)?parseEnglish(t):parseSpanish(t):!t.match(/,/)&&t.match(/\./)?t.match(/\./g).length>1?parseSpanish(t):t.match(/\.[0-9]{3}($|^[0-9])/)?parseSpanish(t):parseEnglish(t):(+t).toString()===t&&+t)},parseEnglish=function(t){return+t.replace(/,/g,"")},parseSpanish=function(t){return+t.replace(/\./g,"").replace(/,/g,".")},smallDataType=dataTypes$1.find(function(t){return"smalls"===t.name}),blankNamePattern=/blank(\d+)?NameSec2/,blankInfoPattern=/blank(\d+)?InfoSec2/,infoBoxStartPattern=/{{\w*box/,tableStartPattern=/{\|(.*)\n?/,tableEndPattern=/\n\|}/,headersPattern=/!\s?(.*)/g,rowPattern=/\|-/,cellSeparatorPattern=/(?:\n\|)|(?:\|\|)/,linkPattern=/\[\[([^\]]+)\]\]/g,linkNamePattern=/^.*\|/,inlineHeaderPattern="!!",actionPattern=/{{anchor\|(.*)}}/g,rowSpanCountPattern=/rowspan="(\d+)"/,stripLinks=function(t){return t.replace(linkPattern,function(t,e){return e.replace(linkNamePattern,"").trim()||e})},removeActions=function(t){return t.replace(actionPattern,"")},transformCell=function(t){return stripLinks(removeActions(t||"")).replace(rowSpanCountPattern,"").replace(linkNamePattern,"").trim()},transformCells=function(t){return t.split(cellSeparatorPattern).map(transformCell)},findIndex=function(t,e){var r=t.match(e);return r?r.index:-1},findTableStart=function(t){var e=t.match(tableStartPattern);return e?e.index+e[0].length:-1},findTableEnd=function(t){return findIndex(t,tableEndPattern)},getHeaders=function(t){for(var e=[],r=void 0;r=headersPattern.exec(t);)e.push.apply(e,toConsumableArray(r[1].split(inlineHeaderPattern).map(transformCell)));return e},getRows=function(t){var e=t.split(rowPattern).map(function(t){return t.replace(/^.*\n+?\|/,"").trim()}).filter(function(t){return t}),r=[],a=0,n=0,l=[],i=!0,s=!1,o=void 0;try{for(var u,c=e[Symbol.iterator]();!(i=(u=c.next()).done);i=!0){var f=u.value,p=f.match(rowSpanCountPattern);p&&(a=0,n=parseInt(p[1]),l=[]),a