UNPKG

string-remove-duplicate-heads-tails

Version:

Detect and (recursively) remove head and tail wrappings around the input string

83 lines (81 loc) 27.2 kB
/** * @name string-remove-duplicate-heads-tails * @fileoverview Detect and (recursively) remove head and tail wrappings around the input string * @version 7.1.0 * @author Roy Revelt * @license MIT * {@link https://codsen.com/os/string-remove-duplicate-heads-tails/} */ "use strict";var stringRemoveDuplicateHeadsTails=(()=>{var ie=Object.create;var _=Object.defineProperty;var oe=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames,W=Object.getOwnPropertySymbols,le=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty,ue=Object.prototype.propertyIsEnumerable;var V=(e,t,i)=>t in e?_(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,$=(e,t)=>{for(var i in t||(t={}))L.call(t,i)&&V(e,i,t[i]);if(W)for(var i of W(t))ue.call(t,i)&&V(e,i,t[i]);return e};var ce=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),fe=(e,t)=>{for(var i in t)_(e,i,{get:t[i],enumerable:!0})},q=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let c of ae(t))!L.call(e,c)&&c!==i&&_(e,c,{get:()=>t[c],enumerable:!(n=oe(t,c))||n.enumerable});return e};var ge=(e,t,i)=>(i=e!=null?ie(le(e)):{},q(t||!e||!e.__esModule?_(i,"default",{value:e,enumerable:!0}):i,e)),he=e=>q(_({},"__esModule",{value:!0}),e);var B=(e,t,i)=>V(e,typeof t!="symbol"?t+"":t,i);var U=ce((Ie,P)=>{"use strict";P.exports=me;function v(e){return e instanceof Buffer?Buffer.from(e):new e.constructor(e.buffer.slice(),e.byteOffset,e.length)}function me(e){if(e=e||{},e.circles)return pe(e);let t=new Map;if(t.set(Date,o=>new Date(o)),t.set(Map,(o,u)=>new Map(n(Array.from(o),u))),t.set(Set,(o,u)=>new Set(n(Array.from(o),u))),e.constructorHandlers)for(let o of e.constructorHandlers)t.set(o[0],o[1]);let i=null;return e.proto?r:c;function n(o,u){let a=Object.keys(o),s=new Array(a.length);for(let l=0;l<a.length;l++){let f=a[l],p=o[f];typeof p!="object"||p===null?s[f]=p:p.constructor!==Object&&(i=t.get(p.constructor))?s[f]=i(p,u):ArrayBuffer.isView(p)?s[f]=v(p):s[f]=u(p)}return s}function c(o){if(typeof o!="object"||o===null)return o;if(Array.isArray(o))return n(o,c);if(o.constructor!==Object&&(i=t.get(o.constructor)))return i(o,c);let u={};for(let a in o){if(Object.hasOwnProperty.call(o,a)===!1)continue;let s=o[a];typeof s!="object"||s===null?u[a]=s:s.constructor!==Object&&(i=t.get(s.constructor))?u[a]=i(s,c):ArrayBuffer.isView(s)?u[a]=v(s):u[a]=c(s)}return u}function r(o){if(typeof o!="object"||o===null)return o;if(Array.isArray(o))return n(o,r);if(o.constructor!==Object&&(i=t.get(o.constructor)))return i(o,r);let u={};for(let a in o){let s=o[a];typeof s!="object"||s===null?u[a]=s:s.constructor!==Object&&(i=t.get(s.constructor))?u[a]=i(s,r):ArrayBuffer.isView(s)?u[a]=v(s):u[a]=r(s)}return u}}function pe(e){let t=[],i=[],n=new Map;if(n.set(Date,a=>new Date(a)),n.set(Map,(a,s)=>new Map(r(Array.from(a),s))),n.set(Set,(a,s)=>new Set(r(Array.from(a),s))),e.constructorHandlers)for(let a of e.constructorHandlers)n.set(a[0],a[1]);let c=null;return e.proto?u:o;function r(a,s){let l=Object.keys(a),f=new Array(l.length);for(let p=0;p<l.length;p++){let h=l[p],g=a[h];if(typeof g!="object"||g===null)f[h]=g;else if(g.constructor!==Object&&(c=n.get(g.constructor)))f[h]=c(g,s);else if(ArrayBuffer.isView(g))f[h]=v(g);else{let m=t.indexOf(g);m!==-1?f[h]=i[m]:f[h]=s(g)}}return f}function o(a){if(typeof a!="object"||a===null)return a;if(Array.isArray(a))return r(a,o);if(a.constructor!==Object&&(c=n.get(a.constructor)))return c(a,o);let s={};t.push(a),i.push(s);for(let l in a){if(Object.hasOwnProperty.call(a,l)===!1)continue;let f=a[l];if(typeof f!="object"||f===null)s[l]=f;else if(f.constructor!==Object&&(c=n.get(f.constructor)))s[l]=c(f,o);else if(ArrayBuffer.isView(f))s[l]=v(f);else{let p=t.indexOf(f);p!==-1?s[l]=i[p]:s[l]=o(f)}}return t.pop(),i.pop(),s}function u(a){if(typeof a!="object"||a===null)return a;if(Array.isArray(a))return r(a,u);if(a.constructor!==Object&&(c=n.get(a.constructor)))return c(a,u);let s={};t.push(a),i.push(s);for(let l in a){let f=a[l];if(typeof f!="object"||f===null)s[l]=f;else if(f.constructor!==Object&&(c=n.get(f.constructor)))s[l]=c(f,u);else if(ArrayBuffer.isView(f))s[l]=v(f);else{let p=t.indexOf(f);p!==-1?s[l]=i[p]:s[l]=u(f)}}return t.pop(),i.pop(),s}}});var Me={};fe(Me,{defaults:()=>se,remDup:()=>De,version:()=>Ee});var Q=ge(U(),1);var Se=(0,Q.default)();function R(e){if(e==null||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t!==null&&t!==Object.prototype&&Object.getPrototypeOf(t)!==null?!1:!(Symbol.iterator in e)&&!(Symbol.toStringTag in e)}function E(e){return typeof e=="string"}function G(e){return Number.isFinite(e)}function N(e){return Number.isSafeInteger(e)&&e>=0}function D(e){return e!=null}function z(e,t){return R(e)&&E(t)&&t in e}function I(e){return typeof e!="string"?e:e.length?[e]:[]}var K={cb:void 0,i:!1,trimBeforeMatching:!1,trimCharsBeforeMatching:[],maxMismatches:0,firstMustMatch:!1,lastMustMatch:!1,hungry:!1},ye=e=>e+1;function de(e,t,i,n,c=!1,r=ye){var w;let o=typeof i=="function"?i():i;if(+t<0&&c&&o==="EOL")return o;let u=$($({},K),n);if(t>=e.length&&!c)return!1;let a=c?1:i.length,s=0,l=!1,f=!1,p=!1,h=u.maxMismatches,g=t,m=!1,T=!1,y=!1;function O(){return s===1&&h<u.maxMismatches-1}for(;e[g];){let d=r(g);if(u.trimBeforeMatching&&e[g].trim()===""){if(!e[d]&&c&&i==="EOL")return!0;g=r(g);continue}if(u&&!u.i&&((w=u==null?void 0:u.trimCharsBeforeMatching)!=null&&w.includes(e[g]))||u!=null&&u.i&&u.trimCharsBeforeMatching&&u.trimCharsBeforeMatching.map(b=>b.toLowerCase()).includes(e[g].toLowerCase())){if(c&&i==="EOL"&&!e[d])return!0;g=r(g);continue}let A=d>g?i[i.length-a]:i[a-1];if(!u.i&&e[g]===A||u.i&&e[g].toLowerCase()===A.toLowerCase()){if(m||(m=!0),p||(p=!0),a===i.length){if(T=!0,h!==u.maxMismatches)return!1}else a===1&&(y=!0);if(a-=1,s++,O())return!1;if(!a)return s!==i.length||h===u.maxMismatches||!l?g:!1}else if(!l&&!s&&(l=!0),u.maxMismatches&&h&&g){h-=1;for(let b=0;b<=h;b++){let M=d>g?i[i.length-a+1+b]:i[a-2-b],C=e[r(g)];if(M&&(!u.i&&e[g]===M||u.i&&e[g].toLowerCase()===M.toLowerCase())&&(!u.firstMustMatch||a!==i.length)){if(s++,O())return!1;a-=2,m=!0;break}else if(C&&M&&(!u.i&&C===M||u.i&&C.toLowerCase()===M.toLowerCase())&&(!u.firstMustMatch||a!==i.length)){if(!s&&!u.hungry)return!1;a-=1,m=!0;break}else if(M===void 0&&h>=0&&m&&(!u.firstMustMatch||T)&&(!u.lastMustMatch||y))return g}m||(f=g)}else return g===0&&a===1&&!u.lastMustMatch&&p?0:!1;if(f!==!1&&f!==g&&(f=!1),a<1)return g;g=r(g)}if(a>0)return c&&o==="EOL"?!0:u&&u.maxMismatches>=a&&p?f||0:!1}function Z(e,t,i,n,c){var l,f,p;if(R(c)&&z(c,"trimBeforeMatching")&&c&&typeof c.trimBeforeMatching!="boolean")throw new Error("string-match-left-right/".concat(e,"(): [THROW_ID_09] opts.trimBeforeMatching should be boolean!").concat(Array.isArray(c.trimBeforeMatching)?" Did you mean to use opts.trimCharsBeforeMatching?":""));let r=$($({},K),c);if(typeof r.trimCharsBeforeMatching=="string"&&(r.trimCharsBeforeMatching=I(r.trimCharsBeforeMatching)),r.trimCharsBeforeMatching=r.trimCharsBeforeMatching.map(h=>E(h)?h:String(h)),!E(t)||!t.length)return!1;if(!Number.isInteger(i)||i<0)throw new Error("string-match-left-right/".concat(e,"(): [THROW_ID_03] the second argument should be a natural number. Currently it's of a type: ").concat(typeof i,", equal to:\n").concat(JSON.stringify(i,null,4)));let o,u;if(E(n))o=[n];else if(Array.isArray(n))o=n;else if(!n)o=n;else if(typeof n=="function")o=[],o.push(n);else throw new Error("string-match-left-right/".concat(e,"(): [THROW_ID_05] the third argument, whatToMatch, is neither string nor array of strings! It's ").concat(typeof n,", equal to:\n").concat(JSON.stringify(n,null,4)));if(c&&!R(c))throw new Error("string-match-left-right/".concat(e,"(): [THROW_ID_06] the fourth argument, options object, should be a plain object. Currently it's of a type \"").concat(typeof c,'", and equal to:\n').concat(JSON.stringify(c,null,4)));let a=0,s="";if((l=r==null?void 0:r.trimCharsBeforeMatching)!=null&&l.some((h,g)=>h.length>1?(a=g,s=h,!0):!1))throw new Error("string-match-left-right/".concat(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 ").concat(a," is longer than 1 character, ").concat(s.length," (equals to ").concat(s,"). Please split it into separate characters and put into array as separate elements."));if(!o||!Array.isArray(o)||Array.isArray(o)&&!o.length||Array.isArray(o)&&o.length===1&&E(o[0])&&!o[0].trim()){if(typeof r.cb=="function"){let g,m=i;if((e==="matchLeftIncl"||e==="matchRight")&&(m+=1),e[5]==="L")for(let w=m;w--;){let d=t[w];if((!r.trimBeforeMatching||r.trimBeforeMatching&&(d!=null&&d.trim()))&&(!((f=r.trimCharsBeforeMatching)!=null&&f.length)||d!==void 0&&!r.trimCharsBeforeMatching.includes(d))){g=w;break}}else if(e.startsWith("matchRight"))for(let w=m;w<t.length;w++){let d=t[w];if((!r.trimBeforeMatching||r.trimBeforeMatching&&d.trim())&&(!((p=r.trimCharsBeforeMatching)!=null&&p.length)||!r.trimCharsBeforeMatching.includes(d))){g=w;break}}if(g===void 0)return!1;let T=t[g],y=g+1,O="";return y&&y>0&&(O=t.slice(0,y)),e[5]==="L"||g&&g>0&&(O=t.slice(g)),r.cb(T,O,g)}let h="";throw c||(h=" More so, the whole options object, the fourth input argument, is missing!"),new Error("string-match-left-right/".concat(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!').concat(h))}for(let h=0,g=o.length;h<g;h++){u=typeof o[h]=="function";let m=o[h],T,y,O="",w=i;e==="matchRight"?w+=1:e==="matchLeft"&&(w-=1);let d=de(t,w,m,r,u,A=>e[5]==="L"?A-1:A+1);if(d&&u&&typeof m=="function"&&m()==="EOL")return m()&&(!r.cb||r.cb(T,O,y))?m():!1;if(Number.isInteger(d)&&(y=e.startsWith("matchLeft")?d-1:d+1,e[5]==="L"?O=t.slice(0,d):O=t.slice(y)),y<0&&(y=void 0),t[y]&&(T=t[y]),Number.isInteger(d)&&(!r.cb||r.cb(T,O,y)))return m}return!1}function x(e,t,i,n){return Z("matchLeftIncl",e,t,i,n)}function S(e,t,i,n){return Z("matchRightIncl",e,t,i,n)}function j(e,t=1){let i="\xA0";function n(r){return Array.from(r).reverse().join("")}function c(r,o,u){let a=u?"\n":"\r",s=u?"\r":"\n";if(!r)return r;let l=0,f=0,p="";for(let h=0,g=r.length;h<g;h++)(r[h]===a||r[h]===s&&r[h-1]!==a)&&f++,"\r\n".includes(r[h])||r[h]===i?(l=0,r[h]===i?p+=r[h]:r[h]===a?f<=o&&(p+=r[h],r[h+1]===s&&(p+=r[h+1],h++)):r[h]===s&&(r==null?void 0:r[h-1])!==a&&f<=o&&(p+=r[h])):(l++,!r[h+1]&&!f&&(p+=" "));return p}if(typeof e=="string"&&e.length){let r=1;typeof+t=="number"&&Number.isInteger(+t)&&+t>=0&&(r=+t);let o="",u="";if(!e.trim())o=e;else if(!e[0].trim()){for(let a=0,s=e.length;a<s;a++)if(e[a].trim()){o=e.slice(0,a);break}}if(e.trim()&&(e.slice(-1).trim()===""||e.slice(-1)===i)){for(let a=e.length;a--;)if(e[a].trim()){u=e.slice(a+1);break}}return"".concat(c(o,r,!1)).concat(e.trim()).concat(n(c(n(u),r,!0)))}return e}var $e={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function k(e,t){if(!Array.isArray(e)||!e.length)return e;let i=$($({},$e),t),n,c;if(i.strictlyTwoElementsInRangeArrays&&!e.every((u,a)=>!Array.isArray(u)||u.length!==2?(n=a,c=u.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, ".concat(n,"th range (").concat(JSON.stringify(e[n],null,4),") has not two but ").concat(c," elements!"));if(!e.every((u,a)=>!Array.isArray(u)||!Number.isInteger(u[0])||u[0]<0||!Number.isInteger(u[1])||u[1]<0?(n=a,!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, ".concat(n,"th range (").concat(JSON.stringify(e[n],null,4),") does not consist of only natural numbers!"));let r=e.length**2,o=0;return Array.from(e).sort((u,a)=>(i.progressFn&&(o+=1,i.progressFn(Math.floor(o*100/r))),u[0]===a[0]?u[1]<a[1]?-1:u[1]>a[1]?1:0:u[0]<a[0]?-1:1))}var X={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function be(e,t){var s;function i(l){return!!l&&typeof l=="object"&&!Array.isArray(l)}if(!Array.isArray(e)||!e.length)return null;let n;if(t)if(i(t)){if(n=$($({},X),t),n.progressFn&&i(n.progressFn)&&!Object.keys(n.progressFn).length)n.progressFn=null;else if(n.progressFn&&typeof n.progressFn!="function")throw new Error('ranges-merge: [THROW_ID_01] resolvedOpts.progressFn must be a function! It was given of a type: "'.concat(typeof n.progressFn,'", equal to ').concat(JSON.stringify(n.progressFn,null,4)));if(![1,2,"1","2"].includes(n.mergeType))throw new Error('ranges-merge: [THROW_ID_02] resolvedOpts.mergeType was customised to a wrong thing! It was given of a type: "'.concat(typeof n.mergeType,'", equal to ').concat(JSON.stringify(n.mergeType,null,4)));if(typeof n.joinRangesThatTouchEdges!="boolean")throw new Error('ranges-merge: [THROW_ID_04] resolvedOpts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "'.concat(typeof n.joinRangesThatTouchEdges,'", equal to ').concat(JSON.stringify(n.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:\n".concat(JSON.stringify(t,null,4)," (type ").concat(typeof t,")"));else n=$({},X);let c=e.filter(l=>Array.isArray(l)).map(l=>[...l]).filter(l=>l[2]!==void 0||l[0]!==l[1]),r,o,u;n.progressFn?r=k(c,{progressFn:l=>{u=Math.floor(l/5),u!==o&&(o=u,n.progressFn!=null&&n.progressFn(u))}}):r=k(c);let a=r.length-1;for(let l=a;l>0;l--)n.progressFn&&(u=Math.floor((1-l/a)*78)+21,u!==o&&u>o&&(o=u,n.progressFn(u))),(r[l][0]<=r[l-1][0]||!n.joinRangesThatTouchEdges&&r[l][0]<r[l-1][1]||n.joinRangesThatTouchEdges&&r[l][0]<=r[l-1][1])&&(r[l-1][0]=Math.min(r[l][0],r[l-1][0]),r[l-1][1]=Math.max(r[l][1],r[l-1][1]),r[l][2]!==void 0&&(r[l-1][0]>=r[l][0]||r[l-1][1]<=r[l][1])&&r[l-1][2]!==null&&(r[l][2]===null&&r[l-1][2]!==null?r[l-1][2]=null:r[l-1][2]!=null?+((s=n||{})==null?void 0:s.mergeType)==2&&r[l-1][0]===r[l][0]?r[l-1][2]=r[l][2]:r[l-1][2]+=r[l][2]:r[l-1][2]=r[l][2]),r.splice(l,1),l=r.length);return r.length?r:null}var Te={limitToBeAddedWhitespace:!1,limitLinebreaksCount:1,mergeType:1},J=class{constructor(e){B(this,"ranges");B(this,"opts");let t=$($({},Te),e);if(t.mergeType&&t.mergeType!==1&&t.mergeType!==2)if(E(t.mergeType)&&t.mergeType.trim()==="1")t.mergeType=1;else if(E(t.mergeType)&&t.mergeType.trim()==="2")t.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: "'.concat(typeof t.mergeType,'", equal to ').concat(JSON.stringify(t.mergeType,null,4)));this.opts=t,this.ranges=[]}add(e,t,i){var r;if(e==null&&t==null)return;if(D(e)&&!D(t)){if(Array.isArray(e)){if(e.length){if(e.some(o=>Array.isArray(o))){e.forEach(o=>{Array.isArray(o)&&this.add(...o)});return}e.length&&N(+e[0])&&N(+e[1])&&this.add(...e)}return}throw new TypeError('ranges-push/Ranges/add(): [THROW_ID_12] the first input argument, "from" is set ('.concat(JSON.stringify(e,null,0),') but second-one, "to" is not (').concat(JSON.stringify(t,null,0),")"))}else if(!D(e)&&D(t))throw new TypeError('ranges-push/Ranges/add(): [THROW_ID_13] the second input argument, "to" is set ('.concat(JSON.stringify(t,null,0),') but first-one, "from" is not (').concat(JSON.stringify(e,null,0),")"));let n=+e,c=+t;if(N(n)&&N(c)){if(D(i)&&!E(i)&&!G(i))throw new TypeError("ranges-push/Ranges/add(): [THROW_ID_08] The third argument, the value to add, was given not as string but ".concat(typeof i,", equal to:\n").concat(JSON.stringify(i,null,4)));if(D(this.ranges)&&Array.isArray(this.last())&&n===this.last()[1]){if(this.last()[1]=c,this.last()[2],this.last()[2]!==null&&D(i)){let o=this.last()[2]&&this.last()[2].length&&(!((r=this.opts)!=null&&r.mergeType)||this.opts.mergeType===1)?"".concat(this.last()[2]).concat(i):i;this.opts.limitToBeAddedWhitespace&&(o=j(o,this.opts.limitLinebreaksCount)),E(o)&&!o.length||(this.last()[2]=o)}}else{this.ranges||(this.ranges=[]);let o=i!==void 0&&!(E(i)&&!i.length)?[n,c,i&&this.opts.limitToBeAddedWhitespace?j(i,this.opts.limitLinebreaksCount):i]:[n,c];this.ranges.push(o)}}else throw N(n)&&n>=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 "'.concat(typeof c,'" equal to: ').concat(JSON.stringify(c,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 "'.concat(typeof n,'" equal to: ').concat(JSON.stringify(n,null,4)))}push(e,t,i){this.add(e,t,i)}current(){return Array.isArray(this.ranges)&&this.ranges.length?(this.ranges=be(this.ranges,{mergeType:this.opts.mergeType}),this.ranges&&this.opts.limitToBeAddedWhitespace?this.ranges.map(e=>D(e[2])?[e[0],e[1],j(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])&&N(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, ".concat(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 Y={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function ee(e,t){function i(s){return!!s&&typeof s=="object"&&!Array.isArray(s)}if(!Array.isArray(e)||!e.length)return null;let n;if(t)if(i(t)){if(n=$($({},Y),t),n.progressFn&&i(n.progressFn)&&!Object.keys(n.progressFn).length)n.progressFn=null;else if(n.progressFn&&typeof n.progressFn!="function")throw new Error('ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "'.concat(typeof n.progressFn,'", equal to ').concat(JSON.stringify(n.progressFn,null,4)));if(![1,2,"1","2"].includes(n.mergeType))throw new Error('ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "'.concat(typeof n.mergeType,'", equal to ').concat(JSON.stringify(n.mergeType,null,4)));if(typeof n.joinRangesThatTouchEdges!="boolean")throw new Error('ranges-merge: [THROW_ID_04] opts.joinRangesThatTouchEdges was customised to a wrong thing! It was given of a type: "'.concat(typeof n.joinRangesThatTouchEdges,'", equal to ').concat(JSON.stringify(n.joinRangesThatTouchEdges,null,4)))}else throw new Error("emlint: [THROW_ID_03] the second input argument must be a plain object. It was given as:\n".concat(JSON.stringify(t,null,4)," (type ").concat(typeof t,")"));else n=$({},Y);let c=e.filter(s=>Array.isArray(s)).map(s=>[...s]).filter(s=>s[2]!==void 0||s[0]!==s[1]),r,o,u;n.progressFn?r=k(c,{progressFn:s=>{u=Math.floor(s/5),u!==o&&(o=u,n.progressFn(u))}}):r=k(c);let a=r.length-1;for(let s=a;s>0;s--)n.progressFn&&(u=Math.floor((1-s/a)*78)+21,u!==o&&u>o&&(o=u,n.progressFn(u))),(r[s][0]<=r[s-1][0]||!n.joinRangesThatTouchEdges&&r[s][0]<r[s-1][1]||n.joinRangesThatTouchEdges&&r[s][0]<=r[s-1][1])&&(r[s-1][0]=Math.min(r[s][0],r[s-1][0]),r[s-1][1]=Math.max(r[s][1],r[s-1][1]),r[s][2]!==void 0&&(r[s-1][0]>=r[s][0]||r[s-1][1]<=r[s][1])&&r[s-1][2]!==null&&(r[s][2]===null&&r[s-1][2]!==null?r[s-1][2]=null:r[s-1][2]!=null?+n.mergeType==2&&r[s-1][0]===r[s][0]?r[s-1][2]=r[s][2]:r[s-1][2]+=r[s][2]:r[s-1][2]=r[s][2]),r.splice(s,1),s=r.length);return r.length?r:null}var we=!0,H="Invariant failed";function re(e,t){if(!e){if(we)throw new Error(H);var i=typeof t=="function"?t():t,n=i?"".concat(H,": ").concat(i):H;throw new Error(n)}}function te(e,t,i){let n=0,c=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: ".concat(typeof e,", equal to: ").concat(JSON.stringify(e,null,4)));if(t&&!Array.isArray(t))throw new TypeError("ranges-apply: [THROW_ID_03] second input argument must be an array (or null)! Currently it's: ".concat(typeof t,", equal to: ").concat(JSON.stringify(t,null,4)));if(i&&typeof i!="function")throw new TypeError("ranges-apply: [THROW_ID_04] the third input argument must be a function (or falsey)! Currently it's: ".concat(typeof i,", equal to: ").concat(JSON.stringify(i,null,4)));if(!(t!=null&&t.filter(l=>l).length))return e;let r;Array.isArray(t)&&Number.isInteger(t[0])&&Number.isInteger(t[1])?r=[Array.from(t)]:r=Array.from(t);let o=r.length,u=0;r.filter(l=>l).forEach((l,f)=>{if(i&&(n=Math.floor(u/o*10),n!==c&&(c=n,i(n))),!Array.isArray(l))throw new TypeError("ranges-apply: [THROW_ID_05] ranges array, second input arg., has ".concat(f,"th element not an array: ").concat(JSON.stringify(l,null,4),", which is ").concat(typeof l));if(!Number.isInteger(l[0])){if(!Number.isInteger(+l[0])||+l[0]<0)throw new TypeError("ranges-apply: [THROW_ID_06] ranges array, second input arg. has ".concat(f,"th element, array ").concat(JSON.stringify(l,null,0),". Its first element is not an integer, string index, but ").concat(typeof l[0],", equal to: ").concat(JSON.stringify(l[0],null,4),"."));r[f][0]=+r[f][0]}if(!Number.isInteger(l[1])){if(!Number.isInteger(+l[1])||+l[1]<0)throw new TypeError("ranges-apply: [THROW_ID_07] ranges array, second input arg. has ".concat(f,"th element, array ").concat(JSON.stringify(l,null,0),". Its second element is not an integer, string index, but ").concat(typeof l[1],", equal to: ").concat(JSON.stringify(l[1],null,4),"."));r[f][1]=+r[f][1]}u+=1});let a=ee(r,{progressFn:l=>{i&&(n=10+Math.floor(l/10),n!==c&&(c=n,i(n)))}});re(a);let s=a.length;if(s>0){let l=e.slice(a[s-1][1]);e=a.reduce((f,p,h,g)=>{i&&(n=20+Math.floor(h/s*80),n!==c&&(c=n,i(n)));let m=h===0?0:g[h-1][1],T=g[h][0];return"".concat(f).concat(e.slice(m,T)).concat(g[h][2]||"")},""),e+=l}return e}var Oe={classicTrim:!1,cr:!1,lf:!1,tab:!1,space:!0,nbsp:!1};function F(e,t){if(typeof e!="string")throw new Error("string-trim-spaces-only: [THROW_ID_01] input must be string! It was given as ".concat(typeof e,", equal to:\n").concat(JSON.stringify(e,null,4)));let i=$($({},Oe),t);function n(o){return i.classicTrim&&!o.trim()||!i.classicTrim&&(i.space&&o===" "||i.cr&&o==="\r"||i.lf&&o==="\n"||i.tab&&o===" "||i.nbsp&&o==="\xA0")}let c,r;if(e.length){if(n(e[0]))for(let o=0,u=e.length;o<u;o++){if(!n(e[o])){c=o;break}if(o===e.length-1)return{res:"",ranges:[[0,e.length]]}}if(n(e[e.length-1])){for(let o=e.length;o--;)if(!n(e[o])){r=o+1;break}}return c?r?{res:e.slice(c,r),ranges:[[0,c],[r,e.length]]}:{res:e.slice(c),ranges:[[0,c]]}:r?{res:e.slice(0,r),ranges:[[r,e.length]]}:{res:e,ranges:[]}}return{res:"",ranges:[]}}var ne="7.1.0";var Ee=ne,se={heads:["{{"],tails:["}}"]};function De(e,t){let i=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(t&&!R(t))throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_03] The given options are not a plain object but ".concat(typeof t,"!"));let n=$({},t);if(n&&i.call(n,"heads"))if(I(n.heads).every(m=>typeof m=="string"||Array.isArray(m)))typeof n.heads=="string"&&(n.heads=I(n.heads));else throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_04] The resolvedOpts.heads contains elements which are not string-type!");if(n&&i.call(n,"tails"))if(I(n.tails).every(m=>typeof m=="string"||Array.isArray(m)))typeof n.tails=="string"&&(n.tails=I(n.tails));else throw new Error("string-remove-duplicate-heads-tails: [THROW_ID_05] The resolvedOpts.tails contains elements which are not string-type!");let c=F(e).res;if(c.length===0)return e;e=c;let r=$($({},se),n);r.heads=r.heads.map(m=>m.trim()),r.tails=r.tails.map(m=>m.trim());let o=!1,u=!1,a=new J({limitToBeAddedWhitespace:!0}),s=new J({limitToBeAddedWhitespace:!0}),l=!0,f=!0,p="";function h(m,T){let y;return S(m,0,T.heads,{trimBeforeMatching:!0,cb:(d,A,b)=>(y=b,!0)})&&S(m,y,T.tails,{trimBeforeMatching:!0,cb:(d,A,b)=>(y=b,!0)})?m.slice(y):m}for(;e!==h(e,r);)e=F(h(e,r)).res;function g(m,T){let y;return!x(m,m.length-1,T.tails,{trimBeforeMatching:!0,cb:(d,A,b)=>(y=b,!0)})||!y?m:x(m,y,T.heads,{trimBeforeMatching:!0,cb:(d,A,b)=>(y=b,!0)})?m.slice(0,y+1):m}for(;e!==g(e,r);)e=F(g(e,r)).res;if(!r.heads.length||!S(e,0,r.heads,{trimBeforeMatching:!0})||!r.tails.length||!x(e,e.length-1,r.tails,{trimBeforeMatching:!0}))return F(e).res;for(let m=0,T=e.length;m<T;m++)if(e[m].trim()!==""){let y;if(S(e,m,r.heads,{trimBeforeMatching:!0,cb:(d,A,b)=>(y=b,!0)})&&y){f=!0,l&&(l=!0);let d;S(e,y,r.tails,{trimBeforeMatching:!0,cb:(b,M,C)=>(d=C,!0)})&&a.push(m,d),s.current()&&o&&p!=="tails"&&a.push(s.current()),o||s.current()&&(a.push(s.current()),s.wipe()),s.push(m,y),p="heads",m=y-1;continue}if(S(e,m,r.tails,{trimBeforeMatching:!0,cb:(d,A,b)=>(y=Number.isInteger(b)?b:e.length,!0)})&&y){f=!0,l?(p==="heads"&&s.wipe(),l=!1):s.push(m,y),p="tails",m=y-1;continue}l&&(l=!0),f&&!o?(o=!0,f=!1):f&&!u?(u=!0,l=!0,f=!1,p==="heads"&&s.wipe()):f&&u&&s.wipe()}return s.current()&&a.push(s.current()),a.current()?te(e,a.current()).trim():e.trim()}return he(Me);})(); /** * @name codsen-utils * @fileoverview Various utility functions * @version 1.7.0 * @author Roy Revelt * @license MIT * {@link https://codsen.com/os/codsen-utils/} */ /** * @name arrayiffy-if-string * @fileoverview Put non-empty strings into arrays, turn empty-ones into empty arrays. Bypass everything else. * @version 5.1.0 * @author Roy Revelt * @license MIT * {@link https://codsen.com/os/arrayiffy-if-string/} */ /** * @name string-match-left-right * @fileoverview Match substrings on the left or right of a given index, ignoring whitespace * @version 9.1.0 * @author Roy Revelt * @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.1.0 * @author Roy Revelt * @license MIT * {@link https://codsen.com/os/string-collapse-leading-whitespace/} */ /** * @name ranges-sort * @fileoverview Sort string index ranges * @version 6.1.0 * @author Roy Revelt * @license MIT * {@link https://codsen.com/os/ranges-sort/} */ /** * @name ranges-push * @fileoverview Gather string index ranges * @version 7.1.0 * @author Roy Revelt * @license MIT * {@link https://codsen.com/os/ranges-push/} */ /** * @name ranges-merge * @fileoverview Merge and sort string index ranges * @version 9.1.0 * @author Roy Revelt * @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.1.0 * @author Roy Revelt * @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.1.0 * @author Roy Revelt * @license MIT * {@link https://codsen.com/os/string-trim-spaces-only/} */