UNPKG

edit-package-json

Version:

Edit package.json without parsing, as string, to keep the formatting intact

72 lines (70 loc) 24.7 kB
/** * @name edit-package-json * @fileoverview Edit package.json without parsing, as string, to keep the formatting intact * @version 0.8.27 * @author Roy Revelt, Codsen Ltd * @license MIT * {@link https://codsen.com/os/edit-package-json/} */ "use strict";var editPackageJson=(()=>{var $e=Object.create;var x=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var fe=Object.getOwnPropertyNames,q=Object.getOwnPropertySymbols,me=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty,ge=Object.prototype.propertyIsEnumerable;var Q=(e,t,i)=>t in e?x(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,w=(e,t)=>{for(var i in t||(t={}))K.call(t,i)&&Q(e,i,t[i]);if(q)for(var i of q(t))ge.call(t,i)&&Q(e,i,t[i]);return e};var be=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),pe=(e,t)=>{for(var i in t)x(e,i,{get:t[i],enumerable:!0})},z=(e,t,i,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of fe(t))!K.call(e,n)&&n!==i&&x(e,n,{get:()=>t[n],enumerable:!(l=ce(t,n))||l.enumerable});return e};var G=(e,t,i)=>(i=e!=null?$e(me(e)):{},z(t||!e||!e.__esModule?x(i,"default",{value:e,enumerable:!0}):i,e)),he=e=>z(x({},"__esModule",{value:!0}),e);var F=be((ke,Z)=>{"use strict";Z.exports=ye;function W(e){return e instanceof Buffer?Buffer.from(e):new e.constructor(e.buffer.slice(),e.byteOffset,e.length)}function ye(e){if(e=e||{},e.circles)return de(e);let t=new Map;if(t.set(Date,s=>new Date(s)),t.set(Map,(s,c)=>new Map(l(Array.from(s),c))),t.set(Set,(s,c)=>new Set(l(Array.from(s),c))),e.constructorHandlers)for(let s of e.constructorHandlers)t.set(s[0],s[1]);let i=null;return e.proto?r:n;function l(s,c){let a=Object.keys(s),u=new Array(a.length);for(let o=0;o<a.length;o++){let $=a[o],m=s[$];typeof m!="object"||m===null?u[$]=m:m.constructor!==Object&&(i=t.get(m.constructor))?u[$]=i(m,c):ArrayBuffer.isView(m)?u[$]=W(m):u[$]=c(m)}return u}function n(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return l(s,n);if(s.constructor!==Object&&(i=t.get(s.constructor)))return i(s,n);let c={};for(let a in s){if(Object.hasOwnProperty.call(s,a)===!1)continue;let u=s[a];typeof u!="object"||u===null?c[a]=u:u.constructor!==Object&&(i=t.get(u.constructor))?c[a]=i(u,n):ArrayBuffer.isView(u)?c[a]=W(u):c[a]=n(u)}return c}function r(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return l(s,r);if(s.constructor!==Object&&(i=t.get(s.constructor)))return i(s,r);let c={};for(let a in s){let u=s[a];typeof u!="object"||u===null?c[a]=u:u.constructor!==Object&&(i=t.get(u.constructor))?c[a]=i(u,r):ArrayBuffer.isView(u)?c[a]=W(u):c[a]=r(u)}return c}}function de(e){let t=[],i=[],l=new Map;if(l.set(Date,a=>new Date(a)),l.set(Map,(a,u)=>new Map(r(Array.from(a),u))),l.set(Set,(a,u)=>new Set(r(Array.from(a),u))),e.constructorHandlers)for(let a of e.constructorHandlers)l.set(a[0],a[1]);let n=null;return e.proto?c:s;function r(a,u){let o=Object.keys(a),$=new Array(o.length);for(let m=0;m<o.length;m++){let g=o[m],f=a[g];if(typeof f!="object"||f===null)$[g]=f;else if(f.constructor!==Object&&(n=l.get(f.constructor)))$[g]=n(f,u);else if(ArrayBuffer.isView(f))$[g]=W(f);else{let y=t.indexOf(f);y!==-1?$[g]=i[y]:$[g]=u(f)}}return $}function s(a){if(typeof a!="object"||a===null)return a;if(Array.isArray(a))return r(a,s);if(a.constructor!==Object&&(n=l.get(a.constructor)))return n(a,s);let u={};t.push(a),i.push(u);for(let o in a){if(Object.hasOwnProperty.call(a,o)===!1)continue;let $=a[o];if(typeof $!="object"||$===null)u[o]=$;else if($.constructor!==Object&&(n=l.get($.constructor)))u[o]=n($,s);else if(ArrayBuffer.isView($))u[o]=W($);else{let m=t.indexOf($);m!==-1?u[o]=i[m]:u[o]=s($)}}return t.pop(),i.pop(),u}function c(a){if(typeof a!="object"||a===null)return a;if(Array.isArray(a))return r(a,c);if(a.constructor!==Object&&(n=l.get(a.constructor)))return n(a,c);let u={};t.push(a),i.push(u);for(let o in a){let $=a[o];if(typeof $!="object"||$===null)u[o]=$;else if($.constructor!==Object&&(n=l.get($.constructor)))u[o]=n($,c);else if(ArrayBuffer.isView($))u[o]=W($);else{let m=t.indexOf($);m!==-1?u[o]=i[m]:u[o]=c($)}}return t.pop(),i.pop(),u}}});var Re={};pe(Re,{del:()=>We,set:()=>Ie,version:()=>je});var Y=G(F(),1);var xe=(0,Y.default)();function V(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 v(e){return typeof e=="string"}function X(e){return Number.isFinite(e)}function ee(e){return Number.isSafeInteger(e)&&e>=0}var te=G(F(),1);var J=(0,te.default)();var R="\xA0";function we(e){let t={value:e,hungry:!1,optional:!1};return(t.value.endsWith("?*")||t.value.endsWith("*?"))&&t.value.length>2?(t.value=t.value.slice(0,t.value.length-2),t.optional=!0,t.hungry=!0):t.value.endsWith("?")&&t.value.length>1?(t.value=t.value.slice(0,~-t.value.length),t.optional=!0):t.value.endsWith("*")&&t.value.length>1&&(t.value=t.value.slice(0,~-t.value.length),t.hungry=!0),t}function Ae({str:e,idx:t=0,stopAtNewlines:i=!1,stopAtRawNbsp:l=!1}){if(typeof e!="string"||!e.length||((!t||typeof t!="number")&&(t=0),!e[t+1]))return null;if(e[t+1]&&(e[t+1].trim()||i&&` \r`.includes(e[t+1])||l&&e[t+1]===R))return t+1;if(e[t+2]&&(e[t+2].trim()||i&&` \r`.includes(e[t+2])||l&&e[t+2]===R))return t+2;for(let n=t+1,r=e.length;n<r;n++)if(e[n].trim()||i&&` \r`.includes(e[n])||l&&e[n]===R)return n;return null}function I(e,t=0){return Ae({str:e,idx:t,stopAtNewlines:!1,stopAtRawNbsp:!1})}function Se({str:e,idx:t,stopAtNewlines:i,stopAtRawNbsp:l}){if(typeof e!="string"||!e.length||((!t||typeof t!="number")&&(t=0),t<1))return null;if(e[~-t]&&(e[~-t].trim()||i&&` \r`.includes(e[~-t])||l&&e[~-t]===R))return~-t;if(e[t-2]&&(e[t-2].trim()||i&&` \r`.includes(e[t-2])||l&&e[t-2]===R))return t-2;for(let n=t;n--;)if(e[n]&&(e[n].trim()||i&&` \r`.includes(e[n])||l&&e[n]===R))return n;return null}function D(e,t=0){return Se({str:e,idx:t,stopAtNewlines:!1,stopAtRawNbsp:!1})}function ne(e,t,i,l,n){if(typeof t!="string"||!t.length||(typeof i!="number"&&(i=0),e==="right"&&!t[i+1]||e==="left"&&!t[~-i]))return null;let r=i,s=[],c,a,u,o=0;for(;o<n.length;){if(!v(n[o])||!n[o].length){o+=1;continue}let{value:$,optional:m,hungry:g}=we(n[o]),f=e==="right"?I(t,r):D(t,r);if(l.i&&t[f].toLowerCase()===$.toLowerCase()||!l.i&&t[f]===$){let y=e==="right"?I(t,f):D(t,f);g&&(l.i&&t[y].toLowerCase()===$.toLowerCase()||!l.i&&t[y]===$)?u=!0:o+=1,typeof f=="number"&&e==="right"&&f>r+1?s.push([r+1,f]):e==="left"&&typeof f=="number"&&f<~-r&&s.unshift([f+1,r]),r=f,e==="right"?(c===void 0&&(c=f),a=f):(a===void 0&&(a=f),c=f)}else if(m){o+=1;continue}else if(u){o+=1,u=void 0;continue}else return null}return c===void 0||a===void 0?null:{gaps:s,leftmostChar:c,rightmostChar:a}}var C={i:!1};function Ee(e,t,...i){if(!(i!=null&&i.length))throw new Error("string-left-right/leftSeq(): only two input arguments were passed! Did you intend to use left() method instead?");let l;return V(i[0])?l=w(w({},C),i.shift()):l=C,ne("left",e,t,l,Array.from(i).reverse())}function Oe(e,t,...i){if(!(i!=null&&i.length))throw new Error("string-left-right/rightSeq(): only two input arguments were passed! Did you intend to use right() method instead?");let l;return V(i[0])?l=w(w({},C),i.shift()):l=C,ne("right",e,t,l,i)}function _(e,t,i,l,n=[]){var a,u;if(typeof t!="string"||!t.length||((!i||typeof i!="number")&&(i=0),e==="right"&&!t[i+1]||e==="left"&&+i==0))return null;let r=null,s=null;do r=e==="right"?Oe(t,typeof s=="number"?s:i,...n):Ee(t,typeof s=="number"?s:i,...n),r!==null&&(s=e==="right"?r.rightmostChar:r.leftmostChar);while(r);if(s!=null&&e==="right"&&(s+=1),s===null)return null;if(e==="right"){if((a=t[s])!=null&&a.trim())return s;let o=I(t,s);if(!l||l.mode===0){if(o===s+1)return s;if(t.slice(s,o||t.length).trim()||t.slice(s,o||t.length).includes(` `)||t.slice(s,o||t.length).includes("\r")){for(let $=s,m=t.length;$<m;$++)if(` \r`.includes(t[$]))return $}else return o?~-o:t.length}else{if(l.mode===1)return s;if(l.mode===2){let $=t.slice(s);if($.trim()||$.includes(` `)||$.includes("\r")){for(let m=s,g=t.length;m<g;m++)if(t[m].trim()||` \r`.includes(t[m]))return m}return t.length}}return o||t.length}if(t[s]&&((u=t[~-s])!=null&&u.trim()))return s;let c=D(t,s);if(!l||l.mode===0){if(c===s-2)return s;if(t.slice(0,s).trim()||t.slice(0,s).includes(` `)||t.slice(0,s).includes("\r")){for(let o=s;o--;)if(` \r`.includes(t[o])||t[o].trim())return o+1+(t[o].trim()?1:0)}return 0}if(l.mode===1)return s;if(l.mode===2){let o=t.slice(0,s);if(o.trim()||o.includes(` `)||o.includes("\r")){for(let $=s;$--;)if(t[$].trim()||` \r`.includes(t[$]))return $+1}return 0}return c!==null?c+1:0}function re(e,t,...i){if(!i.length||i.length===1&&V(i[0]))return null;let l={mode:0};if(V(i[0])){let n=w(w({},l),J(i[0]));if(!n.mode)n.mode=0;else if(v(n.mode)&&n.mode.length===1&&"0123".includes(n.mode))n.mode=+n.mode;else if(!ee(n.mode))throw new Error(`string-left-right/chompLeft(): [THROW_ID_01] the opts.mode is wrong! It should be 0, 1, 2 or 3. It was given as ${n.mode} (type ${typeof n.mode})`);return _("left",e,t,n,J(i).slice(1))}return v(i[0])?_("left",e,t,l,J(i)):_("left",e,t,l,J(i).slice(1))}var Te={strictlyTwoElementsInRangeArrays:!1,progressFn:null};function H(e,t){if(!Array.isArray(e)||!e.length)return e;let i=w(w({},Te),t),l,n;if(i.strictlyTwoElementsInRangeArrays&&!e.every((c,a)=>!Array.isArray(c)||c.length!==2?(l=a,n=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, ${l}th range (${JSON.stringify(e[l],null,4)}) has not two but ${n} elements!`);if(!e.every((c,a)=>!Array.isArray(c)||!Number.isInteger(c[0])||c[0]<0||!Number.isInteger(c[1])||c[1]<0?(l=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, ${l}th range (${JSON.stringify(e[l],null,4)}) does not consist of only natural numbers!`);let r=e.length**2,s=0;return Array.from(e).sort((c,a)=>(i.progressFn&&(s+=1,i.progressFn(Math.floor(s*100/r))),c[0]===a[0]?c[1]<a[1]?-1:c[1]>a[1]?1:0:c[0]<a[0]?-1:1))}var ie={mergeType:1,progressFn:null,joinRangesThatTouchEdges:!0};function ue(e,t){function i(u){return!!u&&typeof u=="object"&&!Array.isArray(u)}if(!Array.isArray(e)||!e.length)return null;let l;if(t)if(i(t)){if(l=w(w({},ie),t),l.progressFn&&i(l.progressFn)&&!Object.keys(l.progressFn).length)l.progressFn=null;else if(l.progressFn&&typeof l.progressFn!="function")throw new Error(`ranges-merge: [THROW_ID_01] opts.progressFn must be a function! It was given of a type: "${typeof l.progressFn}", equal to ${JSON.stringify(l.progressFn,null,4)}`);if(![1,2,"1","2"].includes(l.mergeType))throw new Error(`ranges-merge: [THROW_ID_02] opts.mergeType was customised to a wrong thing! It was given of a type: "${typeof l.mergeType}", equal to ${JSON.stringify(l.mergeType,null,4)}`);if(typeof l.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 l.joinRangesThatTouchEdges}", equal to ${JSON.stringify(l.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(t,null,4)} (type ${typeof t})`);else l=w({},ie);let n=e.filter(u=>Array.isArray(u)).map(u=>[...u]).filter(u=>u[2]!==void 0||u[0]!==u[1]),r,s,c;l.progressFn?r=H(n,{progressFn:u=>{c=Math.floor(u/5),c!==s&&(s=c,l.progressFn(c))}}):r=H(n);let a=r.length-1;for(let u=a;u>0;u--)l.progressFn&&(c=Math.floor((1-u/a)*78)+21,c!==s&&c>s&&(s=c,l.progressFn(c))),(r[u][0]<=r[u-1][0]||!l.joinRangesThatTouchEdges&&r[u][0]<r[u-1][1]||l.joinRangesThatTouchEdges&&r[u][0]<=r[u-1][1])&&(r[u-1][0]=Math.min(r[u][0],r[u-1][0]),r[u-1][1]=Math.max(r[u][1],r[u-1][1]),r[u][2]!==void 0&&(r[u-1][0]>=r[u][0]||r[u-1][1]<=r[u][1])&&r[u-1][2]!==null&&(r[u][2]===null&&r[u-1][2]!==null?r[u-1][2]=null:r[u-1][2]!=null?+l.mergeType==2&&r[u-1][0]===r[u][0]?r[u-1][2]=r[u][2]:r[u-1][2]+=r[u][2]:r[u-1][2]=r[u][2]),r.splice(u,1),u=r.length);return r.length?r:null}var ve=!0,B="Invariant failed";function le(e,t){if(!e){if(ve)throw new Error(B);var i=typeof t=="function"?t():t,l=i?"".concat(B,": ").concat(i):B;throw new Error(l)}}function M(e,t,i){let l=0,n=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(t&&!Array.isArray(t))throw new TypeError(`ranges-apply: [THROW_ID_03] second input argument must be an array (or null)! Currently it's: ${typeof t}, equal to: ${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: ${typeof i}, equal to: ${JSON.stringify(i,null,4)}`);if(!(t!=null&&t.filter(o=>o).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 s=r.length,c=0;r.filter(o=>o).forEach((o,$)=>{if(i&&(l=Math.floor(c/s*10),l!==n&&(n=l,i(l))),!Array.isArray(o))throw new TypeError(`ranges-apply: [THROW_ID_05] ranges array, second input arg., has ${$}th element not an array: ${JSON.stringify(o,null,4)}, which is ${typeof o}`);if(!Number.isInteger(o[0])){if(!Number.isInteger(+o[0])||+o[0]<0)throw new TypeError(`ranges-apply: [THROW_ID_06] ranges array, second input arg. has ${$}th element, array ${JSON.stringify(o,null,0)}. Its first element is not an integer, string index, but ${typeof o[0]}, equal to: ${JSON.stringify(o[0],null,4)}.`);r[$][0]=+r[$][0]}if(!Number.isInteger(o[1])){if(!Number.isInteger(+o[1])||+o[1]<0)throw new TypeError(`ranges-apply: [THROW_ID_07] ranges array, second input arg. has ${$}th element, array ${JSON.stringify(o,null,0)}. Its second element is not an integer, string index, but ${typeof o[1]}, equal to: ${JSON.stringify(o[1],null,4)}.`);r[$][1]=+r[$][1]}c+=1});let a=ue(r,{progressFn:o=>{i&&(l=10+Math.floor(o/10),l!==n&&(n=l,i(l)))}});le(a);let u=a.length;if(u>0){let o=e.slice(a[u-1][1]);e=a.reduce(($,m,g,f)=>{i&&(l=20+Math.floor(g/u*80),l!==n&&(n=l,i(l)));let y=g===0?0:f[g-1][1],O=f[g][0];return`${$}${e.slice(y,O)}${f[g][2]||""}`},""),e+=o}return e}var se="0.8.27";var je=se;function oe(e){return Array.isArray(e)?e.join("."):v(e)?e:String(e)}function De(e){return v(e)&&e.startsWith('"')&&e.endsWith('"')?`${JSON.stringify(e.slice(1,e.length-1),null,0)}`:JSON.stringify(e,null,0)}function E(e,t){if(e[t]!=="\\")return!0;let i=re(e,t,{mode:1},"\\");return!!(X(i)&&(t-i)%2!==0)}function ae({str:e,path:t,valToInsert:i,mode:l}){var U;let n=0;function r(S){e[n]}let s=e.length,c=[];r(`077 main(): MODE=${l}`);let a=["{","}","[","]",":",","],u=i;v(i)&&!i.startsWith('"')&&!i.startsWith("{")&&(u=`"${i}"`);let o=[],$=[],m=!1,g=!1,f=!1,y=null,O=null,b=null,N=null,j=null,P=null,h;function L(){return typeof h=="number"}let A=!1,d=[];function k(){y=null,O=null,b=null,N=null,j=null,P=null}k();let p=[];for(n=0;n<s;n++){if(r(` \x1B[36m===============================\x1B[39m \x1B[35m${`str[ ${n} ] = ${(U=e[n])!=null&&U.trim()?e[n]:JSON.stringify(e[n],null,0)}`}\x1B[39m \x1B[36m===============================\x1B[39m `),typeof h!="number"&&e[n-1]==="["&&(g=!0,e[n]!=="]"&&(m=!1)),typeof h!="number"&&e[n-1]==="{"&&(m=!0,e[n]!=="}"&&(g=!1)),typeof h!="number"&&e[n]==="{"&&E(e,n-1)&&!f&&(g&&(A||(r(`198 \x1B[33mcurrentPath\x1B[39m = ${JSON.stringify(p,null,4)}`),p[p.length-1]=p[p.length-1]+1,r(`207 \x1B[32mSET\x1B[39m ${`\x1B[33m${`currentPath[${p.length-1}]`}\x1B[39m`} = ${p[p.length-1]}`))),o.push(n),r(`215 \x1B[32mPUSH\x1B[39m \x1B[33mwithinObjectIndexes\x1B[39m = ${JSON.stringify(o,null,4)}`)),typeof h!="number"&&e[n]==="}"&&E(e,n-1)&&!f&&(o.pop(),r(`231 \x1B[31mPOP\x1B[39m \x1B[33mwithinObjectIndexes\x1B[39m = ${JSON.stringify(o,null,4)}`)),typeof h!="number"&&e[n]==="]"&&E(e,n-1)&&!f&&($.pop(),r(`248 \x1B[32mPOP\x1B[39m \x1B[33mwithinArrayIndexes\x1B[39m = ${JSON.stringify($,null,4)}`),p.pop(),r(`256 POP path, now = ${JSON.stringify(p,null,4)}`),r("258 \x1B[31mRESET\x1B[39m"),k(),A&&(A=!1,r(`267 \x1B[32mSET\x1B[39m \x1B[33mitsTheFirstElem\x1B[39m = ${A}`))),typeof h!="number"&&e[n]==="]"&&($.length?$.length&&(!o.length||$[$.length-1]>o[o.length-1])&&(g=!0):(g=!1,o.length&&!m&&(m=!0))),typeof h!="number"&&e[n]==="}"&&(o.length?(!$.length||o[o.length-1]>$[$.length-1])&&(m=!0):m=!1),g&&oe(t)===p.join(".")&&!f&&e[n].trim()&&(f=!0,r(`329 \x1B[32mSET\x1B[39m \x1B[33mreplaceThisValue\x1B[39m = ${f}`),b=n,r(`334 \x1B[32mSET\x1B[39m \x1B[33mvalueStartedAt\x1B[39m = ${b}`)),typeof h!="number"&&e[n]==="["&&E(e,n-1)&&!f&&($.push(n),A=!0,r(`348 \x1B[32mPUSH\x1B[39m \x1B[33mwithinArrayIndexes\x1B[39m = ${JSON.stringify($,null,4)}; \x1B[33mitsTheFirstElem\x1B[39m = ${A}`),p.push(0),r(`359 \x1B[32mPUSH\x1B[39m zero to path, now = ${JSON.stringify(p,null,0)}`)),g&&e[n]===","&&A&&!(typeof b=="number"&&N===null)&&(A=!1,r(`379 \x1B[32mSET\x1B[39m \x1B[33mitsTheFirstElem\x1B[39m = ${A}`)),!f&&b===null&&e[n].trim()&&!a.includes(e[n])&&(g||!g&&j!==null)&&(r("415 catching the start of a value clauses"),b=n,r(`418 \x1B[32mSET\x1B[39m \x1B[33mvalueStartedAt\x1B[39m = ${b}`),g&&(A?(A=!1,r(`426 \x1B[32mSET\x1B[39m \x1B[33mitsTheFirstElem\x1B[39m = ${A}`)):typeof p[p.length-1]=="number"&&(p[p.length-1]=p[p.length-1]+1,r(`432 \x1B[32mSET\x1B[39m ${`\x1B[33m${`currentPath[${p.length-1}]`}\x1B[39m`} = ${p[p.length-1]}`)))),!f&&typeof h!="number"&&(g||!g&&j!==null)&&typeof b=="number"&&b<n&&N===null&&(e[b]==='"'&&e[n]==='"'&&e[n-1]!=="\\"||e[b]!=='"'&&!e[n].trim()||["}",","].includes(e[n]))&&(r("451 catching the end of a value clauses"),P=e.slice(b,e[b]==='"'?n+1:n),r(`457 \x1B[32mSET\x1B[39m \x1B[33mkeyValue\x1B[39m = ${P}`),N=n,r(`461 \x1B[32mSET\x1B[39m \x1B[33mvalueEndedAt\x1B[39m = ${N}`)),!f&&!g&&e[n]==='"'&&e[n-1]!=="\\"&&j===null&&y===null&&O===null&&e[n+1]&&(y=n+1,r(`478 \x1B[32mSET\x1B[39m \x1B[33mkeyStartedAt\x1B[39m = ${y}`)),!f&&!g&&e[n]==='"'&&e[n-1]!=="\\"&&O===null&&typeof y=="number"&&b===null&&y<n&&(O=n+1,j=e.slice(y,n),r(`501 \x1B[32mSET\x1B[39m \x1B[33mkeyEndedAt\x1B[39m = ${O}; \x1B[33mkeyName\x1B[39m = ${j}`),p.push(j),r(`506 PUSH to path, now = ${JSON.stringify(p,null,4)}`),oe(t)===p.join(".")&&(f=!0,r(`515 \x1B[32mSET\x1B[39m \x1B[33mreplaceThisValue\x1B[39m = ${f}`))),!f&&typeof h!="number"&&e[n]===","&&m&&(p.pop(),r(`535 POP(), now \x1B[33mcurrentPath\x1B[39m = ${JSON.stringify(p,null,0)}`)),!f&&(typeof N=="number"&&n>=N||["}","]"].includes(e[D(e,n)])&&["}","]"].includes(e[n])||e[n]==="}"&&e[D(e,n)]==="{")&&e[n].trim()&&(r("552 \x1B[36m\u2588\u2588\x1B[39m catch the end of a key-value pair clauses"),e[n]===","&&!["}","]"].includes(e[I(e,n)])?(r("555 \x1B[31mRESET\x1B[39m"),k()):e[n]==="}"&&(r("558 closing curlie caught"),(N||e[D(e,n)]!=="{")&&(p.pop(),r(`569 POP(), now \x1B[33mcurrentPath\x1B[39m = ${JSON.stringify(p,null,0)}`)),r(`577 currently, currentlyWithinObject: ${m}`),r(`578 currently, currentlyWithinArray: ${g}`),$.length&&o.length&&$[$.length-1]>o[o.length-1]&&(m=!1,g=!0),r("616 \x1B[31mRESET\x1B[39m"),k())),!f&&e[n]==="{"&&v(j)&&b===null&&P===null&&(r("630 \x1B[31mRESET\x1B[39m"),k()),e[n].trim()&&f&&b===null&&typeof O=="number"&&n>O&&![":"].includes(e[n])&&(b=n,r(`644 \x1B[32mSET\x1B[39m \x1B[33mvalueStartedAt\x1B[39m = ${b}`)),e[n]==='"'&&E(e,n-1)&&(typeof y=="number"&&O===null||typeof b=="number"&&N===null)&&typeof h!="number"&&(h=n,r(`658 SET \x1B[33mwithinQuotesSince\x1B[39m = ${h}; withinQuotes = ${L()}`)),d.length&&e[n]===d[d.length-1]&&E(e,n-1)?(d.pop(),r(`677 \x1B[32mPOP\x1B[39m skipUntilTheFollowingIsMet = ${JSON.stringify(d,null,4)}`)):(typeof h!="number"||h===n)&&f&&!g&&typeof b=="number"&&(e[n]==="{"&&E(e,n-1)?(d.push("}"),r(`695 \x1B[32mPUSH\x1B[39m \x1B[33mskipUntilTheFollowingIsMet\x1B[39m = ${JSON.stringify(d,null,4)}`)):e[n]==="["&&E(e,n-1)?(d.push("]"),r(`705 \x1B[32mPUSH\x1B[39m \x1B[33mskipUntilTheFollowingIsMet\x1B[39m = ${JSON.stringify(d,null,4)}`)):e[n]==='"'&&E(e,n-1)&&(d.push('"'),r(`715 \x1B[32mPUSH\x1B[39m \x1B[33mskipUntilTheFollowingIsMet\x1B[39m = ${JSON.stringify(d,null,4)}`))),e[n]==='"'&&E(e,n-1)&&typeof h=="number"&&h!==n&&(h=void 0,r(`753 RESET \x1B[33mwithinQuotesSince\x1B[39m = ${h}; withinQuotes = ${L()}`)),f&&Array.isArray(d)&&!d.length&&typeof b=="number"&&n>b&&(r("766 within catch the end of the value when replaceThisValue is on clauses"),typeof h!="number"&&(e[b]==="["&&e[n]==="]"||e[b]==="{"&&e[n]==="}"||e[b]==='"'&&e[n]==='"'||!["[","{",'"'].includes(e[b])&&e[b].trim()&&(!e[n].trim()||a.includes(e[n])&&E(e,n-1))))){if(r(`780 INSIDE CATCH-END CLAUSES currently ${`\x1B[33m${`str[valueStartedAt=${b}]`}\x1B[39m`} = ${JSON.stringify(e[b],null,4)}`),l==="set"){r("789 \x1B[32mRETURN\x1B[39m");let S="";e.slice(b,n+(e[n].trim()?1:0)).includes(` `)&&e[n+(e[n].trim()?1:0)]!==` `&&(S=` `);let T=n+(e[n].trim()?1:0);return(g&&!['"',"[","{"].includes(e[b])&&e[I(e,T-1)]!=="]"||e[T-1]===","&&e[b-1]!=='"')&&(T-=1),g&&e[b-1]==='"'&&(b=b-1),`${e.slice(0,b)}${De(u)}${S}${e.slice(T)}`}if(l==="del"){r("848 \x1B[32mRETURN\x1B[39m"),r(`851 \x1B[33mkeyStartedAt\x1B[39m = ${JSON.stringify(y,null,4)}; val = ${(g?b:y)-1}`);let S=D(e,(g?b:y)-1);typeof S=="number"&&S++,r(`864 \x1B[32mSET\x1B[39m initial \x1B[33mstartingPoint\x1B[39m = ${S}`);let T=n+(e[n].trim()?1:0);typeof S=="number"&&e[S-1]===","&&["}","]"].includes(e[I(e,T-1)])&&(S-=1,r(`873 SET \x1B[33mstartingPoint\x1B[39m = ${S}`)),e[T]===","&&(T+=1,r(`879 SET \x1B[33mendingPoint\x1B[39m = ${T}`)),r(`883 \x1B[33mstartingPoint\x1B[39m = ${JSON.stringify(S,null,4)}; \x1B[33mendingPoint\x1B[39m = ${JSON.stringify(T,null,4)};`),c.push([S,T]),r(`896 \x1B[32mFINAL PUSH\x1B[39m \x1B[33mranges\x1B[39m = ${JSON.stringify(c,null,4)}`),r("902 then \x1B[31mBREAK\x1B[39m");break}}(m&&g||g&&typeof h!="number"&&e[n]==="]"&&E(e,n-1))&&(g=!1,m=!0),r(`${`\x1B[${h?32:31}m${`withinQuotesSince${typeof h=="number"?`=${h}`:""}`}\x1B[39m`}; ${`\x1B[${m?32:31}mcurrentlyWithinObject\x1B[39m`}; ${`\x1B[${g?32:31}mcurrentlyWithinArray\x1B[39m`}; ${`\x1B[${f?32:31}mreplaceThisValue\x1B[39m`}; ${`\x1B[${A?32:31}mitsTheFirstElem\x1B[39m`}; ${`\x1B[${d.length?32:31}m${`skipUntilTheFollowingIsMet${d?`: ${JSON.stringify(d,null,0)}`:""}`}\x1B[39m`}`),r(`current path: ${JSON.stringify(p.join("."),null,0)}`),r(`\x1B[33mkeyName\x1B[39m = ${j}; \x1B[33mkeyValue\x1B[39m = ${P}; \x1B[33mkeyStartedAt\x1B[39m = ${y}; \x1B[33mkeyEndedAt\x1B[39m = ${O}; \x1B[33mvalueStartedAt\x1B[39m = ${b}; \x1B[33mvalueEndedAt\x1B[39m = ${N}`),r(`\x1B[33mwithinArrayIndexes\x1B[39m = ${JSON.stringify($,null,0)}; \x1B[33mwithinObjectIndexes\x1B[39m = ${JSON.stringify(o,null,0)};`)}return r(` \x1B[36m=============================== FIN.\x1B[39m`),r(`947 RETURN applied ${JSON.stringify(M(e,c),null,4)}`),M(e,c)}function Ie(e,t,i){if(!v(e)||!e.length)throw new Error(`edit-package-json/set(): [THROW_ID_01] first input argument must be a non-empty string. It was given as ${JSON.stringify(e,null,4)} (type ${typeof e})`);return ae({str:e,path:t,valToInsert:i,mode:"set"})}function We(e,t){if(!v(e)||!e.length)throw new Error(`edit-package-json/del(): [THROW_ID_02] first input argument must be a non-empty string. It was given as ${JSON.stringify(e,null,4)} (type ${typeof e})`);return ae({str:e,path:t,mode:"del"})}return he(Re);})(); /** * @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-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/} */ /** * @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/} */