UNPKG

json-variables

Version:

Resolves custom-marked, cross-referenced paths in parsed JSON

159 lines (152 loc) 49.6 kB
/** * @name json-variables * @fileoverview Resolves custom-marked, cross-referenced paths in parsed JSON * @version 12.0.23 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/json-variables/} */ "use strict";var jsonVariables=(()=>{var Ve=Object.create;var j=Object.defineProperty,He=Object.defineProperties,Ce=Object.getOwnPropertyDescriptor,je=Object.getOwnPropertyDescriptors,Me=Object.getOwnPropertyNames,ae=Object.getOwnPropertySymbols,Be=Object.getPrototypeOf,oe=Object.prototype.hasOwnProperty,Pe=Object.prototype.propertyIsEnumerable;var Q=(e,r,n)=>r in e?j(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n,O=(e,r)=>{for(var n in r||(r={}))oe.call(r,n)&&Q(e,n,r[n]);if(ae)for(var n of ae(r))Pe.call(r,n)&&Q(e,n,r[n]);return e},M=(e,r)=>He(e,je(r));var le=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),Je=(e,r)=>{for(var n in r)j(e,n,{get:r[n],enumerable:!0})},ue=(e,r,n,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let f of Me(r))!oe.call(e,f)&&f!==n&&j(e,f,{get:()=>r[f],enumerable:!(i=Ce(r,f))||i.enumerable});return e};var k=(e,r,n)=>(n=e!=null?Ve(Be(e)):{},ue(r||!e||!e.__esModule?j(n,"default",{value:e,enumerable:!0}):n,e)),ke=e=>ue(j({},"__esModule",{value:!0}),e);var Z=(e,r,n)=>Q(e,typeof r!="symbol"?r+"":r,n);var F=le((gr,fe)=>{"use strict";fe.exports=Fe;function R(e){return e instanceof Buffer?Buffer.from(e):new e.constructor(e.buffer.slice(),e.byteOffset,e.length)}function Fe(e){if(e=e||{},e.circles)return Le(e);let r=new Map;if(r.set(Date,s=>new Date(s)),r.set(Map,(s,o)=>new Map(i(Array.from(s),o))),r.set(Set,(s,o)=>new Set(i(Array.from(s),o))),e.constructorHandlers)for(let s of e.constructorHandlers)r.set(s[0],s[1]);let n=null;return e.proto?t:f;function i(s,o){let u=Object.keys(s),l=new Array(u.length);for(let a=0;a<u.length;a++){let c=u[a],$=s[c];typeof $!="object"||$===null?l[c]=$:$.constructor!==Object&&(n=r.get($.constructor))?l[c]=n($,o):ArrayBuffer.isView($)?l[c]=R($):l[c]=o($)}return l}function f(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return i(s,f);if(s.constructor!==Object&&(n=r.get(s.constructor)))return n(s,f);let o={};for(let u in s){if(Object.hasOwnProperty.call(s,u)===!1)continue;let l=s[u];typeof l!="object"||l===null?o[u]=l:l.constructor!==Object&&(n=r.get(l.constructor))?o[u]=n(l,f):ArrayBuffer.isView(l)?o[u]=R(l):o[u]=f(l)}return o}function t(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return i(s,t);if(s.constructor!==Object&&(n=r.get(s.constructor)))return n(s,t);let o={};for(let u in s){let l=s[u];typeof l!="object"||l===null?o[u]=l:l.constructor!==Object&&(n=r.get(l.constructor))?o[u]=n(l,t):ArrayBuffer.isView(l)?o[u]=R(l):o[u]=t(l)}return o}}function Le(e){let r=[],n=[],i=new Map;if(i.set(Date,u=>new Date(u)),i.set(Map,(u,l)=>new Map(t(Array.from(u),l))),i.set(Set,(u,l)=>new Set(t(Array.from(u),l))),e.constructorHandlers)for(let u of e.constructorHandlers)i.set(u[0],u[1]);let f=null;return e.proto?o:s;function t(u,l){let a=Object.keys(u),c=new Array(a.length);for(let $=0;$<a.length;$++){let d=a[$],h=u[d];if(typeof h!="object"||h===null)c[d]=h;else if(h.constructor!==Object&&(f=i.get(h.constructor)))c[d]=f(h,l);else if(ArrayBuffer.isView(h))c[d]=R(h);else{let y=r.indexOf(h);y!==-1?c[d]=n[y]:c[d]=l(h)}}return c}function s(u){if(typeof u!="object"||u===null)return u;if(Array.isArray(u))return t(u,s);if(u.constructor!==Object&&(f=i.get(u.constructor)))return f(u,s);let l={};r.push(u),n.push(l);for(let a in u){if(Object.hasOwnProperty.call(u,a)===!1)continue;let c=u[a];if(typeof c!="object"||c===null)l[a]=c;else if(c.constructor!==Object&&(f=i.get(c.constructor)))l[a]=f(c,s);else if(ArrayBuffer.isView(c))l[a]=R(c);else{let $=r.indexOf(c);$!==-1?l[a]=n[$]:l[a]=s(c)}}return r.pop(),n.pop(),l}function o(u){if(typeof u!="object"||u===null)return u;if(Array.isArray(u))return t(u,o);if(u.constructor!==Object&&(f=i.get(u.constructor)))return f(u,o);let l={};r.push(u),n.push(l);for(let a in u){let c=u[a];if(typeof c!="object"||c===null)l[a]=c;else if(c.constructor!==Object&&(f=i.get(c.constructor)))l[a]=f(c,o);else if(ArrayBuffer.isView(c))l[a]=R(c);else{let $=r.indexOf(c);$!==-1?l[a]=n[$]:l[a]=o(c)}}return r.pop(),n.pop(),l}}});var We=le((Ie,z)=>{(function(e,r){"use strict";typeof z=="object"&&typeof z.exports=="object"?z.exports=r():typeof define=="function"&&define.amd?define([],r):e.objectPath=r()})(Ie,function(){"use strict";var e=Object.prototype.toString;function r(a,c){return a==null?!1:Object.prototype.hasOwnProperty.call(a,c)}function n(a){if(!a||t(a)&&a.length===0)return!0;if(typeof a!="string"){for(var c in a)if(r(a,c))return!1;return!0}return!1}function i(a){return e.call(a)}function f(a){return typeof a=="object"&&i(a)==="[object Object]"}var t=Array.isArray||function(a){return e.call(a)==="[object Array]"};function s(a){return typeof a=="boolean"||i(a)==="[object Boolean]"}function o(a){var c=parseInt(a);return c.toString()===a?c:a}function u(a){a=a||{};var c=function(m){return Object.keys(c).reduce(function(g,p){return p==="create"||typeof c[p]=="function"&&(g[p]=c[p].bind(c,m)),g},{})},$;a.includeInheritedProps?$=function(){return!0}:$=function(m,g){return typeof g=="number"&&Array.isArray(m)||r(m,g)};function d(m,g){if($(m,g))return m[g]}var h;a.includeInheritedProps?h=function(m,g){typeof g!="string"&&typeof g!="number"&&(g=String(g));var p=d(m,g);if(g==="__proto__"||g==="prototype"||g==="constructor"&&typeof p=="function")throw new Error("For security reasons, object's magic properties cannot be set");return p}:h=function(m,g){return d(m,g)};function y(m,g,p,b){if(typeof g=="number"&&(g=[g]),!g||g.length===0)return m;if(typeof g=="string")return y(m,g.split(".").map(o),p,b);var w=g[0],v=h(m,w);return g.length===1?((v===void 0||!b)&&(m[w]=p),v):(v===void 0&&(typeof g[1]=="number"?m[w]=[]:m[w]={}),y(m[w],g.slice(1),p,b))}return c.has=function(m,g){if(typeof g=="number"?g=[g]:typeof g=="string"&&(g=g.split(".")),!g||g.length===0)return!!m;for(var p=0;p<g.length;p++){var b=o(g[p]);if(typeof b=="number"&&t(m)&&b<m.length||(a.includeInheritedProps?b in Object(m):r(m,b)))m=m[b];else return!1}return!0},c.ensureExists=function(m,g,p){return y(m,g,p,!0)},c.set=function(m,g,p,b){return y(m,g,p,b)},c.insert=function(m,g,p,b){var w=c.get(m,g);b=~~b,t(w)||(w=[],c.set(m,g,w)),w.splice(b,0,p)},c.empty=function(m,g){if(!n(g)&&m!=null){var p,b;if(p=c.get(m,g)){if(typeof p=="string")return c.set(m,g,"");if(s(p))return c.set(m,g,!1);if(typeof p=="number")return c.set(m,g,0);if(t(p))p.length=0;else if(f(p))for(b in p)$(p,b)&&delete p[b];else return c.set(m,g,null)}}},c.push=function(m,g){var p=c.get(m,g);t(p)||(p=[],c.set(m,g,p)),p.push.apply(p,Array.prototype.slice.call(arguments,2))},c.coalesce=function(m,g,p){for(var b,w=0,v=g.length;w<v;w++)if((b=c.get(m,g[w]))!==void 0)return b;return p},c.get=function(m,g,p){if(typeof g=="number"&&(g=[g]),!g||g.length===0)return m;if(m==null)return p;if(typeof g=="string")return c.get(m,g.split("."),p);var b=o(g[0]),w=h(m,b);return w===void 0?p:g.length===1?w:c.get(m[b],g.slice(1),p)},c.del=function(g,p){if(typeof p=="number"&&(p=[p]),g==null||n(p))return g;if(typeof p=="string")return c.del(g,p.split("."));var b=o(p[0]);if(h(g,b),!$(g,b))return g;if(p.length===1)t(g)?g.splice(b,1):delete g[b];else return c.del(g[b],p.slice(1));return g},c}var l=u();return l.create=u,l.withInheritedProps=u({includeInheritedProps:!0}),l})});var ur={};Je(ur,{defaults:()=>_e,jVar:()=>lr,version:()=>tr});function I(e){return typeof e!="string"?e:e.length?[e]:[]}var ce=k(F(),1);var hr=(0,ce.default)();function E(e){if(e==null||typeof e!="object")return!1;let r=Object.getPrototypeOf(e);return r!==null&&r!==Object.prototype&&Object.getPrototypeOf(r)!==null?!1:!(Symbol.iterator in e)&&!(Symbol.toStringTag in e)}function T(e){return typeof e=="string"}function ge(e){return Number.isFinite(e)}function _(e){return Number.isSafeInteger(e)&&e>=0}function L(e){return typeof e=="boolean"}function B(e){return e===null}function W(e){return e!=null}function he(e,r){return E(e)&&T(r)&&r in e}var pe={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},qe=e=>e+1;function Ue(e,r,n,i,f=!1,t=qe){var b;let s=typeof n=="function"?n():n;if(+r<0&&f&&s==="EOL")return s;let o=O(O({},pe),i);if(r>=e.length&&!f)return!1;let u=f?1:n.length,l=0,a=!1,c=!1,$=!1,d=o.maxMismatches,h=r,y=!1,m=!1,g=!1;function p(){return l===1&&d<o.maxMismatches-1}for(;e[h];){let w=t(h);if(o.trimBeforeMatching&&e[h].trim()===""){if(!e[w]&&f&&n==="EOL")return!0;h=t(h);continue}if(o&&!o.i&&((b=o==null?void 0:o.trimCharsBeforeMatching)!=null&&b.includes(e[h]))||o!=null&&o.i&&o.trimCharsBeforeMatching&&o.trimCharsBeforeMatching.map(S=>S.toLowerCase()).includes(e[h].toLowerCase())){if(f&&n==="EOL"&&!e[w])return!0;h=t(h);continue}let v=w>h?n[n.length-u]:n[u-1];if(!o.i&&e[h]===v||o.i&&e[h].toLowerCase()===v.toLowerCase()){if(y||(y=!0),$||($=!0),u===n.length){if(m=!0,d!==o.maxMismatches)return!1}else u===1&&(g=!0);if(u-=1,l++,p())return!1;if(!u)return l!==n.length||d===o.maxMismatches||!a?h:!1}else if(!a&&!l&&(a=!0),o.maxMismatches&&d&&h){d-=1;for(let S=0;S<=d;S++){let x=w>h?n[n.length-u+1+S]:n[u-2-S],G=e[t(h)];if(x&&(!o.i&&e[h]===x||o.i&&e[h].toLowerCase()===x.toLowerCase())&&(!o.firstMustMatch||u!==n.length)){if(l++,p())return!1;u-=2,y=!0;break}else if(G&&x&&(!o.i&&G===x||o.i&&G.toLowerCase()===x.toLowerCase())&&(!o.firstMustMatch||u!==n.length)){if(!l&&!o.hungry)return!1;u-=1,y=!0;break}else if(x===void 0&&d>=0&&y&&(!o.firstMustMatch||m)&&(!o.lastMustMatch||g))return h}y||(c=h)}else return h===0&&u===1&&!o.lastMustMatch&&$?0:!1;if(c!==!1&&c!==h&&(c=!1),u<1)return h;h=t(h)}if(u>0)return f&&s==="EOL"?!0:o&&o.maxMismatches>=u&&$?c||0:!1}function de(e,r,n,i,f){var a,c,$;if(E(f)&&he(f,"trimBeforeMatching")&&f&&typeof f.trimBeforeMatching!="boolean")throw new Error(`string-match-left-right/${e}(): [THROW_ID_09] opts.trimBeforeMatching should be boolean!${Array.isArray(f.trimBeforeMatching)?" Did you mean to use opts.trimCharsBeforeMatching?":""}`);let t=O(O({},pe),f);if(typeof t.trimCharsBeforeMatching=="string"&&(t.trimCharsBeforeMatching=I(t.trimCharsBeforeMatching)),t.trimCharsBeforeMatching=t.trimCharsBeforeMatching.map(d=>T(d)?d:String(d)),!T(r)||!r.length)return!1;if(!Number.isInteger(n)||n<0)throw new Error(`string-match-left-right/${e}(): [THROW_ID_03] the second argument should be a natural number. Currently it's of a type: ${typeof n}, equal to: ${JSON.stringify(n,null,4)}`);let s,o;if(T(i))s=[i];else if(Array.isArray(i))s=i;else if(!i)s=i;else if(typeof i=="function")s=[],s.push(i);else throw new Error(`string-match-left-right/${e}(): [THROW_ID_05] the third argument, whatToMatch, is neither string nor array of strings! It's ${typeof i}, equal to: ${JSON.stringify(i,null,4)}`);if(f&&!E(f))throw new Error(`string-match-left-right/${e}(): [THROW_ID_06] the fourth argument, options object, should be a plain object. Currently it's of a type "${typeof f}", and equal to: ${JSON.stringify(f,null,4)}`);let u=0,l="";if((a=t==null?void 0:t.trimCharsBeforeMatching)!=null&&a.some((d,h)=>d.length>1?(u=h,l=d,!0):!1))throw new Error(`string-match-left-right/${e}(): [THROW_ID_07] the fourth argument, options object contains trimCharsBeforeMatching. It was meant to list the single characters but one of the entries at index ${u} is longer than 1 character, ${l.length} (equals to ${l}). Please split it into separate characters and put into array as separate elements.`);if(!s||!Array.isArray(s)||Array.isArray(s)&&!s.length||Array.isArray(s)&&s.length===1&&T(s[0])&&!s[0].trim()){if(typeof t.cb=="function"){let h,y=n;if((e==="matchLeftIncl"||e==="matchRight")&&(y+=1),e[5]==="L")for(let b=y;b--;){let w=r[b];if((!t.trimBeforeMatching||t.trimBeforeMatching&&(w!=null&&w.trim()))&&(!((c=t.trimCharsBeforeMatching)!=null&&c.length)||w!==void 0&&!t.trimCharsBeforeMatching.includes(w))){h=b;break}}else if(e.startsWith("matchRight"))for(let b=y;b<r.length;b++){let w=r[b];if((!t.trimBeforeMatching||t.trimBeforeMatching&&w.trim())&&(!(($=t.trimCharsBeforeMatching)!=null&&$.length)||!t.trimCharsBeforeMatching.includes(w))){h=b;break}}if(h===void 0)return!1;let m=r[h],g=h+1,p="";return g&&g>0&&(p=r.slice(0,g)),e[5]==="L"||h&&h>0&&(p=r.slice(h)),t.cb(m,p,h)}let d="";throw f||(d=" More so, the whole options object, the fourth input argument, is missing!"),new Error(`string-match-left-right/${e}(): [THROW_ID_08] the third argument, "whatToMatch", was given as an empty string. This means, you intend to match purely by a callback. The callback was not set though, the opts key "cb" is not set!${d}`)}for(let d=0,h=s.length;d<h;d++){o=typeof s[d]=="function";let y=s[d],m,g,p="",b=n;e==="matchRight"?b+=1:e==="matchLeft"&&(b-=1);let w=Ue(r,b,y,t,o,v=>e[5]==="L"?v-1:v+1);if(w&&o&&typeof y=="function"&&y()==="EOL")return y()&&(!t.cb||t.cb(m,p,g))?y():!1;if(Number.isInteger(w)&&(g=e.startsWith("matchLeft")?w-1:w+1,e[5]==="L"?p=r.slice(0,w):p=r.slice(g)),g<0&&(g=void 0),r[g]&&(m=r[g]),Number.isInteger(w)&&(!t.cb||t.cb(m,p,g)))return y}return!1}function V(e,r,n,i){return de("matchLeftIncl",e,r,n,i)}function D(e,r,n,i){return de("matchRightIncl",e,r,n,i)}function q(e,r=1){let n="\xA0";function i(t){return Array.from(t).reverse().join("")}function f(t,s,o){let u=o?` `:"\r",l=o?"\r":` `;if(!t)return t;let a=0,c=0,$="";for(let d=0,h=t.length;d<h;d++)(t[d]===u||t[d]===l&&t[d-1]!==u)&&c++,`\r `.includes(t[d])||t[d]===n?(a=0,t[d]===n?$+=t[d]:t[d]===u?c<=s&&($+=t[d],t[d+1]===l&&($+=t[d+1],d++)):t[d]===l&&(t==null?void 0:t[d-1])!==u&&c<=s&&($+=t[d])):(a++,!t[d+1]&&!c&&($+=" "));return $}if(typeof e=="string"&&e.length){let t=1;typeof+r=="number"&&Number.isInteger(+r)&&+r>=0&&(t=+r);let s="",o="";if(!e.trim())s=e;else if(!e[0].trim()){for(let u=0,l=e.length;u<l;u++)if(e[u].trim()){s=e.slice(0,u);break}}if(e.trim()&&(e.slice(-1).trim()===""||e.slice(-1)===n)){for(let u=e.length;u--;)if(e[u].trim()){o=e.slice(u+1);break}}return`${f(s,t,!1)}${e.trim()}${i(f(i(o),t,!0))}`}return e}var Ke={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function H(e,r){if(!Array.isArray(e)||!e.length)return e;let n=O(O({},Ke),r),i,f;if(n.strictlyTwoElementsInRangeArrays&&!e.every((o,u)=>!Array.isArray(o)||o.length!==2?(i=u,f=o.length,!1):!0))throw new TypeError(`ranges-sort: [THROW_ID_03] The first argument should be an array and must consist of arrays which are natural number indexes representing TWO string index ranges. However, ${i}th range (${JSON.stringify(e[i],null,4)}) has not two but ${f} elements!`);if(!e.every((o,u)=>!Array.isArray(o)||!Number.isInteger(o[0])||o[0]<0||!Number.isInteger(o[1])||o[1]<0?(i=u,!1):!0))throw new TypeError(`ranges-sort: [THROW_ID_04] The first argument should be an array and must consist of arrays which are natural number indexes representing string index ranges. However, ${i}th range (${JSON.stringify(e[i],null,4)}) does not consist of only natural numbers!`);let t=e.length**2,s=0;return Array.from(e).sort((o,u)=>(n.progressFn&&(s+=1,n.progressFn(Math.floor(s*100/t))),o[0]===u[0]?o[1]<u[1]?-1:o[1]>u[1]?1:0:o[0]<u[0]?-1:1))}var ye={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function ze(e,r){var l;function n(a){return!!a&&typeof a=="object"&&!Array.isArray(a)}if(!Array.isArray(e)||!e.length)return null;let i;if(r)if(n(r)){if(i=O(O({},ye),r),i.progressFn&&n(i.progressFn)&&!Object.keys(i.progressFn).length)i.progressFn=null;else if(i.progressFn&&typeof i.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] resolvedOpts.progressFn must be a function! It was given of a type: "${typeof i.progressFn}", equal to ${JSON.stringify(i.progressFn,null,4)}`);if(![1,2,"1","2"].includes(i.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] resolvedOpts.mergeType was customised to a wrong thing! It was given of a type: "${typeof i.mergeType}", equal to ${JSON.stringify(i.mergeType,null,4)}`);if(typeof i.joinRangesThatTouchEdges!="boolean")throw new Error(`ranges-merge: [THROW_ID_04] resolvedOpts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof i.joinRangesThatTouchEdges}", equal to ${JSON.stringify(i.joinRangesThatTouchEdges,null,4)}`)}else throw new Error(`ranges-merge: [THROW_ID_03] the second input argument must be a plain object. It was given as: ${JSON.stringify(r,null,4)} (type ${typeof r})`);else i=O({},ye);let f=e.filter(a=>Array.isArray(a)).map(a=>[...a]).filter(a=>a[2]!==void 0||a[0]!==a[1]),t,s,o;i.progressFn?t=H(f,{progressFn:a=>{o=Math.floor(a/5),o!==s&&(s=o,i.progressFn!=null&&i.progressFn(o))}}):t=H(f);let u=t.length-1;for(let a=u;a>0;a--)i.progressFn&&(o=Math.floor((1-a/u)*78)+21,o!==s&&o>s&&(s=o,i.progressFn(o))),(t[a][0]<=t[a-1][0]||!i.joinRangesThatTouchEdges&&t[a][0]<t[a-1][1]||i.joinRangesThatTouchEdges&&t[a][0]<=t[a-1][1])&&(t[a-1][0]=Math.min(t[a][0],t[a-1][0]),t[a-1][1]=Math.max(t[a][1],t[a-1][1]),t[a][2]!==void 0&&(t[a-1][0]>=t[a][0]||t[a-1][1]<=t[a][1])&&t[a-1][2]!==null&&(t[a][2]===null&&t[a-1][2]!==null?t[a-1][2]=null:t[a-1][2]!=null?+((l=i||{})==null?void 0:l.mergeType)==2&&t[a-1][0]===t[a][0]?t[a-1][2]=t[a][2]:t[a-1][2]+=t[a][2]:t[a-1][2]=t[a][2]),t.splice(a,1),a=t.length);return t.length?t:null}var Ge={limitToBeAddedWhitespace:!1,limitLinebreaksCount:1,mergeType:1},P=class{constructor(e){Z(this,"ranges");Z(this,"opts");let r=O(O({},Ge),e);if(r.mergeType&&r.mergeType!==1&&r.mergeType!==2)if(T(r.mergeType)&&r.mergeType.trim()==="1")r.mergeType=1;else if(T(r.mergeType)&&r.mergeType.trim()==="2")r.mergeType=2;else throw new Error(`ranges-push: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof r.mergeType}", equal to ${JSON.stringify(r.mergeType,null,4)}`);this.opts=r,this.ranges=[]}add(e,r,n){var t;if(e==null&&r==null)return;if(W(e)&&!W(r)){if(Array.isArray(e)){if(e.length){if(e.some(s=>Array.isArray(s))){e.forEach(s=>{Array.isArray(s)&&this.add(...s)});return}e.length&&_(+e[0])&&_(+e[1])&&this.add(...e)}return}throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_12] the first input argument, "from" is set (${JSON.stringify(e,null,0)}) but second-one, "to" is not (${JSON.stringify(r,null,0)})`)}else if(!W(e)&&W(r))throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_13] the second input argument, "to" is set (${JSON.stringify(r,null,0)}) but first-one, "from" is not (${JSON.stringify(e,null,0)})`);let i=+e,f=+r;if(_(n)&&(n=String(n)),_(i)&&_(f)){if(W(n)&&!T(n)&&!_(n))throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_08] The third argument, the value to add, was given not as string but ${typeof n}, equal to: ${JSON.stringify(n,null,4)}`);if(W(this.ranges)&&Array.isArray(this.last())&&i===this.last()[1]){if(this.last()[1]=f,this.last()[2],this.last()[2]!==null&&W(n)){let s=this.last()[2]&&this.last()[2].length&&(!((t=this.opts)!=null&&t.mergeType)||this.opts.mergeType===1)?`${this.last()[2]}${n}`:n;this.opts.limitToBeAddedWhitespace&&(s=q(s,this.opts.limitLinebreaksCount)),T(s)&&!s.length||(this.last()[2]=s)}}else{this.ranges||(this.ranges=[]);let s=n!==void 0&&!(T(n)&&!n.length)?[i,f,n&&this.opts.limitToBeAddedWhitespace?q(n,this.opts.limitLinebreaksCount):n]:[i,f];this.ranges.push(s)}}else throw _(i)&&i>=0?new TypeError(`ranges-push/Ranges/add(): [THROW_ID_10] "to" value, the second input argument, must be a natural number or zero! Currently it's of a type "${typeof f}" equal to: ${JSON.stringify(f,null,4)}`):new TypeError(`ranges-push/Ranges/add(): [THROW_ID_09] "from" value, the first input argument, must be a natural number or zero! Currently it's of a type "${typeof i}" equal to: ${JSON.stringify(i,null,4)}`)}push(e,r,n){this.add(e,r,n)}current(){return Array.isArray(this.ranges)&&this.ranges.length?(this.ranges=ze(this.ranges,{mergeType:this.opts.mergeType}),this.ranges&&this.opts.limitToBeAddedWhitespace?this.ranges.map(e=>W(e[2])?[e[0],e[1],q(e[2],this.opts.limitLinebreaksCount)]:e):this.ranges):null}wipe(){this.ranges=[]}replace(e){if(Array.isArray(e)&&e.length)if(Array.isArray(e[0])&&_(e[0][0]))this.ranges=Array.from(e);else throw new Error(`ranges-push/Ranges/replace(): [THROW_ID_11] Single range was given but we expected array of arrays! The first element, ${JSON.stringify(e[0],null,4)} should be an array and its first element should be an integer, a string index.`);else this.ranges=[]}last(){return Array.isArray(this.ranges)&&this.ranges.length?this.ranges[this.ranges.length-1]:null}};var me={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function we(e,r){function n(l){return!!l&&typeof l=="object"&&!Array.isArray(l)}if(!Array.isArray(e)||!e.length)return null;let i;if(r)if(n(r)){if(i=O(O({},me),r),i.progressFn&&n(i.progressFn)&&!Object.keys(i.progressFn).length)i.progressFn=null;else if(i.progressFn&&typeof i.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof i.progressFn}", equal to ${JSON.stringify(i.progressFn,null,4)}`);if(![1,2,"1","2"].includes(i.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof i.mergeType}", equal to ${JSON.stringify(i.mergeType,null,4)}`);if(typeof i.joinRangesThatTouchEdges!="boolean")throw new Error(`ranges-merge: [THROW_ID_04] opts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "${typeof i.joinRangesThatTouchEdges}", equal to ${JSON.stringify(i.joinRangesThatTouchEdges,null,4)}`)}else throw new Error(`emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as: ${JSON.stringify(r,null,4)} (type ${typeof r})`);else i=O({},me);let f=e.filter(l=>Array.isArray(l)).map(l=>[...l]).filter(l=>l[2]!==void 0||l[0]!==l[1]),t,s,o;i.progressFn?t=H(f,{progressFn:l=>{o=Math.floor(l/5),o!==s&&(s=o,i.progressFn(o))}}):t=H(f);let u=t.length-1;for(let l=u;l>0;l--)i.progressFn&&(o=Math.floor((1-l/u)*78)+21,o!==s&&o>s&&(s=o,i.progressFn(o))),(t[l][0]<=t[l-1][0]||!i.joinRangesThatTouchEdges&&t[l][0]<t[l-1][1]||i.joinRangesThatTouchEdges&&t[l][0]<=t[l-1][1])&&(t[l-1][0]=Math.min(t[l][0],t[l-1][0]),t[l-1][1]=Math.max(t[l][1],t[l-1][1]),t[l][2]!==void 0&&(t[l-1][0]>=t[l][0]||t[l-1][1]<=t[l][1])&&t[l-1][2]!==null&&(t[l][2]===null&&t[l-1][2]!==null?t[l-1][2]=null:t[l-1][2]!=null?+i.mergeType==2&&t[l-1][0]===t[l][0]?t[l-1][2]=t[l][2]:t[l-1][2]+=t[l][2]:t[l-1][2]=t[l][2]),t.splice(l,1),l=t.length);return t.length?t:null}var Qe=!0,Y="Invariant failed";function be(e,r){if(!e){if(Qe)throw new Error(Y);var n=typeof r=="function"?r():r,i=n?"".concat(Y,": ").concat(n):Y;throw new Error(i)}}function C(e,r,n){let i=0,f=0;if(arguments.length===0)throw new Error("ranges-apply: [THROW_ID_01] inputs missing!");if(typeof e!="string")throw new TypeError(`ranges-apply: [THROW_ID_02] first input argument must be a string! Currently it's: ${typeof e}, equal to: ${JSON.stringify(e,null,4)}`);if(r&&!Array.isArray(r))throw new TypeError(`ranges-apply: [THROW_ID_03] second input argument must be an array (or null)! Currently it's: ${typeof r}, equal to: ${JSON.stringify(r,null,4)}`);if(n&&typeof n!="function")throw new TypeError(`ranges-apply: [THROW_ID_04] the third input argument must be a function (or falsey)! Currently it's: ${typeof n}, equal to: ${JSON.stringify(n,null,4)}`);if(!(r!=null&&r.filter(a=>a).length))return e;let t;Array.isArray(r)&&Number.isInteger(r[0])&&Number.isInteger(r[1])?t=[Array.from(r)]:t=Array.from(r);let s=t.length,o=0;t.filter(a=>a).forEach((a,c)=>{if(n&&(i=Math.floor(o/s*10),i!==f&&(f=i,n(i))),!Array.isArray(a))throw new TypeError(`ranges-apply: [THROW_ID_05] ranges array, second input arg., has ${c}th element not an array: ${JSON.stringify(a,null,4)}, which is ${typeof a}`);if(!Number.isInteger(a[0])){if(!Number.isInteger(+a[0])||+a[0]<0)throw new TypeError(`ranges-apply: [THROW_ID_06] ranges array, second input arg. has ${c}th element, array ${JSON.stringify(a,null,0)}. Its first element is not an integer, string index, but ${typeof a[0]}, equal to: ${JSON.stringify(a[0],null,4)}.`);t[c][0]=+t[c][0]}if(!Number.isInteger(a[1])){if(!Number.isInteger(+a[1])||+a[1]<0)throw new TypeError(`ranges-apply: [THROW_ID_07] ranges array, second input arg. has ${c}th element, array ${JSON.stringify(a,null,0)}. Its second element is not an integer, string index, but ${typeof a[1]}, equal to: ${JSON.stringify(a[1],null,4)}.`);t[c][1]=+t[c][1]}o+=1});let u=we(t,{progressFn:a=>{n&&(i=10+Math.floor(a/10),i!==f&&(f=i,n(i)))}});be(u);let l=u.length;if(l>0){let a=e.slice(u[l-1][1]);e=u.reduce((c,$,d,h)=>{n&&(i=20+Math.floor(d/l*80),i!==f&&(f=i,n(i)));let y=d===0?0:h[d-1][1],m=h[d][0];return`${c}${e.slice(y,m)}${h[d][2]||""}`},""),e+=a}return e}var Ze={classicTrim:!1,cr:!1,lf:!1,tab:!1,space:!0,nbsp:!1};function J(e,r){if(typeof e!="string")throw new Error(`string-trim-spaces-only: [THROW_ID_01] input must be string! It was given as ${typeof e}, equal to: ${JSON.stringify(e,null,4)}`);let n=O(O({},Ze),r);function i(s){return n.classicTrim&&!s.trim()||!n.classicTrim&&(n.space&&s===" "||n.cr&&s==="\r"||n.lf&&s===` `||n.tab&&s===" "||n.nbsp&&s==="\xA0")}let f,t;if(e.length){if(i(e[0]))for(let s=0,o=e.length;s<o;s++){if(!i(e[s])){f=s;break}if(s===e.length-1)return{res:"",ranges:[[0,e.length]]}}if(i(e[e.length-1])){for(let s=e.length;s--;)if(!i(e[s])){t=s+1;break}}return f?t?{res:e.slice(f,t),ranges:[[0,f],[t,e.length]]}:{res:e.slice(f),ranges:[[0,f]]}:t?{res:e.slice(0,t),ranges:[[t,e.length]]}:{res:e,ranges:[]}}return{res:"",ranges:[]}}var Ye={heads:["{{"],tails:["}}"]};function $e(e,r){let n=Object.prototype.hasOwnProperty;if(e===void 0)throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_01] The input is missing!");if(typeof e!="string")return e;if(r&&!E(r))throw new Error(`string-remove-duplicate-heads-tails: [THROW_ID_03] The given options are not a plain object but ${typeof r}!`);let i=O({},r);if(i&&n.call(i,"heads"))if(I(i.heads).every(y=>typeof y=="string"||Array.isArray(y)))typeof i.heads=="string"&&(i.heads=I(i.heads));else throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_04] The resolvedOpts.heads contains elements which are not string-type!");if(i&&n.call(i,"tails"))if(I(i.tails).every(y=>typeof y=="string"||Array.isArray(y)))typeof i.tails=="string"&&(i.tails=I(i.tails));else throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_05] The resolvedOpts.tails contains elements which are not string-type!");let f=J(e).res;if(f.length===0)return e;e=f;let t=O(O({},Ye),i);t.heads=t.heads.map(y=>y.trim()),t.tails=t.tails.map(y=>y.trim());let s=!1,o=!1,u=new P({limitToBeAddedWhitespace:!0}),l=new P({limitToBeAddedWhitespace:!0}),a=!0,c=!0,$="";function d(y,m){let g;return D(y,0,m.heads,{trimBeforeMatching:!0,cb:(p,b,w)=>(g=w,!0)})&&D(y,g,m.tails,{trimBeforeMatching:!0,cb:(p,b,w)=>(g=w,!0)})?y.slice(g):y}for(;e!==d(e,t);)e=J(d(e,t)).res;function h(y,m){let g;return!V(y,y.length-1,m.tails,{trimBeforeMatching:!0,cb:(p,b,w)=>(g=w,!0)})||!g?y:V(y,g,m.heads,{trimBeforeMatching:!0,cb:(p,b,w)=>(g=w,!0)})?y.slice(0,g+1):y}for(;e!==h(e,t);)e=J(h(e,t)).res;if(!t.heads.length||!D(e,0,t.heads,{trimBeforeMatching:!0})||!t.tails.length||!V(e,e.length-1,t.tails,{trimBeforeMatching:!0}))return J(e).res;for(let y=0,m=e.length;y<m;y++)if(e[y].trim()!==""){let g;if(D(e,y,t.heads,{trimBeforeMatching:!0,cb:(p,b,w)=>(g=w,!0)})&&g){c=!0,a&&(a=!0);let p;D(e,g,t.tails,{trimBeforeMatching:!0,cb:(b,w,v)=>(p=v,!0)})&&u.push(y,p),l.current()&&s&&$!=="tails"&&u.push(l.current()),s||l.current()&&(u.push(l.current()),l.wipe()),l.push(y,g),$="heads",y=g-1;continue}if(D(e,y,t.tails,{trimBeforeMatching:!0,cb:(p,b,w)=>(g=Number.isInteger(w)?w:e.length,!0)})&&g){c=!0,a?($==="heads"&&l.wipe(),a=!1):l.push(y,g),$="tails",y=g-1;continue}a&&(a=!0),c&&!s?(s=!0,c=!1):c&&!o?(o=!0,a=!0,c=!1,$==="heads"&&l.wipe()):c&&o&&l.wipe()}return l.current()&&u.push(l.current()),u.current()?C(e,u.current()).trim():e.trim()}var Te={fromIndex:0,throwWhenSomethingWrongIsDetected:!0,allowWholeValueToBeOnlyHeadsOrTails:!0,source:"string-find-heads-tails",matchHeadsAndTailsStrictlyInPairsByTheirOrder:!1,relaxedAPI:!1};function X(e,r,n,i){if(W(i)&&!E(i))throw new TypeError(`string-find-heads-tails: [THROW_ID_01] the fourth input argument, an Optional Options Object, must be a plain object! Currently it's equal to: ${i} (type: ${typeof i})`);let f=O(O({},Te),i);if(T(f.fromIndex)&&/^\d*$/.test(f.fromIndex))f.fromIndex=Number(f.fromIndex);else if(!Number.isInteger(f.fromIndex)||f.fromIndex<0)throw new TypeError(`${f.source} [THROW_ID_18] the fourth input argument must be a natural number or zero! Currently it's: ${f.fromIndex}`);if(!T(e)||e.length===0){if(f.relaxedAPI)return[];throw new TypeError(`string-find-heads-tails: [THROW_ID_02] the first input argument, input string, must be a non-zero-length string! Currently it's: ${typeof e}, equal to: ${e}`)}let t,s;if(!T(r)&&!Array.isArray(r)){if(f.relaxedAPI)return[];throw new TypeError(`string-find-heads-tails: [THROW_ID_03] the second input argument, heads, must be either a string or an array of strings! Currently it's: ${typeof r}, equal to: ${JSON.stringify(r,null,4)}`)}else if(T(r))if(r.length===0){if(f.relaxedAPI)return[];throw new TypeError("string-find-heads-tails: [THROW_ID_04] the second input argument, heads, must be a non-empty string! Currently it's empty.")}else r=I(r);else if(Array.isArray(r))if(r.length===0){if(f.relaxedAPI)return[];throw new TypeError("string-find-heads-tails: [THROW_ID_05] the second input argument, heads, must be a non-empty array and contain at least one string! Currently it's empty.")}else if(r.every((h,y)=>(t=h,s=y,T(h)))){if(!r.every((h,y)=>(s=y,T(h)&&h.length&&h.trim()!=="")))if(f.relaxedAPI){if(r=r.filter(h=>T(h)&&h.length),r.length===0)return[]}else throw new TypeError(`string-find-heads-tails: [THROW_ID_07] the second input argument, heads, should not contain empty strings! For example, there's one detected at index ${s} of heads array: ${JSON.stringify(r,null,4)}.`)}else if(f.relaxedAPI){if(r=r.filter(h=>T(h)&&h.length),r.length===0)return[]}else throw new TypeError(`string-find-heads-tails: [THROW_ID_06] the second input argument, heads, contains non-string elements! For example, element at ${s}th index is ${typeof t}, equal to: ${JSON.stringify(t,null,4)}. Whole heads array looks like: ${JSON.stringify(r,null,4)}`);if(!T(n)&&!Array.isArray(n)){if(f.relaxedAPI)return[];throw new TypeError(`string-find-heads-tails: [THROW_ID_08] the third input argument, tails, must be either a string or an array of strings! Currently it's: ${typeof n}, equal to: ${JSON.stringify(n,null,4)}`)}else if(T(n))if(n.length===0){if(f.relaxedAPI)return[];throw new TypeError("string-find-heads-tails: [THROW_ID_09] the third input argument, tails, must be a non-empty string! Currently it's empty.")}else n=I(n);else if(Array.isArray(n))if(n.length===0){if(f.relaxedAPI)return[];throw new TypeError("string-find-heads-tails: [THROW_ID_10] the third input argument, tails, must be a non-empty array and contain at least one string! Currently it's empty.")}else if(n.every((h,y)=>(t=h,s=y,T(h)))){if(!n.every((h,y)=>(s=y,T(h)&&h.length&&h.trim()!=="")))if(f.relaxedAPI){if(n=n.filter(h=>T(h)&&h.length),n.length===0)return[]}else throw new TypeError(`string-find-heads-tails: [THROW_ID_12] the third input argument, tails, should not contain empty strings! For example, there's one detected at index ${s}. Whole tails array is equal to: ${JSON.stringify(n,null,4)}`)}else if(f.relaxedAPI){if(n=n.filter(h=>T(h)&&h.length),n.length===0)return[]}else throw new TypeError(`string-find-heads-tails: [THROW_ID_11] the third input argument, tails, contains non-string elements! For example, element at ${s}th index is ${typeof t}, equal to: ${JSON.stringify(t,null,4)}. Whole tails array is equal to: ${JSON.stringify(n,null,4)}`);let o=f.source===Te.source;if(f.throwWhenSomethingWrongIsDetected&&!f.allowWholeValueToBeOnlyHeadsOrTails){if(I(r).includes(e))throw new Error(`${f.source}${o?": [THROW_ID_16]":""} the whole input string can't be equal to ${T(r)?"":"one of "}heads (${e})!`);if(I(n).includes(e))throw new Error(`${f.source}${o?": [THROW_ID_17]":""} the whole input string can't be equal to ${T(n)?"":"one of "}tails (${e})!`)}let u=r.concat(n).map(h=>h.charAt(0)).reduce((h,y)=>y.charCodeAt(0)>h[1]?[h[0],y.charCodeAt(0)]:y.charCodeAt(0)<h[0]?[y.charCodeAt(0),h[1]]:h,[r[0].charCodeAt(0),r[0].charCodeAt(0)]),l=[],a=!1,c={},$="",d;for(let h=f.fromIndex,y=e.length;h<y;h++){let m=e[h].charCodeAt(0);if(m<=u[1]&&m>=u[0]){let g=D(e,h,r);if(g&&f.matchHeadsAndTailsStrictlyInPairsByTheirOrder){for(let b=r.length;b--;)if(r[b]===g){d=b;break}}if(T(g))if(a){if(f.throwWhenSomethingWrongIsDetected)throw new TypeError(`${f.source}${o?": [THROW_ID_19]":""} When processing "${e}", we found heads (${e.slice(h,h+g.length)}) starting at character with index number "${h}" and there was another set of heads before it! Generally speaking, there should be "heads-tails-heads-tails", not "heads-heads-tails"! We're talking about the area of the code: --------------------------------------starts ${e.slice(Math.max(h-200,0),h)} \x1B[33m------->\x1B[39m ${`\x1B[31m${e.slice(h,h+g.length)}\x1B[39m`} \x1B[33m<-------\x1B[39m ${e.slice(h+g.length,Math.min(y,h+200))} --------------------------------------ends To turn off this error being thrown, set resolvedOpts.throwWhenSomethingWrongIsDetected to Boolean false.`)}else{c={},c.headsStartAt=h,c.headsEndAt=h+g.length,a=!0,h+=g.length-1,$&&($="");continue}let p=D(e,h,n);if(a&&p&&f.matchHeadsAndTailsStrictlyInPairsByTheirOrder&&d!==void 0&&n[d]!==void 0&&n[d]!==p){let b;for(let w=n.length;w--;)if(n[w]===p){b=w;break}throw new TypeError(`${f.source}${o?": [THROW_ID_20]":""} When processing "${e}", we had "resolvedOpts.matchHeadsAndTailsStrictlyInPairsByTheirOrder" on. We found heads (${r[d]}) but the tails the followed it were not of the same index, ${d} (${n[d]}) but ${b} (${p}).`)}if(T(p))if(a){c.tailsStartAt=h,c.tailsEndAt=h+p.length,l.push(c),c={},a=!1,h+=p.length-1;continue}else f.throwWhenSomethingWrongIsDetected&&($=`${f.source}${o?": [THROW_ID_21]":""} When processing "${e}", we found tails (${e.slice(h,h+p.length)}) starting at character with index number "${h}" but there were no heads preceding it. That's very naughty!`)}if(f.throwWhenSomethingWrongIsDetected&&h===y-1){if(Object.keys(c).length!==0)throw new TypeError(`${f.source}${o?": [THROW_ID_22]":""} When processing "${e}", we reached the end of the string and yet didn't find any tails (${JSON.stringify(n,null,4)}) to match the last detected heads (${e.slice(c.headsStartAt,c.headsEndAt)})!`);if($)throw new Error($)}}return l}var Oe=k(F(),1);function ee(e){if(e.includes(".")){let r=e.lastIndexOf(".");if(!e.slice(0,r).includes("."))return e.slice(0,r);for(let n=r-1;n--;)if(e[n]===".")return e.slice(n+1,r)}return null}var re=(0,Oe.default)();function U(e,r){let n={now:!1};function i(f,t,s,o){let u=re(f),l,a=O({depth:-1,path:""},s);if(a.depth+=1,Array.isArray(u))for(let c=0,$=u.length;c<$&&!o.now;c++){let d=a.path?`${a.path}.${c}`:`${c}`;u[c]!==void 0?(a.parent=re(u),a.parentType="array",a.parentKey=ee(d),l=i(t(u[c],void 0,M(O({},a),{path:d}),o),t,M(O({},a),{path:d}),o),Number.isNaN(l)&&c<u.length?(u.splice(c,1),c-=1):u[c]=l):u.splice(c,1)}else if(E(u))for(let c in u){if(o.now&&c!=null)break;let $=a.path?`${a.path}.${c}`:c;a.depth===0&&c!=null&&(a.topmostKey=c),a.parent=re(u),a.parentType="object",a.parentKey=ee($),l=i(t(c,u[c],M(O({},a),{path:$}),o),t,M(O({},a),{path:$}),o),Number.isNaN(l)?delete u[c]:u[c]=l}return u}return i(e,r,{},n)}function te(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}var ne=new Map,Ae=(e,r)=>{if(!Array.isArray(e))switch(typeof e){case"string":e=[e];break;case"undefined":e=[];break;default:throw new TypeError(`Expected '${r}' to be a string or an array, but got a type of '${typeof e}'`)}return e.filter(n=>{if(typeof n!="string"){if(typeof n>"u")return!1;throw new TypeError(`Expected '${r}' to be an array of strings, but found a type of '${typeof n}' in the array`)}return!0})},Xe=(e,r)=>{r=O({caseSensitive:!1},r);let n=e+JSON.stringify(r);if(ne.has(n))return ne.get(n);let i=e[0]==="!";i&&(e=e.slice(1)),e=te(e).replace(/\\\*/g,"[\\s\\S]*");let f=new RegExp(`^${e}$`,r.caseSensitive?"":"i");return f.negated=i,ne.set(n,f),f},er=(e,r,n,i)=>{if(e=Ae(e,"inputs"),r=Ae(r,"patterns"),r.length===0)return[];r=r.map(s=>Xe(s,n));let{allPatterns:f}=n||{},t=[];for(let s of e){let o,u=[...r].fill(!1);for(let[l,a]of r.entries())if(a.test(s)&&(u[l]=!0,o=!a.negated,!o))break;if(!(o===!1||o===void 0&&r.some(l=>!l.negated)||f&&u.some((l,a)=>!l&&!r[a].negated))&&(t.push(s),i))break}return t};function K(e,r,n){return er(e,r,n,!0).length>0}var Ee=k(F(),1);var ve=(0,Ee.default)();function ie(e,r,n){let i;n!==void 0&&(i=Array.isArray(n)?ve(n):[ve(n)]);let f=[],t=U(e,(s,o,u)=>{let l=o!==void 0?o:s;if(o!==void 0&&K(s,r,{caseSensitive:!0})){if(i===void 0)f.push({val:o,path:u.path});else if(i.length)return i.shift()}return l});return i===void 0?f:t}var N=k(We(),1);var Se="12.0.23";var tr=Se,nr=Object.prototype.hasOwnProperty,_e={heads:"%%_",tails:"_%%",headsNoWrap:"%%-",tailsNoWrap:"-%%",lookForDataContainers:!0,dataContainerIdentifierTails:"_data",wrapHeadsWith:"",wrapTailsWith:"",dontWrapVars:[],preventDoubleWrapping:!0,wrapGlobalFlipSwitch:!0,noSingleMarkers:!1,resolveToBoolIfAnyValuesContainBool:!0,resolveToFalseIfAnyValuesContainBool:!0,throwWhenNonStringInsertedInString:!1,allowUnresolved:!1};function A(e){return T(e)?e.trim():e}function ir(e){if(T(e)&&e.length&&e.indexOf(".")!==-1){for(let r=0,n=e.length;r<n;r++)if(e[r]===".")return e.slice(0,r)}return e}function sr(e){if(T(e)&&e.length&&e.indexOf(".")!==-1){for(let r=0,n=e.length;r<n;r++)if(e[r]===".")return e.slice(r+1)}return e}function xe(e){if(T(e)&&e.length&&e.indexOf(".")!==-1){for(let r=e.length;r--;)if(e[r]===".")return e.slice(0,r)}return e}function De(e){if(T(e)&&e.length&&e.indexOf(".")!==-1){for(let r=e.length;r--;)if(e[r]===".")return e.slice(r+1)}return e}function se(e,r){return!T(e)||!e.trim()?!1:!!(e.includes(r.heads)||e.includes(r.tails)||T(r.headsNoWrap)&&r.headsNoWrap.length&&e.includes(r.headsNoWrap)||T(r.tailsNoWrap)&&r.tailsNoWrap.length&&e.includes(r.tailsNoWrap))}function ar(e,r,n){let i,f;return T(e)&&e.length&&D(e,0,r,{trimBeforeMatching:!0,cb:(t,s,o)=>(i=o,!0)})&&V(e,e.length-1,n,{trimBeforeMatching:!0,cb:(t,s,o)=>(f=(o||0)+1,!0)})?e.slice(i,f):e}function Ne(e,r,n=!1,i,f,t){if(r.wrapHeadsWith||(r.wrapHeadsWith=""),r.wrapTailsWith||(r.wrapTailsWith=""),T(e)&&!n&&r.wrapGlobalFlipSwitch&&!r.dontWrapVars.some(s=>K(t,s))&&(!r.preventDoubleWrapping||r.preventDoubleWrapping&&T(e)&&!e.includes(r.wrapHeadsWith)&&!e.includes(r.wrapTailsWith)))return`${r.wrapHeadsWith}${e}${r.wrapTailsWith}`;if(n){if(!T(e))return e;let s=$e(e,{heads:r.wrapHeadsWith,tails:r.wrapTailsWith});return T(s)?ar(s,r.wrapHeadsWith,r.wrapTailsWith):s}return e}function or(e,r,n,i){let f;if(n.indexOf(".")!==-1){let t=n,s=!0;if(i.lookForDataContainers&&T(i.dataContainerIdentifierTails)&&i.dataContainerIdentifierTails.length&&!t.endsWith(i.dataContainerIdentifierTails)){let o=N.default.get(e,t+i.dataContainerIdentifierTails);E(o)&&N.default.get(o,r)&&(f=N.default.get(o,r),s=!1)}for(;s&&t.indexOf(".")!==-1;){if(t=xe(t),De(t)===r)throw new Error(`json-variables/findValues(): [THROW_ID_20] While trying to resolve: "${r}" at path "${n}", we encountered a closed loop. The parent key "${De(t)}" is called the same as the variable "${r}" we're looking for.`);if(i.lookForDataContainers&&T(i.dataContainerIdentifierTails)&&i.dataContainerIdentifierTails.length&&!t.endsWith(i.dataContainerIdentifierTails)){let o=N.default.get(e,t+i.dataContainerIdentifierTails);E(o)&&N.default.get(o,r)&&(f=N.default.get(o,r),s=!1)}if(f===void 0){let o=N.default.get(e,t);E(o)&&N.default.get(o,r)&&(f=N.default.get(o,r),s=!1)}}}if(f===void 0){let t=N.default.get(e,r);t!==void 0&&(f=t)}if(f===void 0)if(r.indexOf(".")===-1){let t=ie(e,r);if(t.length){for(let s=0,o=t.length;s<o;s++)if(T(t[s].val)||L(t[s].val)||B(t[s].val)){f=t[s].val;break}else if(ge(t[s].val)){f=String(t[s].val);break}else if(Array.isArray(t[s].val)){f=t[s].val.join("");break}}}else{let t=ie(e,ir(r));if(t.length)for(let s=0,o=t.length;s<o;s++){let u=N.default.get(t[s].val,sr(r));u&&T(u)&&(f=u)}}return f}function Re(e,r,n,i,f=[]){if(f.includes(n)){let d="";if(f.length>1){let h=` \u2192 `;d=f.reduce((y,m,g)=>y+(g===0?"":h)+(m===n?"\u{1F4A5} ":" ")+m,` Here's the path we travelled up until we hit the recursion: `),d+=`${h}\u{1F4A5} ${n}`}throw new Error(`json-variables/resolveString(): [THROW_ID_19] While trying to resolve: "${r}" at path "${n}", we encountered a closed loop, the key is referencing itself."${d}`)}let t={},s=Array.from(f);s.push(n);let o=new P;function u(d,h,y){for(let m=0,g=d.length;m<g;m++){let p=d[m],b=r.slice(p.headsEndAt,p.tailsStartAt);if(b.length===0)o.push(p.headsStartAt,p.tailsEndAt);else if(nr.call(t,b)&&T(t[b]))o.push(p.headsStartAt,p.tailsEndAt,t[b]);else{let w=or(e,b.trim(),n,i);if(w===void 0)if(i.allowUnresolved===!0)w="";else if(T(i.allowUnresolved))w=i.allowUnresolved;else throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_18] We couldn't find the value to resolve the variable ${r.slice(p.headsEndAt,p.tailsStartAt)}. We're at path: "${n}".`);if(!y&&i.throwWhenNonStringInsertedInString&&!T(w))throw new Error(`json-variables/processHeadsAndTails(): [THROW_ID_23] While resolving the variable ${r.slice(p.headsEndAt,p.tailsStartAt)} at path ${n}, it resolved into a non-string value, ${JSON.stringify(w,null,4)}. This is happening because options setting "throwWhenNonStringInsertedInString" is active (set to "true").`);if(L(w)){if(i.resolveToBoolIfAnyValuesContainBool)return o.wipe(),i.resolveToFalseIfAnyValuesContainBool?!1:w;w=""}else{if(B(w)&&y)return o.wipe(),w;Array.isArray(w)?w=String(w.join("")):B(w)?w="":w=String(w)}let v=n.includes(".")?`${xe(n)}.${b}`:b;if(se(w,i)){let S=Ne(Re(e,w,v,i,s),i,h,s,v,b.trim());T(S)&&o.push(p.headsStartAt,p.tailsEndAt,S)}else{t[b]=w;let S=Ne(w,i,h,s,v,b.trim());T(S)&&o.push(p.headsStartAt,p.tailsEndAt,S)}}}}let l;try{l=X(r,i.heads,i.tails,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(d){throw new Error(`json-variables/resolveString(): [THROW_ID_17] While trying to resolve string: "${r}" at path ${n}, something wrong with heads and tails was detected! Here's the internal error message: ${d}`)}let a=!1;l.length===1&&C(r,[[l[0].headsStartAt,l[0].tailsEndAt]]).trim()===""&&(a=!0);let c=u(l,!1,a);if(typeof c=="boolean"||c===null)return c;try{l=X(r,i.headsNoWrap,i.tailsNoWrap,{source:"",throwWhenSomethingWrongIsDetected:!1})}catch(d){throw new Error(`json-variables/resolveString(): [THROW_ID_22] While trying to resolve string: "${r}" at path ${n}, something wrong with no-wrap heads and no-wrap tails was detected! Here's the internal error message: ${d}`)}l.length===1&&C(r,[[l[0].headsStartAt,l[0].tailsEndAt]]).trim()===""&&(a=!0);let $=u(l,!0,a);return L($)||B($)?$:o!=null&&o.current()?C(r,o.current()):r}function lr(e,r){if(!arguments.length)throw new Error("json-variables/jVar(): [THROW_ID_01] Alas! Inputs are missing!");if(!E(e))throw new TypeError(`json-variables/jVar(): [THROW_ID_02] Alas! The input must be a plain object! Currently it's: ${Array.isArray(e)?"array":typeof e}`);if(r&&!E(r))throw new TypeError(`json-variables/jVar(): [THROW_ID_03] Alas! An Optional Options Object must be a plain object! Currently it's: ${Array.isArray(r)?"array":typeof r}`);let n=O(O({},_e),r);n.dontWrapVars?Array.isArray(n.dontWrapVars)||(n.dontWrapVars=I(n.dontWrapVars)):n.dontWrapVars=[];let i,f;if(n.dontWrapVars.length&&!n.dontWrapVars.every((s,o)=>T(s)?!0:(i=s,f=o,!1)))throw new Error(`json-variables/jVar(): [THROW_ID_05] Alas! All variable names set in resolvedOpts.dontWrapVars should be of a string type. Computer detected a value "${i}" at index ${f}, which is not string but ${Array.isArray(i)?"array":typeof i}!`);if(n.heads==="")throw new Error("json-variables/jVar(): [THROW_ID_06] Alas! resolvedOpts.heads are empty!");if(n.tails==="")throw new Error("json-variables/jVar(): [THROW_ID_07] Alas! resolvedOpts.tails are empty!");if(n.lookForDataContainers&&n.dataContainerIdentifierTails==="")throw new Error("json-variables/jVar(): [THROW_ID_08] Alas! resolvedOpts.dataContainerIdentifierTails is empty!");if(n.heads===n.tails)throw new Error("json-variables/jVar(): [THROW_ID_09] Alas! resolvedOpts.heads and resolvedOpts.tails can't be equal!");if(n.heads===n.headsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_10] Alas! resolvedOpts.heads and resolvedOpts.headsNoWrap can't be equal!");if(n.tails===n.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_11] Alas! resolvedOpts.tails and resolvedOpts.tailsNoWrap can't be equal!");if(n.headsNoWrap==="")throw new Error("json-variables/jVar(): [THROW_ID_12] Alas! resolvedOpts.headsNoWrap is an empty string!");if(n.tailsNoWrap==="")throw new Error("json-variables/jVar(): [THROW_ID_13] Alas! resolvedOpts.tailsNoWrap is an empty string!");if(n.headsNoWrap===n.tailsNoWrap)throw new Error("json-variables/jVar(): [THROW_ID_14] Alas! resolvedOpts.headsNoWrap and resolvedOpts.tailsNoWrap can't be equal!");let t;return U(e,(s,o,u)=>{if(W(o)&&se(s,n))throw new Error(`json-variables/jVar(): [THROW_ID_15] Alas! Object keys can't contain variables! Please check the following key: ${s}`);if(o!==void 0?t=o:t=s,t==="")return t;if(n.heads.length&&A(t)===A(n.heads)||n.tails.length&&A(t)===A(n.tails)||n.headsNoWrap.length&&A(t)===A(n.headsNoWrap)||n.tailsNoWrap.length&&A(t)===A(n.tailsNoWrap)){if(!n.noSingleMarkers)return t;throw new Error(`json-variables/jVar(): [THROW_ID_16] Alas! While processing the input, we stumbled upon ${A(t)} which is equal to ${A(t)===A(n.heads)?"heads":""}${A(t)===A(n.tails)?"tails":""}${T(n.headsNoWrap)&&A(t)===A(n.headsNoWrap)?"headsNoWrap":""}${T(n.tailsNoWrap)&&A(t)===A(n.tailsNoWrap)?"tailsNoWrap":""}. If you wouldn't have set resolvedOpts.noSingleMarkers to "true" this error would not happen and computer would have left the current element (${A(t)}) alone`)}return T(t)&&se(t,n)?Re(e,t,u.path,n):t})}return ke(ur);})(); /** * @name arrayiffy-if-string * @fileoverview Put non-empty strings into arrays, turn empty-ones into empty arrays. Bypass everything else. * @version 5.0.10 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/arrayiffy-if-string/} */ /** * @name codsen-utils * @fileoverview Various utility functions * @version 1.6.8 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/codsen-utils/} */ /** * @name string-match-left-right * @fileoverview Match substrings on the left or right of a given index, ignoring whitespace * @version 9.0.23 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/string-match-left-right/} */ /** * @name string-collapse-leading-whitespace * @fileoverview Collapse the leading and trailing whitespace of a string * @version 7.0.9 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/string-collapse-leading-whitespace/} */ /** * @name ranges-sort * @fileoverview Sort string index ranges * @version 6.0.14 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/ranges-sort/} */ /** * @name ranges-push * @fileoverview Gather string index ranges * @version 7.0.19 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/ranges-push/} */ /** * @name ranges-merge * @fileoverview Merge and sort string index ranges * @version 9.0.19 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/ranges-merge/} */ /** * @name ranges-apply * @fileoverview Take an array of string index ranges, delete/replace the string according to them * @version 7.0.20 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/ranges-apply/} */ /** * @name string-trim-spaces-only * @fileoverview Like String.trim() but you can choose granularly what to trim * @version 5.0.13 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/string-trim-spaces-only/} */ /** * @name string-remove-duplicate-heads-tails * @fileoverview Detect and (recursively) remove head and tail wrappings around the input string * @version 7.0.23 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/string-remove-duplicate-heads-tails/} */ /** * @name string-find-heads-tails * @fileoverview Finds where are arbitrary templating marker heads and tails located * @version 6.0.23 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/string-find-heads-tails/} */ /** * @name ast-monkey-util * @fileoverview Utility library of AST helper functions * @version 3.0.10 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/ast-monkey-util/} */ /** * @name ast-monkey-traverse * @fileoverview Utility library to traverse AST * @version 4.0.20 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/ast-monkey-traverse/} */ /** * @name ast-get-values-by-key * @fileoverview Extract values and paths from AST by keys OR set them by keys * @version 5.0.22 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/ast-get-values-by-key/} */