-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.min.mjs
1 lines (1 loc) · 3.79 KB
/
index.min.mjs
1
const r=Object.keys,e=r=>r.length,t=r=>typeof r,n=r=>"object"===t(r),o=Array.isArray,l=r=>null===r,f=r=>l(r)?"null":o(r)?"array":t(r),a=(r,e)=>f(r)!==f(e),s=(t,o)=>{if(t===o)return!0;if(a(t,o))return!1;if(!n(t))return!1;const l=r(t);if(e(l)!==e(r(o)))return!1;for(let r of l)if(!(r in o))return!1;for(let r of l)if(!s(t[r],o[r]))return!1;return!0},i=(r,e)=>r===e,u=r=>r,c=r=>(e,...t)=>e[r](...t),d=c("map"),b=r=>{throw new Error(`Invalid value type "${f(r)}": ${r}`)},y=e=>(({array:r=>d(r,y),boolean:u,null:u,number:u,object:e=>((e,t,n)=>{const o={};for(let l of r(e))o[l]=t.apply(n,[e[l],l,e]);return o})(e,y),string:u,undefined:u}[f(e)]||b)(e)),h=r=>(e,t)=>e===t||n(e)&&!a(e,t)&&r(e,t),g=r=>"string"===t(r),p=r=>{const e=new Map,t=new Map,n=n=>{if(!e.has(n)){let o=r(n);g(o)&&(t.has(o)||t.set(o,Symbol(o)),o=t.get(o)),e.set(n,o)}return e.get(n)};return(r,e)=>n(r)===n(e)},v=r=>[r],m=c("flat"),j=r=>0===r,$=r=>void 0===r,w=c("push"),M=c("filter"),_=r=>2===r,A=r=>3===r,x=r=>1===r,I=r=>4===r,O=(r,t)=>o(r)&&e(r)===t,S=r=>O(r,1),q=r=>{return j(r)||x(r)||_(r)||A(r)||I(r)||S(r)||o(t=r)&&e(t)%2==0;var t},E=r=>q(r)&&!I(r),N=r=>O(r,2),k=Number.isInteger,J=r=>k(r)&&r<0||g(r),z=r=>N(r)&&J(r[0])&&E(r[1]),B=r=>k(r)&&r>0,C=(r,e)=>N(r)&&r[1]===e&&O(r[0],2)&&B(r[0][0])&&(r=>B(r)||J(r))(r[0][1]),D=r=>C(r,9),F=r=>C(r,8),G=r=>N(r)&&B(r[0])&&I(r[1]),H=r=>N(r)&&B(r[0])&&E(r[1]),K=r=>o(r[0])?r[0][1]:r[0],L=c("sort"),P=r=>L(r,((r,e)=>K(e)-K(r))),Q=r=>[P(M(r,D)),P(M(r,F)),P(M(r,H)),P(M(r,G)),P(M(r,z))],R=(r,t)=>{const n=[];for(let e of r)if(!$(e[2]))for(let o of r)!$(o[1])&&$(o[2])&&t(o[1],e[2])&&(w(n,[[o[0],e[0]],8]),e.length=o.length=0);for(let e of r){const r=lr(e[1],e[2],t);j(r)||w(n,[e[0],r])}return e(n)>0?m(Q(n),2):0},T=(r,e,t)=>e<0||t<0?-1:r[e][t],U=Array.from,V=Math.max,W=Math.min,X=c("slice"),Y=(r,t,n)=>{const o=e(r),l=e(t),f=W(o,l);let a=0;for(;a<f&&n(r[a],t[a]);)a++;let s=0;for(;s<f&&n(r[o-1-s],t[l-1-s]);)s++;const i=((r,t,n)=>{const o=e(r)+1,l=e(t)+1,f=U({length:l},(()=>Array(o).fill(0)));for(let e=1;e<l;e++)for(let l=1;l<o;l++)f[e][l]=n(r[l-1],t[e-1])?f[e-1][l-1]+1:V(f[e][l-1],f[e-1][l]);return f})(X(r,a,o-s),X(t,a,l-s),n),u=[];let c=l-a-s,d=o-a-s;for(;d>0||c>0;){const e=T(i,c,d-1),n=T(i,c-1,d),o=d+a-1,l=c+a-1;e>n?(w(u,[+(o+1),r[o],void 0]),d--):n>e?(w(u,[-(l+1),void 0,t[l]]),c--):(T(i,c,d)===T(i,c-1,d-1)&&w(u,[+(o+1),r[o],t[l]]),d--,c--)}return R(u,n)},Z=(r,e,t)=>v(e),rr=c("indexOf"),er=e=>o(e)?U(e,((r,e)=>e)):L(r(e)),tr=c("includes"),nr=(e,t,n)=>{const o=er(e);return R(d(M((l=[...r(e),...r(t)],[...new Set(l)]),(r=>!n(e[r],t[r]))),(r=>[tr(o,r)?+(rr(o,r)+1):r,e[r],t[r]])),n);var l},or=(r,e,t)=>v(e),lr=(r,e,t)=>t(r,e)?0:!0===e?1:(r=>!1===r)(e)?2:l(e)?3:$(e)?4:a(r,e)?v(e):({array:Y,number:Z,object:nr,string:or}[f(r)]||b)(r,e,t),fr=c("join"),ar=JSON.stringify,sr=e=>(({array:r=>`[${fr(d(r,ar),",")}]`,boolean:ar,null:ar,number:ar,object:e=>`{${d(L(r(e)),(r=>`"${r}":${sr(e[r])}`))}}`,string:ar,undefined:()=>"undefined"}[f(e)]||b)(e)),ir=(r,e,{compute_object_hash:t=sr,are_objects_equal:n=p(t),are_equal:o=h(n)}={})=>lr(r,e,o),ur=Math.abs,cr=(r,e)=>g(r)?r:B(r)?e[r-1]:ur(r)-1,dr=c("splice"),br=(r,t)=>{const[n,l,f,a,s]=Q(((r,t,n=0)=>{const o=[];for(;n<e(r);)w(o,X(r,n,n+t)),n+=t;return o})(t,2)),i=er(r);for(let e of[...n,...l]){const t=e[0][0],n=e[0][1];F(e)&&w(a,[t,4]),w(B(n)?f:s,[n,v(r[cr(t,i)])])}P(s),P(a);const u=o(r)?[...r]:{...r};for(let e of f){const t=cr(e[0],i);u[t]=pr(r[t],e[1])}for(let r of a){const e=cr(r[0],i);o(u)?dr(u,e,1):delete u[e]}for(let r of s){const e=cr(r[0],i),t=pr(void 0,r[1]);o(u)?dr(u,e,0,t):u[e]=t}return u},yr=br,hr=br,gr=(r,e)=>{throw new Error(`Invalid delta for value of type "${f(r)}": ${e}`)},pr=(r,e)=>j(e)?r:!!x(e)||!_(e)&&(A(e)?null:I(e)?void 0:S(e)?e[0]:({array:yr,object:hr}[f(r)]||gr)(r,e));export{s as are_deep_equal,i as are_strict_equal,y as deep_clone,ir as diff,pr as patch,sr as stringify_json_value};