string-collapse-white-space
Version:
Replace chunks of whitespace with a single spaces
87 lines (85 loc) • 21.1 kB
JavaScript
/**
* @name string-collapse-white-space
* @fileoverview Replace chunks of whitespace with a single spaces
* @version 11.0.23
* @author Roy Revelt, Codsen Ltd
* @license MIT
* {@link https://codsen.com/os/string-collapse-white-space/}
*/
;var stringCollapseWhiteSpace=(()=>{var G=Object.create;var x=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames,C=Object.getOwnPropertySymbols,ee=Object.getPrototypeOf,W=Object.prototype.hasOwnProperty,te=Object.prototype.propertyIsEnumerable;var R=(e,r,l)=>r in e?x(e,r,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[r]=l,h=(e,r)=>{for(var l in r||(r={}))W.call(r,l)&&R(e,l,r[l]);if(C)for(var l of C(r))te.call(r,l)&&R(e,l,r[l]);return e};var re=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),ne=(e,r)=>{for(var l in r)x(e,l,{get:r[l],enumerable:!0})},J=(e,r,l,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let u of X(r))!W.call(e,u)&&u!==l&&x(e,u,{get:()=>r[u],enumerable:!(s=Y(r,u))||s.enumerable});return e};var F=(e,r,l)=>(l=e!=null?G(ee(e)):{},J(r||!e||!e.__esModule?x(l,"default",{value:e,enumerable:!0}):l,e)),se=e=>J(x({},"__esModule",{value:!0}),e);var I=(e,r,l)=>R(e,typeof r!="symbol"?r+"":r,l);var V=re((xe,q)=>{"use strict";q.exports=le;function O(e){return e instanceof Buffer?Buffer.from(e):new e.constructor(e.buffer.slice(),e.byteOffset,e.length)}function le(e){if(e=e||{},e.circles)return ae(e);let r=new Map;if(r.set(Date,a=>new Date(a)),r.set(Map,(a,c)=>new Map(s(Array.from(a),c))),r.set(Set,(a,c)=>new Set(s(Array.from(a),c))),e.constructorHandlers)for(let a of e.constructorHandlers)r.set(a[0],a[1]);let l=null;return e.proto?t:u;function s(a,c){let o=Object.keys(a),n=new Array(o.length);for(let i=0;i<o.length;i++){let f=o[i],m=a[f];typeof m!="object"||m===null?n[f]=m:m.constructor!==Object&&(l=r.get(m.constructor))?n[f]=l(m,c):ArrayBuffer.isView(m)?n[f]=O(m):n[f]=c(m)}return n}function u(a){if(typeof a!="object"||a===null)return a;if(Array.isArray(a))return s(a,u);if(a.constructor!==Object&&(l=r.get(a.constructor)))return l(a,u);let c={};for(let o in a){if(Object.hasOwnProperty.call(a,o)===!1)continue;let n=a[o];typeof n!="object"||n===null?c[o]=n:n.constructor!==Object&&(l=r.get(n.constructor))?c[o]=l(n,u):ArrayBuffer.isView(n)?c[o]=O(n):c[o]=u(n)}return c}function t(a){if(typeof a!="object"||a===null)return a;if(Array.isArray(a))return s(a,t);if(a.constructor!==Object&&(l=r.get(a.constructor)))return l(a,t);let c={};for(let o in a){let n=a[o];typeof n!="object"||n===null?c[o]=n:n.constructor!==Object&&(l=r.get(n.constructor))?c[o]=l(n,t):ArrayBuffer.isView(n)?c[o]=O(n):c[o]=t(n)}return c}}function ae(e){let r=[],l=[],s=new Map;if(s.set(Date,o=>new Date(o)),s.set(Map,(o,n)=>new Map(t(Array.from(o),n))),s.set(Set,(o,n)=>new Set(t(Array.from(o),n))),e.constructorHandlers)for(let o of e.constructorHandlers)s.set(o[0],o[1]);let u=null;return e.proto?c:a;function t(o,n){let i=Object.keys(o),f=new Array(i.length);for(let m=0;m<i.length;m++){let p=i[m],g=o[p];if(typeof g!="object"||g===null)f[p]=g;else if(g.constructor!==Object&&(u=s.get(g.constructor)))f[p]=u(g,n);else if(ArrayBuffer.isView(g))f[p]=O(g);else{let S=r.indexOf(g);S!==-1?f[p]=l[S]:f[p]=n(g)}}return f}function a(o){if(typeof o!="object"||o===null)return o;if(Array.isArray(o))return t(o,a);if(o.constructor!==Object&&(u=s.get(o.constructor)))return u(o,a);let n={};r.push(o),l.push(n);for(let i in o){if(Object.hasOwnProperty.call(o,i)===!1)continue;let f=o[i];if(typeof f!="object"||f===null)n[i]=f;else if(f.constructor!==Object&&(u=s.get(f.constructor)))n[i]=u(f,a);else if(ArrayBuffer.isView(f))n[i]=O(f);else{let m=r.indexOf(f);m!==-1?n[i]=l[m]:n[i]=a(f)}}return r.pop(),l.pop(),n}function c(o){if(typeof o!="object"||o===null)return o;if(Array.isArray(o))return t(o,c);if(o.constructor!==Object&&(u=s.get(o.constructor)))return u(o,c);let n={};r.push(o),l.push(n);for(let i in o){let f=o[i];if(typeof f!="object"||f===null)n[i]=f;else if(f.constructor!==Object&&(u=s.get(f.constructor)))n[i]=u(f,c);else if(ArrayBuffer.isView(f))n[i]=O(f);else{let m=r.indexOf(f);m!==-1?n[i]=l[m]:n[i]=c(f)}}return r.pop(),l.pop(),n}}});var de={};ne(de,{cbSchema:()=>me,collapse:()=>he,defaults:()=>Z,version:()=>pe});var ie={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function T(e,r){if(!Array.isArray(e)||!e.length)return e;let l=h(h({},ie),r),s,u;if(l.strictlyTwoElementsInRangeArrays&&!e.every((c,o)=>!Array.isArray(c)||c.length!==2?(s=o,u=c.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, ${s}th range (${JSON.stringify(e[s],null,4)}) has not two but ${u} elements!`);if(!e.every((c,o)=>!Array.isArray(c)||!Number.isInteger(c[0])||c[0]<0||!Number.isInteger(c[1])||c[1]<0?(s=o,!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, ${s}th range (${JSON.stringify(e[s],null,4)}) does not consist of only natural numbers!`);let t=e.length**2,a=0;return Array.from(e).sort((c,o)=>(l.progressFn&&(a+=1,l.progressFn(Math.floor(a*100/t))),c[0]===o[0]?c[1]<o[1]?-1:c[1]>o[1]?1:0:c[0]<o[0]?-1:1))}var L={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function H(e,r){function l(n){return!!n&&typeof n=="object"&&!Array.isArray(n)}if(!Array.isArray(e)||!e.length)return null;let s;if(r)if(l(r)){if(s=h(h({},L),r),s.progressFn&&l(s.progressFn)&&!Object.keys(s.progressFn).length)s.progressFn=null;else if(s.progressFn&&typeof s.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof s.progressFn}", equal to ${JSON.stringify(s.progressFn,null,4)}`);if(![1,2,"1","2"].includes(s.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof s.mergeType}", equal to ${JSON.stringify(s.mergeType,null,4)}`);if(typeof s.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 s.joinRangesThatTouchEdges}", equal to ${JSON.stringify(s.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 s=h({},L);let u=e.filter(n=>Array.isArray(n)).map(n=>[...n]).filter(n=>n[2]!==void 0||n[0]!==n[1]),t,a,c;s.progressFn?t=T(u,{progressFn:n=>{c=Math.floor(n/5),c!==a&&(a=c,s.progressFn(c))}}):t=T(u);let o=t.length-1;for(let n=o;n>0;n--)s.progressFn&&(c=Math.floor((1-n/o)*78)+21,c!==a&&c>a&&(a=c,s.progressFn(c))),(t[n][0]<=t[n-1][0]||!s.joinRangesThatTouchEdges&&t[n][0]<t[n-1][1]||s.joinRangesThatTouchEdges&&t[n][0]<=t[n-1][1])&&(t[n-1][0]=Math.min(t[n][0],t[n-1][0]),t[n-1][1]=Math.max(t[n][1],t[n-1][1]),t[n][2]!==void 0&&(t[n-1][0]>=t[n][0]||t[n-1][1]<=t[n][1])&&t[n-1][2]!==null&&(t[n][2]===null&&t[n-1][2]!==null?t[n-1][2]=null:t[n-1][2]!=null?+s.mergeType==2&&t[n-1][0]===t[n][0]?t[n-1][2]=t[n][2]:t[n-1][2]+=t[n][2]:t[n-1][2]=t[n][2]),t.splice(n,1),n=t.length);return t.length?t:null}var oe=!0,j="Invariant failed";function B(e,r){if(!e){if(oe)throw new Error(j);var l=typeof r=="function"?r():r,s=l?"".concat(j,": ").concat(l):j;throw new Error(s)}}function M(e,r,l){let s=0,u=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(l&&typeof l!="function")throw new TypeError(`ranges-apply: [THROW_ID_04] the third input argument must be a function (or falsey)! Currently it's: ${typeof l}, equal to: ${JSON.stringify(l,null,4)}`);if(!(r!=null&&r.filter(i=>i).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 a=t.length,c=0;t.filter(i=>i).forEach((i,f)=>{if(l&&(s=Math.floor(c/a*10),s!==u&&(u=s,l(s))),!Array.isArray(i))throw new TypeError(`ranges-apply: [THROW_ID_05] ranges array, second input arg., has ${f}th element not an array: ${JSON.stringify(i,null,4)}, which is ${typeof i}`);if(!Number.isInteger(i[0])){if(!Number.isInteger(+i[0])||+i[0]<0)throw new TypeError(`ranges-apply: [THROW_ID_06] ranges array, second input arg. has ${f}th element, array ${JSON.stringify(i,null,0)}. Its first element is not an integer, string index, but ${typeof i[0]}, equal to: ${JSON.stringify(i[0],null,4)}.`);t[f][0]=+t[f][0]}if(!Number.isInteger(i[1])){if(!Number.isInteger(+i[1])||+i[1]<0)throw new TypeError(`ranges-apply: [THROW_ID_07] ranges array, second input arg. has ${f}th element, array ${JSON.stringify(i,null,0)}. Its second element is not an integer, string index, but ${typeof i[1]}, equal to: ${JSON.stringify(i[1],null,4)}.`);t[f][1]=+t[f][1]}c+=1});let o=H(t,{progressFn:i=>{l&&(s=10+Math.floor(i/10),s!==u&&(u=s,l(s)))}});B(o);let n=o.length;if(n>0){let i=e.slice(o[n-1][1]);e=o.reduce((f,m,p,g)=>{l&&(s=20+Math.floor(p/n*80),s!==u&&(u=s,l(s)));let S=p===0?0:g[p-1][1],d=g[p][0];return`${f}${e.slice(S,d)}${g[p][2]||""}`},""),e+=i}return e}function N(e,r=1){let l="\xA0";function s(t){return Array.from(t).reverse().join("")}function u(t,a,c){let o=c?`
`:"\r",n=c?"\r":`
`;if(!t)return t;let i=0,f=0,m="";for(let p=0,g=t.length;p<g;p++)(t[p]===o||t[p]===n&&t[p-1]!==o)&&f++,`\r
`.includes(t[p])||t[p]===l?(i=0,t[p]===l?m+=t[p]:t[p]===o?f<=a&&(m+=t[p],t[p+1]===n&&(m+=t[p+1],p++)):t[p]===n&&(t==null?void 0:t[p-1])!==o&&f<=a&&(m+=t[p])):(i++,!t[p+1]&&!f&&(m+=" "));return m}if(typeof e=="string"&&e.length){let t=1;typeof+r=="number"&&Number.isInteger(+r)&&+r>=0&&(t=+r);let a="",c="";if(!e.trim())a=e;else if(!e[0].trim()){for(let o=0,n=e.length;o<n;o++)if(e[o].trim()){a=e.slice(0,o);break}}if(e.trim()&&(e.slice(-1).trim()===""||e.slice(-1)===l)){for(let o=e.length;o--;)if(e[o].trim()){c=e.slice(o+1);break}}return`${u(a,t,!1)}${e.trim()}${s(u(s(c),t,!0))}`}return e}var P=F(V(),1);var Ne=(0,P.default)();function E(e){return typeof e=="string"}function w(e){return Number.isSafeInteger(e)&&e>=0}function A(e){return e!=null}var Q={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function ue(e,r){var n;function l(i){return!!i&&typeof i=="object"&&!Array.isArray(i)}if(!Array.isArray(e)||!e.length)return null;let s;if(r)if(l(r)){if(s=h(h({},Q),r),s.progressFn&&l(s.progressFn)&&!Object.keys(s.progressFn).length)s.progressFn=null;else if(s.progressFn&&typeof s.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] resolvedOpts.progressFn must be a function! It was given of a type: "${typeof s.progressFn}", equal to ${JSON.stringify(s.progressFn,null,4)}`);if(![1,2,"1","2"].includes(s.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] resolvedOpts.mergeType was customised to a wrong thing! It was given of a type: "${typeof s.mergeType}", equal to ${JSON.stringify(s.mergeType,null,4)}`);if(typeof s.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 s.joinRangesThatTouchEdges}", equal to ${JSON.stringify(s.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 s=h({},Q);let u=e.filter(i=>Array.isArray(i)).map(i=>[...i]).filter(i=>i[2]!==void 0||i[0]!==i[1]),t,a,c;s.progressFn?t=T(u,{progressFn:i=>{c=Math.floor(i/5),c!==a&&(a=c,s.progressFn!=null&&s.progressFn(c))}}):t=T(u);let o=t.length-1;for(let i=o;i>0;i--)s.progressFn&&(c=Math.floor((1-i/o)*78)+21,c!==a&&c>a&&(a=c,s.progressFn(c))),(t[i][0]<=t[i-1][0]||!s.joinRangesThatTouchEdges&&t[i][0]<t[i-1][1]||s.joinRangesThatTouchEdges&&t[i][0]<=t[i-1][1])&&(t[i-1][0]=Math.min(t[i][0],t[i-1][0]),t[i-1][1]=Math.max(t[i][1],t[i-1][1]),t[i][2]!==void 0&&(t[i-1][0]>=t[i][0]||t[i-1][1]<=t[i][1])&&t[i-1][2]!==null&&(t[i][2]===null&&t[i-1][2]!==null?t[i-1][2]=null:t[i-1][2]!=null?+((n=s||{})==null?void 0:n.mergeType)==2&&t[i-1][0]===t[i][0]?t[i-1][2]=t[i][2]:t[i-1][2]+=t[i][2]:t[i-1][2]=t[i][2]),t.splice(i,1),i=t.length);return t.length?t:null}var ce={limitToBeAddedWhitespace:!1,limitLinebreaksCount:1,mergeType:1},U=class{constructor(e){I(this,"ranges");I(this,"opts");let r=h(h({},ce),e);if(r.mergeType&&r.mergeType!==1&&r.mergeType!==2)if(E(r.mergeType)&&r.mergeType.trim()==="1")r.mergeType=1;else if(E(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,l){var t;if(e==null&&r==null)return;if(A(e)&&!A(r)){if(Array.isArray(e)){if(e.length){if(e.some(a=>Array.isArray(a))){e.forEach(a=>{Array.isArray(a)&&this.add(...a)});return}e.length&&w(+e[0])&&w(+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(!A(e)&&A(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 s=+e,u=+r;if(w(l)&&(l=String(l)),w(s)&&w(u)){if(A(l)&&!E(l)&&!w(l))throw new TypeError(`ranges-push/Ranges/add(): [THROW_ID_08] The third argument, the value to add, was given not as string but ${typeof l}, equal to:
${JSON.stringify(l,null,4)}`);if(A(this.ranges)&&Array.isArray(this.last())&&s===this.last()[1]){if(this.last()[1]=u,this.last()[2],this.last()[2]!==null&&A(l)){let a=this.last()[2]&&this.last()[2].length&&(!((t=this.opts)!=null&&t.mergeType)||this.opts.mergeType===1)?`${this.last()[2]}${l}`:l;this.opts.limitToBeAddedWhitespace&&(a=N(a,this.opts.limitLinebreaksCount)),E(a)&&!a.length||(this.last()[2]=a)}}else{this.ranges||(this.ranges=[]);let a=l!==void 0&&!(E(l)&&!l.length)?[s,u,l&&this.opts.limitToBeAddedWhitespace?N(l,this.opts.limitLinebreaksCount):l]:[s,u];this.ranges.push(a)}}else throw w(s)&&s>=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 u}" equal to: ${JSON.stringify(u,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 s}" equal to: ${JSON.stringify(s,null,4)}`)}push(e,r,l){this.add(e,r,l)}current(){return Array.isArray(this.ranges)&&this.ranges.length?(this.ranges=ue(this.ranges,{mergeType:this.opts.mergeType}),this.ranges&&this.opts.limitToBeAddedWhitespace?this.ranges.map(e=>A(e[2])?[e[0],e[1],N(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])&&w(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 z=F(V(),1);var Fe=(0,z.default)();var k="\xA0";function ge({str:e,idx:r=0,stopAtNewlines:l=!1,stopAtRawNbsp:s=!1}){if(typeof e!="string"||!e.length||((!r||typeof r!="number")&&(r=0),!e[r+1]))return null;if(e[r+1]&&(e[r+1].trim()||l&&`
\r`.includes(e[r+1])||s&&e[r+1]===k))return r+1;if(e[r+2]&&(e[r+2].trim()||l&&`
\r`.includes(e[r+2])||s&&e[r+2]===k))return r+2;for(let u=r+1,t=e.length;u<t;u++)if(e[u].trim()||l&&`
\r`.includes(e[u])||s&&e[u]===k)return u;return null}function _(e,r=0){return ge({str:e,idx:r,stopAtNewlines:!1,stopAtRawNbsp:!1})}var K="11.0.23";var pe=K,Z={trimStart:!0,trimEnd:!0,trimLines:!1,trimnbsp:!1,removeEmptyLines:!1,limitConsecutiveEmptyLinesTo:0,enforceSpacesOnly:!1,cb:({suggested:e})=>e},me=["suggested","whiteSpaceStartsAt","whiteSpaceEndsAt","str"];function he(e,r){if(typeof e!="string")throw new Error(`string-collapse-white-space/collapse(): [THROW_ID_01] The input is not string but ${typeof e}, equal to: ${JSON.stringify(e,null,4)}`);if(r&&typeof r!="object")throw new Error(`string-collapse-white-space/collapse(): [THROW_ID_02] The resolvedOpts is not a plain object but ${typeof r}, equal to:
${JSON.stringify(r,null,4)}`);if(!e.length)return{result:"",ranges:null};let l=new U,s="\xA0",u=h(h({},Z),r);function t(g,S){if(typeof u.cb=="function"){let d=u.cb(h({suggested:g},S));Array.isArray(d)&&l.push(...d)}else g&&l.push(...g)}let a=null,c=null,o=null,n=null,i=null,f=!1,m=[],p=0;for(let g=0,S=e.length;g<=S;g++){if((e[g]==="\r"||e[g]===`
`&&e[g-1]!=="\r")&&(p+=1,n===null&&(n=g),i=e[g]==="\r"&&e[g+1]===`
`?g+2:g+1),!u.trimnbsp&&e[g]===s&&!f&&(f=!0),a!==null&&e[g]!==" "){let d=a&&c||!c&&(!u.trimStart||!u.trimnbsp&&(e[g]===s||e[a-1]===s)),b=e[g]||!u.trimEnd||!u.trimnbsp&&(e[g]===s||e[a-1]===s),y=!u.enforceSpacesOnly||(!e[a-1]||e[a-1].trim())&&(!e[g]||e[g].trim());if(a<g-1&&d&&b&&y){let $=a,v=g,D=" ";u.trimLines&&(!a||!e[g]||e[a-1]&&`\r
`.includes(e[a-1])||e[g]&&`\r
`.includes(e[g]))&&(D=null),D&&e[a]===" "&&(v-=1,D=null),(!a&&u.trimStart||!e[g]&&u.trimEnd)&&(v=g),m.push([D?[$,v,D]:[$,v],{whiteSpaceStartsAt:c,whiteSpaceEndsAt:_(e,g-1)||g,str:e}])}}if(a===null&&e[g]===" "&&(a=g),c===null&&e[g]&&!e[g].trim()&&(c=g),o!==null&&(`
\r`.includes(e[g])||!e[g]||e[g].trim()||!(u.trimnbsp||u.enforceSpacesOnly)&&e[g]===s)&&(o||!u.trimStart||u.enforceSpacesOnly&&f)&&(e[g]||!u.trimEnd||u.enforceSpacesOnly&&f)){if(u.enforceSpacesOnly&&(g>o+1||e[o]!==" ")){let d=o,b=g,y=" ";e[b-1]===" "?(b-=1,y=null):e[o]===" "&&(d+=1,y=null),((u.trimStart||u.trimLines)&&!o||(u.trimEnd||u.trimLines)&&!e[g])&&(y=null),t(y?[d,b,y]:[d,b],{whiteSpaceStartsAt:c,whiteSpaceEndsAt:g,str:e})}u.trimLines&&(!o||`\r
`.includes(e[o-1])||!e[g]||`\r
`.includes(e[g]))&&(u.trimnbsp||!f)&&t([o,g],{whiteSpaceStartsAt:c,whiteSpaceEndsAt:_(e,g-1)||g,str:e}),o=null}if(o===null&&!`\r
`.includes(e[g])&&e[g]&&!e[g].trim()&&(u.trimnbsp||e[g]!==s||u.enforceSpacesOnly)&&(o=g),c!==null&&(!e[g]||e[g].trim())){if((!c&&(u.trimStart||u.trimLines&&n===null)||!e[g]&&(u.trimEnd||u.trimLines&&n===null))&&(u.trimnbsp||!f||u.enforceSpacesOnly))t([c,g],{whiteSpaceStartsAt:c,whiteSpaceEndsAt:g,str:e});else{let d=!1;if(u.removeEmptyLines&&n!==null&&p>(u.limitConsecutiveEmptyLinesTo||0)+1){d=!0;let b=n,y=i||e.length,$=`${e[n]==="\r"&&e[n+1]===`
`?`\r
`:e[n]}`.repeat((u.limitConsecutiveEmptyLinesTo||0)+1);e.endsWith($,i)?(y-=$.length||0,$=null):e.startsWith($,n)&&(b+=$.length,$=null),t($?[b,y,$]:[b,y],{whiteSpaceStartsAt:c,whiteSpaceEndsAt:g,str:e})}if(m.length){for(;m.length;)t(...m.shift());d=!0}d||t(null,{whiteSpaceStartsAt:c,whiteSpaceEndsAt:g,str:e})}c=null,o=null,f=!1,p&&(p=0,n=null,i=null)}a!==null&&e[g]!==" "&&(a=null)}return{result:M(e,l.current()),ranges:l.current()}}return se(de);})();
/**
* @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-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-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 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 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 string-left-right
* @fileoverview Looks up the first non-whitespace character to the left/right of a given index
* @version 6.0.21
* @author Roy Revelt, Codsen Ltd
* @license MIT
* {@link https://codsen.com/os/string-left-right/}
*/