json-conflict-resolver
Version:
A rules-based JSON conflict resolver that parses Git conflict markers, reconstructs ours/theirs, and merges with deterministic strategies — beyond line-based merges.
2 lines (1 loc) • 1.75 kB
JavaScript
var d="\0",m="",w={isMatch:(r,e)=>{let n=a(r);return e.some(t=>p(n,a(t)))}},E=async r=>{if(r==="micromatch"){let e;try{e=await import("micromatch")}catch{throw new Error("micromatch is not installed. Please add it as a dependency if you want to use it.")}return{isMatch:(n,t)=>{try{return e.isMatch(a(n),t.map(a))}catch(s){throw new Error(`micromatch failed to run isMatch: ${s.message}`)}}}}if(r==="picomatch"){let e;try{e=(await import("picomatch")).default}catch{throw new Error("picomatch is not installed. Please add it as a dependency if you want to use it.")}return{isMatch:(n,t)=>{try{return e(t.map(a))(a(n))}catch(s){throw new Error(`picomatch failed to run isMatch: ${s.message}`)}}}}throw new Error(`Unknown matcher name: ${r}`)},a=r=>r.replace(/\\[./]|\./g,e=>e==="\\."?"\0":e==="\\/"?"":"/"),u=r=>{let e=r.startsWith("!"),n=e?r.slice(1):r,t=[],s="",c=!1;for(let i of n)c?(s+="\\"+i,c=!1):i==="\\"?c=!0:i==="/"?(t.push(s),s=""):s+=i;return c&&(s+="\\"),t.push(s),e&&(t.negated=!0),t},p=(r,e)=>{let n=r.split("/"),t=u(e),s=t.negated===!0,c=h(n,t);return s?!c:c},h=(r,e)=>{let n=0,t=0;for(;n<r.length&&t<e.length;){let s=e[t];if(s==="**"){if(t===e.length-1)return!0;for(let c=0;n+c<=r.length;c++)if(h(r.slice(n+c),e.slice(t+1)))return!0;return!1}if(!g(r[n],s))return!1;n++,t++}for(;t<e.length&&e[t]==="**";)t++;return n===r.length&&t===e.length},g=(r,e)=>{let n=!1,t=!1,s="",c="";for(let o=0;o<e.length;o++){let l=e[o];if(n){c+=l,n=!1;continue}if(l==="\\"){n=!0;continue}if(l==="*"){if(!t){t=!0,s=c,c="";continue}c+="*";continue}c+=l}if(n&&(c+="\\"),!t){let o=c.replace(/\\(.)/g,"$1");return r===o}let i=c.replace(/\\(.)/g,"$1"),f=s.replace(/\\(.)/g,"$1");return r.startsWith(f)&&r.endsWith(i)};export{d as a,m as b,w as c,E as d};