UNPKG

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) 2.46 kB
"use strict";var d=Object.create;var h=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var E=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty;var y=(t,e)=>{for(var r in e)h(t,r,{get:e[r],enumerable:!0})},f=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of w(e))!M.call(t,c)&&c!==r&&h(t,c,{get:()=>e[c],enumerable:!(n=m(e,c))||n.enumerable});return t};var u=(t,e,r)=>(r=t!=null?d(E(t)):{},f(e||!t||!t.__esModule?h(r,"default",{value:t,enumerable:!0}):r,t)),P=t=>f(h({},"__esModule",{value:!0}),t);var O={};y(O,{ESCAPED_DOT:()=>b,ESCAPED_SLASH:()=>x,basicMatcher:()=>A,loadMatcher:()=>D});module.exports=P(O);var b="\0",x="",A={isMatch:(t,e)=>{let r=a(t);return e.some(n=>C(r,a(n)))}},D=async t=>{if(t==="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:(r,n)=>{try{return e.isMatch(a(r),n.map(a))}catch(c){throw new Error(`micromatch failed to run isMatch: ${c.message}`)}}}}if(t==="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:(r,n)=>{try{return e(n.map(a))(a(r))}catch(c){throw new Error(`picomatch failed to run isMatch: ${c.message}`)}}}}throw new Error(`Unknown matcher name: ${t}`)},a=t=>t.replace(/\\[./]|\./g,e=>e==="\\."?"\0":e==="\\/"?"":"/"),$=t=>{let e=t.startsWith("!"),r=e?t.slice(1):t,n=[],c="",s=!1;for(let i of r)s?(c+="\\"+i,s=!1):i==="\\"?s=!0:i==="/"?(n.push(c),c=""):c+=i;return s&&(c+="\\"),n.push(c),e&&(n.negated=!0),n},C=(t,e)=>{let r=t.split("/"),n=$(e),c=n.negated===!0,s=p(r,n);return c?!s:s},p=(t,e)=>{let r=0,n=0;for(;r<t.length&&n<e.length;){let c=e[n];if(c==="**"){if(n===e.length-1)return!0;for(let s=0;r+s<=t.length;s++)if(p(t.slice(r+s),e.slice(n+1)))return!0;return!1}if(!_(t[r],c))return!1;r++,n++}for(;n<e.length&&e[n]==="**";)n++;return r===t.length&&n===e.length},_=(t,e)=>{let r=!1,n=!1,c="",s="";for(let o=0;o<e.length;o++){let l=e[o];if(r){s+=l,r=!1;continue}if(l==="\\"){r=!0;continue}if(l==="*"){if(!n){n=!0,c=s,s="";continue}s+="*";continue}s+=l}if(r&&(s+="\\"),!n){let o=s.replace(/\\(.)/g,"$1");return t===o}let i=s.replace(/\\(.)/g,"$1"),g=c.replace(/\\(.)/g,"$1");return t.startsWith(g)&&t.endsWith(i)};0&&(module.exports={ESCAPED_DOT,ESCAPED_SLASH,basicMatcher,loadMatcher});