@fluixi/utils 1.0.0-alpha.83 → 1.0.0-alpha.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2858 -1
- package/dist/index.mjs +2838 -1
- package/dist/lib/array/advanced.cjs +2227 -1
- package/dist/lib/array/advanced.mjs +2204 -1
- package/dist/lib/array/array.cjs +57 -1
- package/dist/lib/array/array.mjs +36 -1
- package/dist/lib/array/index.cjs +2344 -1
- package/dist/lib/array/index.mjs +2322 -1
- package/dist/lib/array/utils.cjs +103 -1
- package/dist/lib/array/utils.mjs +82 -1
- package/dist/lib/color/color.cjs +2190 -1
- package/dist/lib/color/color.mjs +2167 -1
- package/dist/lib/color/constants.cjs +380 -1
- package/dist/lib/color/constants.mjs +359 -1
- package/dist/lib/color/conversions.cjs +629 -1
- package/dist/lib/color/conversions.mjs +608 -1
- package/dist/lib/color/helpers.cjs +2534 -1
- package/dist/lib/color/helpers.mjs +2511 -1
- package/dist/lib/color/index.cjs +2641 -1
- package/dist/lib/color/index.mjs +2619 -1
- package/dist/lib/color/types.cjs +18 -1
- package/dist/lib/color/utils.cjs +962 -1
- package/dist/lib/color/utils.mjs +939 -1
- package/dist/lib/compare/comparators.cjs +171 -1
- package/dist/lib/compare/comparators.mjs +150 -1
- package/dist/lib/compare/index.cjs +172 -1
- package/dist/lib/compare/index.mjs +152 -1
- package/dist/lib/crypto/hash.cjs +83 -1
- package/dist/lib/crypto/hash.mjs +62 -1
- package/dist/lib/crypto/index.cjs +85 -1
- package/dist/lib/crypto/index.mjs +62 -1
- package/dist/lib/dom/events.cjs +40 -1
- package/dist/lib/dom/events.mjs +19 -1
- package/dist/lib/dom/index.cjs +78 -1
- package/dist/lib/dom/index.mjs +56 -1
- package/dist/lib/dom/utils.cjs +57 -1
- package/dist/lib/dom/utils.mjs +36 -1
- package/dist/lib/functions/functions.cjs +366 -1
- package/dist/lib/functions/functions.mjs +345 -1
- package/dist/lib/functions/index.cjs +369 -1
- package/dist/lib/functions/index.mjs +347 -1
- package/dist/lib/functions/types.cjs +18 -1
- package/dist/lib/helpers.cjs +78 -1
- package/dist/lib/helpers.mjs +59 -1
- package/dist/lib/index.cjs +2857 -1
- package/dist/lib/index.mjs +2836 -1
- package/dist/lib/maths/constants.cjs +70 -1
- package/dist/lib/maths/constants.mjs +50 -1
- package/dist/lib/maths/fn/advanced.cjs +231 -1
- package/dist/lib/maths/fn/advanced.mjs +208 -1
- package/dist/lib/maths/fn/basic.cjs +212 -1
- package/dist/lib/maths/fn/basic.mjs +191 -1
- package/dist/lib/maths/fn/complex.cjs +268 -1
- package/dist/lib/maths/fn/complex.mjs +247 -1
- package/dist/lib/maths/fn/index.cjs +877 -1
- package/dist/lib/maths/fn/index.mjs +855 -1
- package/dist/lib/maths/fn/trigo.cjs +179 -1
- package/dist/lib/maths/fn/trigo.mjs +156 -1
- package/dist/lib/maths/fn/vector.cjs +728 -1
- package/dist/lib/maths/fn/vector.mjs +707 -1
- package/dist/lib/maths/formatter.cjs +61 -1
- package/dist/lib/maths/formatter.mjs +40 -1
- package/dist/lib/maths/guards.cjs +164 -1
- package/dist/lib/maths/guards.mjs +144 -1
- package/dist/lib/maths/index.cjs +1152 -1
- package/dist/lib/maths/index.mjs +1130 -1
- package/dist/lib/maths/parser.cjs +75 -1
- package/dist/lib/maths/parser.mjs +54 -1
- package/dist/lib/maths/random.cjs +49 -1
- package/dist/lib/maths/random.mjs +28 -1
- package/dist/lib/maths/types/advanced.cjs +18 -1
- package/dist/lib/maths/types/basic.cjs +18 -1
- package/dist/lib/maths/types/index.cjs +19 -1
- package/dist/lib/maths/types/index.mjs +1 -0
- package/dist/lib/maths/types/negative.cjs +18 -1
- package/dist/lib/maths/types/operations.cjs +18 -1
- package/dist/lib/object/clone.cjs +88 -1
- package/dist/lib/object/clone.mjs +65 -1
- package/dist/lib/object/diff.cjs +573 -1
- package/dist/lib/object/diff.mjs +550 -1
- package/dist/lib/object/getter-setter.cjs +2351 -1
- package/dist/lib/object/getter-setter.mjs +2330 -1
- package/dist/lib/object/index.cjs +3956 -6
- package/dist/lib/object/index.mjs +3936 -6
- package/dist/lib/object/merge.cjs +1029 -1
- package/dist/lib/object/merge.mjs +1006 -1
- package/dist/lib/object/object.cjs +280 -1
- package/dist/lib/object/object.mjs +257 -1
- package/dist/lib/object/omit.cjs +2022 -1
- package/dist/lib/object/omit.mjs +1999 -1
- package/dist/lib/object/reconcile.cjs +126 -1
- package/dist/lib/object/reconcile.mjs +105 -1
- package/dist/lib/object/selector.cjs +303 -1
- package/dist/lib/object/selector.mjs +282 -1
- package/dist/lib/object/sort.cjs +209 -1
- package/dist/lib/object/sort.mjs +186 -1
- package/dist/lib/object/transform.cjs +2211 -1
- package/dist/lib/object/transform.mjs +2190 -1
- package/dist/lib/object/types.cjs +18 -1
- package/dist/lib/object/utils.cjs +326 -6
- package/dist/lib/object/utils.mjs +305 -6
- package/dist/lib/primitive/boolean/boolean.cjs +407 -1
- package/dist/lib/primitive/boolean/boolean.mjs +386 -1
- package/dist/lib/primitive/boolean/index.cjs +382 -1
- package/dist/lib/primitive/boolean/index.mjs +359 -1
- package/dist/lib/primitive/boolean/types.cjs +18 -1
- package/dist/lib/primitive/date/date.cjs +1126 -1
- package/dist/lib/primitive/date/date.mjs +1105 -1
- package/dist/lib/primitive/date/index.cjs +1128 -1
- package/dist/lib/primitive/date/index.mjs +1105 -1
- package/dist/lib/primitive/date/types.cjs +18 -1
- package/dist/lib/primitive/index.cjs +2338 -5
- package/dist/lib/primitive/index.mjs +2316 -5
- package/dist/lib/primitive/string/index.cjs +875 -5
- package/dist/lib/primitive/string/index.mjs +852 -5
- package/dist/lib/primitive/string/parser-2.cjs +543 -8
- package/dist/lib/primitive/string/parser-2.mjs +522 -8
- package/dist/lib/primitive/string/parser.cjs +236 -3
- package/dist/lib/primitive/string/parser.mjs +215 -3
- package/dist/lib/primitive/string/string.cjs +926 -5
- package/dist/lib/primitive/string/string.mjs +903 -5
- package/dist/lib/primitive/string/types.cjs +18 -1
- package/dist/lib/primitive/types.cjs +18 -1
- package/dist/lib/url/index.cjs +327 -1
- package/dist/lib/url/index.mjs +304 -1
- package/dist/lib/url/parser.cjs +325 -1
- package/dist/lib/url/parser.mjs +304 -1
- package/dist/lib/url/types.cjs +18 -1
- package/package.json +5 -5
package/dist/lib/object/omit.cjs
CHANGED
|
@@ -1 +1,2022 @@
|
|
|
1
|
-
"use strict";var U=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var H=(e,i)=>{for(var s in i)U(e,s,{get:i[s],enumerable:!0})},X=(e,i,s,r)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of Z(i))!G.call(e,n)&&n!==s&&U(e,n,{get:()=>i[n],enumerable:!(r=Q(i,n))||r.enumerable});return e};var Y=e=>X(U({},"__esModule",{value:!0}),e);var ce={};H(ce,{createOmitter:()=>ae,deepOmit:()=>D,deepOmitBy:()=>C,omit:()=>ie,omitBy:()=>z,omitNil:()=>oe,omitPath:()=>ye,pick:()=>le,pickBy:()=>fe,pickPath:()=>ue});module.exports=Y(ce);var m=e=>e==null||Array.isArray(e)||typeof e=="function"||e instanceof Date||e instanceof RegExp||e instanceof Map||e instanceof Set||e instanceof Error?!1:typeof e=="object";function k(e){if(typeof e!="object"||e===null)return!1;let i=Object.getPrototypeOf(e);return i===Object.prototype||i===null}var w=(e,i,s,r)=>{if(s>r)return;if(i.length===0)return e;let n=i[0],f=i.slice(1);if(n.type==="descendant"){let o=w(e,f,s+1,r);if(o!==void 0)return o;if(e&&typeof e=="object")if(Array.isArray(e)){let t=[];for(let l=0;l<e.length;l++){let a=w(e[l],i,s+1,r);a!==void 0&&(t[l]=a)}return t.length>0?t:void 0}else{let t={};for(let l in e)if(e.hasOwnProperty(l)){let a=w(e[l],i,s+1,r);a!==void 0&&(t[l]=a)}return Object.keys(t).length>0?t:void 0}return}switch(n.type){case"property":if(m(e)&&n.value&&String(n.value)in e){let o=e[String(n.value)],t=w(o,f,s+1,r);if(t!==void 0)return{[String(n.value)]:t}}break;case"index":if(Array.isArray(e)){let o=n.value;if(o>=0&&o<e.length){let t=w(e[o],f,s+1,r);if(t!==void 0){let l=new Array(e.length).filter(a=>a!==void 0);return l[o]=t,l}}}else if(e&&typeof e=="object"){let o=String(n.value);if(o in e){let t=w(e[o],f,s+1,r);if(t!==void 0)return{[o]:t}}}break;case"wildcard":if(e&&typeof e=="object")if(Array.isArray(e)){let o=[],t=!1;for(let l=0;l<e.length;l++){let a=w(e[l],f,s+1,r);a!==void 0&&(o[l]=a,t=!0)}return t?o:void 0}else{let o={},t=!1;for(let l in e)if(e.hasOwnProperty(l)){let a=w(e[l],f,s+1,r);a!==void 0&&(o[l]=a,t=!0)}return t?o:void 0}break;case"slice":if(Array.isArray(e)){let[o,t]=n.value,l=Math.max(0,o),a=Math.min(e.length,t===1/0?e.length:t),y=[],g=!1;for(let A=l;A<a;A++){let p=w(e[A],f,s+1,r);p!==void 0&&(y[A]=p,g=!0)}return g?y:void 0}break;case"union":if(Array.isArray(e)){let o=n.value,t=[],l=!1;for(let a of o)if(a>=0&&a<e.length){let y=w(e[a],f,s+1,r);y!==void 0&&(t[a]=y,l=!0)}return l?t:void 0}break;case"filter":if(Array.isArray(e)){let o=n.value,t=[],l=!1;for(let a=0;a<e.length;a++)if(o(e[a])){let y=w(e[a],f,s+1,r);y!==void 0&&(t[a]=y,l=!0)}return l?t:void 0}break}};var O=(e,i)=>{if(e==null||typeof e!="object")return e;if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return new RegExp(e.source,e.flags);if(e instanceof Map){let s=new Map;return e.forEach((r,n)=>{(!i||!i.some(f=>f.toString()===n.toString()))&&s.set(n,O(r))}),s}if(e instanceof Set){let s=new Set;return e.forEach(r=>{s.add(O(r))}),s}if(Array.isArray(e))return Array.from(e).map(s=>O(s));if(m(e)){let s={};for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(!i||!i.some(f=>f.toString()===n.toString()))&&(s[n]=O(e[n]));let r=Object.getOwnPropertySymbols(e);for(let n of r)(!i||!i.some(f=>f.toString()===n.toString()))&&(s[n]=O(e[n]));return s}return e};var N=(e,i)=>e===i,V=(e,i)=>{if(e.length!==i.length)return!1;for(let s=0;s<e.length;s++)if(Array.isArray(e[s])&&Array.isArray(i[s])){if(!V(e[s],i[s]))return!1}else if(m(e[s])&&m(i[s])){if(!B(e[s],i[s]))return!1}else if(e[s]!==i[s])return!1;return!0},B=(e,i)=>{let s=Object.keys(e),r=Object.keys(i);if(s.length!==r.length)return!1;for(let n of s){if(!(n in i))return!1;let f=e[n],o=i[n];if(Array.isArray(f)&&Array.isArray(o)){if(!V(f,o))return!1}else if(m(f)&&m(o)){if(!B(f,o))return!1}else if(f!==o)return!1}return!0},_=(e,i,s={})=>{let{includeDeleted:r=!1,includeAdded:n=!0,deepArrayComparison:f=!0,equalityFn:o=N,preserveStructure:t=!1}=s;if(e==null&&i==null)return{};if(e==null)return n?{...i}:{};if(i==null){if(r){let y={};for(let g in e)y[g]=void 0;return y}return{}}if(!m(e)||!m(i))return o(e,i)?{}:i;let l={},a=new Set;for(let y in i){a.add(y);let g=e[y],A=i[y];if(!(y in e)){n&&(l[y]=A);continue}if(Array.isArray(g)&&Array.isArray(A)){f?V(g,A)?t&&(l[y]=void 0):l[y]=A:g!==A?l[y]=A:t&&(l[y]=void 0);continue}if(m(g)&&m(A)){let p=_(g,A,s);Object.keys(p).length>0?l[y]=p:t&&(l[y]=void 0);continue}o(g,A)?t&&(l[y]=void 0):l[y]=A}if(r)for(let y in e)a.has(y)||(l[y]=void 0);return l},j=(e,i,s={})=>{let r=[],n=[],f=[],o={},{includeDeleted:t=!1,includeAdded:l=!0,deepArrayComparison:a=!0,equalityFn:y=N}=s;if(Array.isArray(e)&&Array.isArray(i)){let p=Math.max(e.length,i.length),d=[],c=!1;for(let u=0;u<p;u++){let T=`[${u}]`;if(u>=e.length)r.push(T),d[u]=i[u],c=!0;else if(u>=i.length)n.push(T),c=!0;else{let x=e[u],h=i[u];m(x)&&m(h)||Array.isArray(x)&&Array.isArray(h)?j(x,h,s).hasChanges?(f.push(T),d[u]=h,c=!0):d[u]=x:y(x,h)?d[u]=x:(f.push(T),d[u]=h,c=!0)}}return{changes:c?d:{},added:r,deleted:n,modified:f,hasChanges:c||n.length>0}}let g=(p,d,c="")=>{let u={added:[],deleted:[],modified:[]};if(Array.isArray(p)&&Array.isArray(d)){let T=Math.max(p.length,d.length);for(let x=0;x<T;x++){let h=c?`${c}[${x}]`:`[${x}]`;if(x>=p.length)u.added.push(h);else if(x>=d.length)u.deleted.push(h);else{let S=p[x],b=d[x];if(m(S)&&m(b)){let K=g(S,b,h);u.added.push(...K.added),u.deleted.push(...K.deleted),u.modified.push(...K.modified)}else if(Array.isArray(S)&&Array.isArray(b)){let K=g(S,b,h);u.added.push(...K.added),u.deleted.push(...K.deleted),u.modified.push(...K.modified)}else S!==b&&u.modified.push(h)}}return u}if(m(p)&&m(d)){let T=new Set([...Object.keys(p||{}),...Object.keys(d||{})]);for(let x of T){let h=p?.[x],S=d?.[x],b=c?`${c}.${x}`:x;if(!(x in(p||{})))u.added.push(b);else if(!(x in(d||{})))u.deleted.push(b);else if(Array.isArray(h)&&Array.isArray(S)){if(!V(h,S)){let K=g(h,S,b);u.added.push(...K.added),u.deleted.push(...K.deleted),u.modified.push(...K.modified)}}else if(m(h)&&m(S)){let K=g(h,S,b);u.added.push(...K.added),u.deleted.push(...K.deleted),u.modified.push(...K.modified)}else h!==S&&u.modified.push(b)}}return u};if(e==null&&i==null)return{changes:{},added:r,deleted:n,modified:f,hasChanges:!1};if(e==null){if(l&&i)for(let p in i)r.push(p),o[p]=i[p];return{changes:o,added:r,deleted:n,modified:f,hasChanges:r.length>0}}if(i==null){if(t)for(let p in e)n.push(p),o[p]=void 0;return{changes:o,added:r,deleted:n,modified:f,hasChanges:n.length>0}}let A=new Set;for(let p in i){A.add(p);let d=e[p],c=i[p];if(!(p in e)){l&&(r.push(p),o[p]=c);continue}let u=!1;if(Array.isArray(d)&&Array.isArray(c)){if(u=a?!V(d,c):d!==c,u){let T=g(d,c,p);r.push(...T.added),n.push(...T.deleted),f.push(...T.modified),o[p]=c}}else if(m(d)&&m(c)){let T=_(d,c,s);if(u=Object.keys(T).length>0,u){let x=g(d,c,p);r.push(...x.added),n.push(...x.deleted),f.push(...x.modified),o[p]=T}}else u=!y(d,c),u&&(f.push(p),o[p]=c)}for(let p in e)A.has(p)||(n.push(p),o[p]=void 0);return{changes:o,added:r,deleted:n,modified:f,hasChanges:r.length>0||n.length>0||f.length>0}};function ee(e){return!!(e&&(e.diff||e.changes)&&(e.modified||e.deleted||e.hasChanges))}var F=(e,i,s)=>{if(!ee(i)){let u=i,T=s||!1;if(Array.isArray(e)&&Array.isArray(u)){let h=T?e:[...e];u.length<h.length&&(h.length=u.length);for(let S=0;S<u.length;S++){let b=u[S];b!==void 0&&(m(h[S])&&m(b)||Array.isArray(h[S])&&Array.isArray(b)?h[S]=F(h[S],b,T):h[S]=b)}return h}if(!m(e))return u;if(!m(u))return e;let x=T?e:{...e};for(let h in u){let S=u[h];S===void 0?delete x[h]:Array.isArray(x[h])&&Array.isArray(S)||m(x[h])&&m(S)?x[h]=F(x[h],S,T):x[h]=S}return x}let{diff:r,added:n=[],deleted:f=[],modified:o=[],changes:t,keepRef:l}=i,a=s!==void 0?s:l,y=t||r;if(!y)return e;let g=new Set(n),A=new Set(f),p=new Set(o),d=u=>{if(n.length===0&&f.length===0&&o.length===0)return!0;let T=u.split(/[.\[\]]+/).filter(Boolean);for(let x=0;x<=T.length;x++){let h=T.slice(0,x).join("."),S=T.slice(0,x).map((b,K)=>/^\d+$/.test(b)?`[${b}]`:K>0?`.${b}`:b).join("");if(g.has(h)||g.has(S)||A.has(h)||A.has(S)||p.has(h)||p.has(S))return!0}return!1};if(Array.isArray(e)&&Array.isArray(y)){let u=a?e:[...e];u.length=y.length;for(let T=0;T<y.length;T++){let x=`[${T}]`,h=y[T];h!==void 0&&d(x)&&(m(u[T])&&m(h)||Array.isArray(u[T])&&Array.isArray(h)?u[T]=F(u[T],h,a):u[T]=h)}return u}if(!m(e))return y;if(!m(y))return e;let c=a?e:{...e};for(let u of f)u.includes(".")||u.includes("[")||d(u)&&delete c[u];for(let u in y){let T=y[u];d(u)&&(T===void 0?delete c[u]:Array.isArray(c[u])&&Array.isArray(T)||m(c[u])&&m(T)?c[u]=F(c[u],T,a):c[u]=T)}return c};var P=(e,i={})=>{let{type:s="auto",throwOnError:r=!1}=i;if(!e||typeof e!="string")return[];let n=[],f="",o=!1,t=!1,l="",a="",y=0,A=s==="auto"?(d=>d.includes("..")?"descendant":d.includes("[?(")?"filter":d.includes("[:")||d.includes("[0:")?"slice":d.includes("[,")||d.includes("[0,1]")?"union":d.includes("[*]")||d.includes(".*.")?"wildcard":d.includes("[]")?"array-wildcard":d.includes("[")&&d.includes("]")?"bracket":"dot")(e):s,p=d=>{let c=d.trim();if(c==="*"||c==="")return{type:"wildcard",value:c===""?"[]":"*",raw:c===""?"[]":d};if(c==="[]")return{type:"wildcard",value:"[]",raw:d};if(/^-?\d+$/.test(c))return{type:"index",value:parseInt(c,10),raw:d};if(c.includes(":")){let u=c.split(":").map(h=>h.trim()),T=u[0]===""?0:parseInt(u[0],10),x=u[1]===""?1/0:parseInt(u[1],10);if(isNaN(T)||isNaN(x)){if(r)throw new Error(`Invalid slice notation: ${d}`);return{type:"wildcard",value:"*",raw:d}}return{type:"slice",value:[T,x],raw:d}}if(c.includes(",")){let u=c.split(",").map(T=>{let x=parseInt(T.trim(),10);return isNaN(x)?-1:x}).filter(T=>T>=0);if(u.length===0){if(r)throw new Error(`Invalid union notation: ${d}`);return{type:"wildcard",value:"*",raw:d}}return{type:"union",value:u,raw:d}}if(c.startsWith("?(")&&c.endsWith(")")){let u=c.slice(2,-1);try{return{type:"filter",value:te(u),raw:d}}catch(T){if(r)throw T;return{type:"wildcard",value:"*",raw:d}}}return c.startsWith('"')&&c.endsWith('"')||c.startsWith("'")&&c.endsWith("'")?{type:"property",value:c.slice(1,-1),raw:d}:{type:"property",value:c,raw:d}};for(let d=0;d<e.length;d++){let c=e[d],u=e[d+1];if((c==='"'||c==="'")&&!t){t=!0,l=c;continue}else if(c===l&&t){t=!1,l="",c==='"'||c==="'"||(o?a+=c:f+=c);continue}if(t){o?a+=c:f+=c;continue}if(c==="["&&!o){f&&(n.push({type:"property",value:f,raw:f}),f=""),o=!0,a="";continue}if(c==="]"&&o&&!t){o=!1;let x=p(a);n.push(x);continue}let T=n.length>0?n[n.length-1]:null;if(c==="."&&!o&&!t){if(u==="."){let x=e.split("..")[0];n.push({type:"property",value:x,raw:x}),n.push({type:"descendant",value:"..",raw:".."}),d++}else f&&(f==="*"?n.push({type:"wildcard",value:f,raw:f}):n.push({type:"property",value:f,raw:f}),f="");continue}if(o)a+=c;else if(T&&T.type!=="descendant")f+=c;else{let x=e.split(T?.raw)[1];x!==void 0?f=x:f+=c}}return f&&n.push({type:"property",value:f,raw:f}),n.map(d=>{if(d.type==="property"&&typeof d.value=="string"&&/^-?\d+$/.test(d.value)){let c=parseInt(d.value,10);if(!isNaN(c))return{...d,type:"index",value:c}}return d})},te=e=>{let i=e.replace(/@\.([a-zA-Z_$][\w$]*)/g,(s,r)=>`item.${r}`).replace(/@/g,"item");try{return new Function("item",`return ${i}`)}catch{throw new Error(`Invalid filter expression: ${e}`)}},M=e=>{let i=[];for(let s=0;s<e.length;s++){let r=e[s],n=s>0?e[s-1]:null;switch(r.type){case"property":/[\.\[\]\s]/.test(String(r.value))?i.push(`["${r.value}"]`):(n&&n.type!=="descendant"&&i.push("."),i.push(String(r.value)));break;case"index":i.push(`[${r.value}]`);break;case"wildcard":r.value==="[]"?i.push("[]"):i.push("[*]");break;case"slice":let[o,t]=r.value;i.push(`[${o}:${t===1/0?"":t}]`);break;case"union":let l=r.value;i.push(`[${l.join(",")}]`);break;case"filter":i.push(`[?(${r.raw?.slice(2,-1)||""})]`);break;case"descendant":i.push("..");break}}return i.join("").replace(/\.\[/g,"[")};function ne(e,i){for(let s in i){let r=e[s],n=i[s],f=j(r,n);Array.isArray(r)&&Array.isArray(n)?(r.length=0,r.push(...n)):typeof r=="object"&&typeof n=="object"&&r&&n&&f.hasChanges?F(r,n):e[s]=n}}function $(e,...i){if(i.length===0)return O(e);let s={preserveTarget:!1,strict:!1},r=i,n=i[i.length-1];n&&typeof n=="object"&&("preserveTarget"in n||"strict"in n)&&(s={...s,...n},r=i.slice(0,-1));let f=s.preserveTarget?e:O(e),o=Array.isArray(f);for(let t of r)if(t&&Array.isArray(t)!==o)throw new Error("Cannot mix arrays and objects in deepMergeWithOptions");for(let t of r)if(t!=null)if(o){let l=f,a=t;if(s.strict)for(let y=0;y<l.length&&y<a.length;y++)k(l[y])&&k(a[y])?l[y]=$(l[y],a[y],s):typeof l[y]==typeof a[y]&&(l[y]=O(a[y]));else ne(l,a)}else{if(!k(t))continue;let l=f,a=t;for(let g in a){if(!Object.prototype.hasOwnProperty.call(a,g))continue;let A=a[g];if(s.strict&&!(g in l))continue;let p=l[g];p===void 0?l[g]=O(A):Array.isArray(A)&&Array.isArray(p)?s.strict?l[g]=$(p,A,s):l[g]=[...p,...A.map(d=>O(d))]:k(A)&&k(p)?l[g]=$(p,A,s):l[g]=O(A)}let y=Object.getOwnPropertySymbols(a);for(let g of y){if(s.strict&&!(g in l))continue;let A=a[g],p=l[g];p===void 0?l[g]=O(A):Array.isArray(A)&&Array.isArray(p)?s.strict?l[g]=$(p,A,s):l[g]=[...p,...A.map(d=>O(d))]:k(A)&&k(p)?l[g]=$(p,A,s):l[g]=O(A)}}return f}function W(e,...i){return $(e,...i,{preserveTarget:!0})}var q=(e,i,s)=>{let r=P(i),n=e;for(let f=0;f<r.length;f++){let o=r[f],t=f===r.length-1;switch(o.type){case"property":if(t)n[String(o.value)]=s;else{if(!n[String(o.value)]){let a=r[f+1];n[String(o.value)]=a.type==="index"||a.type==="slice"||a.type==="union"||a.type==="wildcard"?[]:{}}n=n[String(o.value)]}break;case"index":Array.isArray(n)||(n=[]);let l=o.value;if(t){if(l>=n.length)for(let a=n.length;a<=l;a++)n.push(void 0);n[l]=s}else{if(!n[l]){let a=r[f+1];n[l]=a.type==="index"||a.type==="slice"||a.type==="union"||a.type==="wildcard"?[]:{}}n=n[l]}break;case"wildcard":if(Array.isArray(n))if(t)for(let a=0;a<n.length;a++)n[a]=s;else{let a=r[f+1];for(let y=0;y<n.length;y++)n[y]||(n[y]=a.type==="index"||a.type==="slice"||a.type==="union"||a.type==="wildcard"?[]:{});n.length>0&&(n=n[0])}break}}};function I(e,i,s={}){let{preserveStructure:r,multiple:n,throwOnError:f=!1,defaultValue:o,maxDepth:t=20}=s;if(!e||typeof e!="object")return o;if(!i)return e;if(Array.isArray(i))if(r){let y={};for(let g of i){let A=I(e,g,{...s,preserveStructure:!1});A!==void 0&&q(y,g,A)}return y}else return i.map(y=>I(e,y,{...s,preserveStructure:!1}));let l=P(i,{...s,throwOnError:f});if(l.length===0)return e;if(typeof r>"u"||r===!1){let y=re(e,i);return n===!1&&Array.isArray(y)?y[0]:y===void 0&&o!==void 0?o:y}let a=w(e,l,0,t);return a===void 0&&o!==void 0?o:a}function re(e,i,s={}){let{createMissing:r=!1,add:n=!1,debug:f=!1}=s,o=P(i),t=e,l=!1,a="",y=i;if(typeof t=="object"&&!Array.isArray(t)&&y.length>0&&t[y])return t=t[y],t;for(let g=0;g<o.length;g++){let A=o[g],p=o.length>1?g===o.length-1:!1;if(t===null&&!r)return;let d=o[g+1];switch(A.type){case"property":if(t&&typeof t=="object")if(Array.isArray(t)){if(typeof A.value=="number"){let c=A.value;if(r&&c>=t.length)for(let u=t.length;u<=c;u++)t.push(void 0);if(r&&(t[c]===null||t[c]===void 0)&&(!p||l)&&(d?t[c]=d.type==="index"||d.type==="slice"||d.type==="union"||d.type==="wildcard"?[]:{}:t[c]=null,l=!1),t=t[c],d){l=!0;continue}}else n?t.push({[String(A.value)]:null}):t=t.map(c=>c[String(A.value)]);if(d)continue;return J(t)}else{if(t[a]&&a.split(".").length>=2){t=t[a];continue}if(r&&(t[String(A.value)]===null||t[String(A.value)]===void 0)&&(!p||l)&&(d?t[String(A.value)]=d.type==="index"||d.type==="slice"||d.type==="union"||d.type==="wildcard"?[]:{}:t[String(A.value)]=null,l=!1,t=t[String(A.value)],d)){l=!0;continue}if(t?(!t[String(A.value)]&&r&&(t[String(A.value)]=null),t=t[String(A.value)]):t={[String(A.value)]:null},d)continue}else if(r)t={},t[String(A.value)]=d.type==="index"||d.type==="slice"||d.type==="union"||d.type==="wildcard"||s.type==="array"?[]:{},t=t[String(A.value)];else return;break;case"index":case"wildcard":if(Array.isArray(t)){if(A.type==="index"){let c=A.value;if(c<0){t=t[t.length-Math.abs(c)];continue}if(r&&(c>=t.length||t[c]==null||t[c]==null)&&!p){for(let u=t.length;u<=c;u++)t.push(void 0);d&&(t[c]=d.type==="index"||d.type==="slice"||d.type==="union"||d.type==="wildcard"?[]:{})}t=t[c]}else if(!p)continue}else if(r){let c=o[g+1];t=[];let u=A.value;for(let T=0;T<=u;T++)t.push(void 0);t[u]=c.type==="index"||c.type==="slice"||c.type==="union"||c.type==="wildcard"||s.type==="array"?[]:{},t=t[u]}else{if(A.type==="index"&&typeof t=="object"&&t&&t[String(A.value)]!==void 0){t=t[String(A.value)];continue}if(typeof t=="object"){t=Object.values(t);continue}return}break;default:return}}return J(t)}function J(e){return Array.isArray(e)?e.filter(i=>typeof i<"u"):e}var R=(e,i,s={})=>{let{throwOnError:r=!1}=s;if(Array.isArray(i))return i.map(t=>R(e,t,s));let n=P(i,{throwOnError:r});if(n.length===0)return!1;let f=n[n.length-1];if(n.some(t=>t.type==="wildcard"||t.type==="slice"||t.type==="union")){let t=L(e,i,s),l=!1;for(let a of t)se(e,a)&&(l=!0);return l}let o=e;for(let t=0;t<n.length-1;t++){let l=n[t];if(o==null)return!1;switch(l.type){case"property":o=o[String(l.value)];break;case"index":if(!Array.isArray(o))return!1;let a=l.value;if(a<0||a>=o.length)return!1;o=o[a];break;default:return!1}}if(o==null)return!1;switch(f.type){case"property":if(String(f.value)in o)return delete o[String(f.value)],!0;break;case"index":if(!Array.isArray(o))return!1;let t=f.value;if(t>=0&&t<o.length)return o.splice(t,1),!0;break}return!1},se=(e,i)=>{let s=P(i);if(s.length===0)return!1;let r=s[s.length-1],n=e;for(let f=0;f<s.length-1;f++){let o=s[f];if(n==null)return!1;switch(o.type){case"property":n=n[String(o.value)];break;case"index":if(!Array.isArray(n))return!1;let t=o.value;if(t<0||t>=n.length)return!1;n=n[t];break;default:return!1}}if(n==null)return!1;switch(r.type){case"property":if(String(r.value)in n)return delete n[String(r.value)],!0;break;case"index":if(!Array.isArray(n))return!1;let f=r.value;if(f>=0&&f<n.length)return n.splice(f,1),!0;break}return!1},L=(e,i,s={})=>{let{format:r="selector",maxDepth:n=20}=s;if(i&&Array.isArray(i)){let t=[];for(let l of i){let a=L(e,l,s);t.push(...a)}return t}if(i){let t=P(i,s);return v(e,t,0,n).map(a=>r==="selector"?a.path:a.stringPath)}let f=[],o=(t,l=[],a=[],y=0)=>{if(!(y>n)){if(l.length>0){let g=M(l);f.push({path:g,stringPath:a.join(".")})}if(t&&typeof t=="object")if(Array.isArray(t))for(let g=0;g<t.length;g++)o(t[g],[...l,{type:"index",value:g,raw:`[${g}]`}],[...a,`[${g}]`],y+1);else for(let g in t)t.hasOwnProperty(g)&&o(t[g],[...l,{type:"property",value:g,raw:g}],[...a,g],y+1)}};return o(e),f.map(t=>r==="selector"?t.path:t.stringPath)};function v(e,i,s,r,n=[],f=[]){if(s>r)return[];if(i.length===0)return[{value:e,path:M(n),stringPath:f.join(".")}];let o=i[0],t=i.slice(1),l=[];if(o.type==="descendant"){if(l.push(...v(e,t,s+1,r,n,f)),e&&typeof e=="object")if(Array.isArray(e))for(let a=0;a<e.length;a++)l.push(...v(e[a],i,s+1,r,[...n,{type:"index",value:a,raw:`[${a}]`}],[...f,`[${a}]`]));else for(let a in e)e.hasOwnProperty(a)&&l.push(...v(e[a],i,s+1,r,[...n,{type:"property",value:a,raw:a}],[...f,a]));return l}switch(o.type){case"property":if(e&&typeof e=="object"&&String(o.value)in e){let a=e[String(o.value)];l.push(...v(a,t,s+1,r,[...n,o],[...f,String(o.value)]))}break;case"index":if(Array.isArray(e)){let a=o.value;a>=0&&a<e.length&&l.push(...v(e[a],t,s+1,r,[...n,o],[...f,`[${a}]`]))}else if(e&&typeof e=="object"){let a=String(o.value);a in e&&l.push(...v(e[a],t,s+1,r,[...n,{...o,type:"property"}],[...f,a]))}break;case"wildcard":if(e&&typeof e=="object")if(Array.isArray(e))for(let a=0;a<e.length;a++)l.push(...v(e[a],t,s+1,r,[...n,{type:"index",value:a,raw:`[${a}]`}],[...f,`[${a}]`]));else for(let a in e)e.hasOwnProperty(a)&&l.push(...v(e[a],t,s+1,r,[...n,{type:"property",value:a,raw:a}],[...f,a]));break;case"slice":if(Array.isArray(e)){let[a,y]=o.value,g=Math.max(0,a),A=Math.min(e.length,y===1/0?e.length:y);for(let p=g;p<A;p++)l.push(...v(e[p],t,s+1,r,[...n,{type:"index",value:p,raw:`[${p}]`}],[...f,`[${p}]`]))}break;case"union":if(Array.isArray(e)){let a=o.value;for(let y of a)y>=0&&y<e.length&&l.push(...v(e[y],t,s+1,r,[...n,{type:"index",value:y,raw:`[${y}]`}],[...f,`[${y}]`]))}break;case"filter":if(Array.isArray(e)){let a=o.value;for(let y=0;y<e.length;y++)a(e[y])&&l.push(...v(e[y],t,s+1,r,[...n,{type:"index",value:y,raw:`[${y}]`}],[...f,`[${y}]`]))}break}return l}function ie(e,i){if(!m(e))return{};let s={...e};for(let r of i)delete s[r];return s}function D(e,i){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(r=>D(r,i));let s={};for(let[r,n]of Object.entries(e))i.includes(r)||(s[r]=D(n,i));return s}function ae(e){return i=>{if(!m(i))return{};let s={...i};for(let r of e)r in s&&delete s[r];return s}}function z(e,i){if(!m(e))return{};let s={};for(let r in e)Object.prototype.hasOwnProperty.call(e,r)&&!i(e[r],r,e)&&(s[r]=e[r]);return s}function oe(e){return z(e,i=>i==null)}function le(e,i){if(!m(e))return{};let s={};for(let r of i)r in e&&(s[r]=e[r]);return s}function fe(e,i){if(!m(e))return{};let s={};for(let r in e)Object.prototype.hasOwnProperty.call(e,r)&&i(e[r],r,e)&&(s[r]=e[r]);return s}function ye(e,i,s){if(!m(e))return{};let r=JSON.parse(JSON.stringify(e)),n=Array.isArray(i)?i:[i];for(let o=0;o<n.length;o++){let t=n[o],l=n[o+1];if(!t||t==="")continue;let a=P(t);if(t.includes("*")||t.includes("[")||a.length>1){let A=function(p,d=""){if(m(p)){if(Array.isArray(p)){p.forEach((c,u)=>{A(c,d?`${d}[${u}]`:`[${u}]`)});return}for(let c in p)if(Object.prototype.hasOwnProperty.call(p,c)){let u=d?`${d}.${c}`:c;g.push({fullPath:u,segments:P(u)}),A(p[c],u)}}};var f=A;let y=I(r,t,{preserveStructure:!0});if(y===void 0)continue;let g=[];A(y);for(let{fullPath:p,segments:d}of g){let c=[...d],u=c.pop();if(!u)continue;let T=c.map(K=>K.type==="index"?`[${K.value}]`:K.value).join(".").replace(/\.\[/g,"["),x=I(r,T.length>0?T:p,{preserveStructure:!0}),h=T?x:r;if(!h)continue;let S=String(u.value),b=h[S];if(s){let K=s(b,p,r);if(K===!0)if(u.type==="index"&&Array.isArray(h)){let E=u.value;E>=0&&E<h.length&&h.splice(E,1)}else R(r,n[o]);else K!==!1&&(h[S]=K)}else if(u.type==="index"&&Array.isArray(h)){let K=u.value;K>=0&&K<h.length&&h.splice(K,1)}else R(r,n[o])}}else{let y=t;if(typeof y=="string"&&y in r)if(s){let g=s(r[y],t,r);g===!0?delete r[y]:g!==!1&&(r[y]=g)}else R(r,n[o])}}return r}function ue(e,i,s){if(!m(e))return{};if(Array.isArray(i)){let f={};for(let o of i){let t=I(e,o,{preserveStructure:!0});if(t!==void 0)if(s){let l=(y,g)=>{if(m(y)){if(Array.isArray(y))return y.map((p,d)=>l(p,`${g}[${d}]`));let A={};for(let p in y)if(Object.prototype.hasOwnProperty.call(y,p)){let d=g?`${g}.${p}`:p;A[p]=l(y[p],d)}return A}return s(y,g,e)},a=l(t,o);W(f,a)}else Object.assign(f,W(f,t))}return f}let r=Array.isArray(i)?i[0]:i,n=I(e,r,{preserveStructure:!0});if(n===void 0)return{};if(s){let f=(o,t)=>{if(m(o)){if(Array.isArray(o))return o.map((a,y)=>f(a,`${t}[${y}]`));let l={};for(let a in o)if(Object.prototype.hasOwnProperty.call(o,a)){let y=t?`${t}.${a}`:a;l[a]=f(o[a],y)}return l}return s(o,t,e)};return f(n,r)}return n}function C(e,i){if(!m(e))return e;if(Array.isArray(e))return e.map(r=>C(r,i));let s={};for(let r in e){if(!Object.prototype.hasOwnProperty.call(e,r))continue;let n=e[r];i(n,r,e)||(m(n)?s[r]=C(n,i):Array.isArray(n)?s[r]=n.map(f=>C(f,i)):s[r]=n)}return s}
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/object/omit.ts
|
|
21
|
+
var omit_exports = {};
|
|
22
|
+
__export(omit_exports, {
|
|
23
|
+
createOmitter: () => createOmitter,
|
|
24
|
+
deepOmit: () => deepOmit,
|
|
25
|
+
deepOmitBy: () => deepOmitBy,
|
|
26
|
+
omit: () => omit,
|
|
27
|
+
omitBy: () => omitBy,
|
|
28
|
+
omitNil: () => omitNil,
|
|
29
|
+
omitPath: () => omitPath,
|
|
30
|
+
pick: () => pick,
|
|
31
|
+
pickBy: () => pickBy,
|
|
32
|
+
pickPath: () => pickPath
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(omit_exports);
|
|
35
|
+
|
|
36
|
+
// src/lib/object/utils.ts
|
|
37
|
+
var isObject = (value) => {
|
|
38
|
+
if (value == null) return false;
|
|
39
|
+
if (Array.isArray(value)) return false;
|
|
40
|
+
if (typeof value === "function") return false;
|
|
41
|
+
if (value instanceof Date) return false;
|
|
42
|
+
if (value instanceof RegExp) return false;
|
|
43
|
+
if (value instanceof Map) return false;
|
|
44
|
+
if (value instanceof Set) return false;
|
|
45
|
+
if (value instanceof Error) return false;
|
|
46
|
+
return typeof value === "object";
|
|
47
|
+
};
|
|
48
|
+
function isPlainObject(v) {
|
|
49
|
+
if (typeof v !== "object" || v === null) return false;
|
|
50
|
+
const proto = Object.getPrototypeOf(v);
|
|
51
|
+
return proto === Object.prototype || proto === null;
|
|
52
|
+
}
|
|
53
|
+
var traverseStructure = (current, segments, depth, maxDepth) => {
|
|
54
|
+
if (depth > maxDepth) return void 0;
|
|
55
|
+
if (segments.length === 0) return current;
|
|
56
|
+
const segment = segments[0];
|
|
57
|
+
const remaining = segments.slice(1);
|
|
58
|
+
if (segment.type === "descendant") {
|
|
59
|
+
const result = traverseStructure(current, remaining, depth + 1, maxDepth);
|
|
60
|
+
if (result !== void 0) {
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
if (current && typeof current === "object") {
|
|
64
|
+
if (Array.isArray(current)) {
|
|
65
|
+
const arrResult = [];
|
|
66
|
+
for (let i = 0; i < current.length; i++) {
|
|
67
|
+
const itemResult = traverseStructure(
|
|
68
|
+
current[i],
|
|
69
|
+
segments,
|
|
70
|
+
depth + 1,
|
|
71
|
+
maxDepth
|
|
72
|
+
);
|
|
73
|
+
if (itemResult !== void 0) {
|
|
74
|
+
arrResult[i] = itemResult;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return arrResult.length > 0 ? arrResult : void 0;
|
|
78
|
+
} else {
|
|
79
|
+
const objResult = {};
|
|
80
|
+
for (const key in current) {
|
|
81
|
+
if (current.hasOwnProperty(key)) {
|
|
82
|
+
const itemResult = traverseStructure(
|
|
83
|
+
current[key],
|
|
84
|
+
segments,
|
|
85
|
+
depth + 1,
|
|
86
|
+
maxDepth
|
|
87
|
+
);
|
|
88
|
+
if (itemResult !== void 0) {
|
|
89
|
+
objResult[key] = itemResult;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return Object.keys(objResult).length > 0 ? objResult : void 0;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return void 0;
|
|
97
|
+
}
|
|
98
|
+
switch (segment.type) {
|
|
99
|
+
case "property":
|
|
100
|
+
if (isObject(current) && segment.value && String(segment.value) in current) {
|
|
101
|
+
const next = current[String(segment.value)];
|
|
102
|
+
const result = traverseStructure(next, remaining, depth + 1, maxDepth);
|
|
103
|
+
if (result !== void 0) {
|
|
104
|
+
return { [String(segment.value)]: result };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
case "index":
|
|
109
|
+
if (Array.isArray(current)) {
|
|
110
|
+
const index = segment.value;
|
|
111
|
+
if (index >= 0 && index < current.length) {
|
|
112
|
+
const result = traverseStructure(
|
|
113
|
+
current[index],
|
|
114
|
+
remaining,
|
|
115
|
+
depth + 1,
|
|
116
|
+
maxDepth
|
|
117
|
+
);
|
|
118
|
+
if (result !== void 0) {
|
|
119
|
+
const arr = new Array(current.length).filter(
|
|
120
|
+
(a) => a !== void 0
|
|
121
|
+
);
|
|
122
|
+
arr[index] = result;
|
|
123
|
+
return arr;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
} else if (current && typeof current === "object") {
|
|
127
|
+
const key = String(segment.value);
|
|
128
|
+
if (key in current) {
|
|
129
|
+
const result = traverseStructure(
|
|
130
|
+
current[key],
|
|
131
|
+
remaining,
|
|
132
|
+
depth + 1,
|
|
133
|
+
maxDepth
|
|
134
|
+
);
|
|
135
|
+
if (result !== void 0) {
|
|
136
|
+
return { [key]: result };
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
break;
|
|
141
|
+
case "wildcard":
|
|
142
|
+
if (current && typeof current === "object") {
|
|
143
|
+
if (Array.isArray(current)) {
|
|
144
|
+
const arrResult = [];
|
|
145
|
+
let hasResults = false;
|
|
146
|
+
for (let i = 0; i < current.length; i++) {
|
|
147
|
+
const result = traverseStructure(
|
|
148
|
+
current[i],
|
|
149
|
+
remaining,
|
|
150
|
+
depth + 1,
|
|
151
|
+
maxDepth
|
|
152
|
+
);
|
|
153
|
+
if (result !== void 0) {
|
|
154
|
+
arrResult[i] = result;
|
|
155
|
+
hasResults = true;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return hasResults ? arrResult : void 0;
|
|
159
|
+
} else {
|
|
160
|
+
const objResult = {};
|
|
161
|
+
let hasResults = false;
|
|
162
|
+
for (const key in current) {
|
|
163
|
+
if (current.hasOwnProperty(key)) {
|
|
164
|
+
const result = traverseStructure(
|
|
165
|
+
current[key],
|
|
166
|
+
remaining,
|
|
167
|
+
depth + 1,
|
|
168
|
+
maxDepth
|
|
169
|
+
);
|
|
170
|
+
if (result !== void 0) {
|
|
171
|
+
objResult[key] = result;
|
|
172
|
+
hasResults = true;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return hasResults ? objResult : void 0;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
break;
|
|
180
|
+
case "slice":
|
|
181
|
+
if (Array.isArray(current)) {
|
|
182
|
+
const [start, end] = segment.value;
|
|
183
|
+
const actualStart = Math.max(0, start);
|
|
184
|
+
const actualEnd = Math.min(
|
|
185
|
+
current.length,
|
|
186
|
+
end === Infinity ? current.length : end
|
|
187
|
+
);
|
|
188
|
+
const arrResult = [];
|
|
189
|
+
let hasResults = false;
|
|
190
|
+
for (let i = actualStart; i < actualEnd; i++) {
|
|
191
|
+
const result = traverseStructure(
|
|
192
|
+
current[i],
|
|
193
|
+
remaining,
|
|
194
|
+
depth + 1,
|
|
195
|
+
maxDepth
|
|
196
|
+
);
|
|
197
|
+
if (result !== void 0) {
|
|
198
|
+
arrResult[i] = result;
|
|
199
|
+
hasResults = true;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return hasResults ? arrResult : void 0;
|
|
203
|
+
}
|
|
204
|
+
break;
|
|
205
|
+
case "union":
|
|
206
|
+
if (Array.isArray(current)) {
|
|
207
|
+
const indices = segment.value;
|
|
208
|
+
const arrResult = [];
|
|
209
|
+
let hasResults = false;
|
|
210
|
+
for (const index of indices) {
|
|
211
|
+
if (index >= 0 && index < current.length) {
|
|
212
|
+
const result = traverseStructure(
|
|
213
|
+
current[index],
|
|
214
|
+
remaining,
|
|
215
|
+
depth + 1,
|
|
216
|
+
maxDepth
|
|
217
|
+
);
|
|
218
|
+
if (result !== void 0) {
|
|
219
|
+
arrResult[index] = result;
|
|
220
|
+
hasResults = true;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return hasResults ? arrResult : void 0;
|
|
225
|
+
}
|
|
226
|
+
break;
|
|
227
|
+
case "filter":
|
|
228
|
+
if (Array.isArray(current)) {
|
|
229
|
+
const filterFn = segment.value;
|
|
230
|
+
const arrResult = [];
|
|
231
|
+
let hasResults = false;
|
|
232
|
+
for (let i = 0; i < current.length; i++) {
|
|
233
|
+
if (filterFn(current[i])) {
|
|
234
|
+
const result = traverseStructure(
|
|
235
|
+
current[i],
|
|
236
|
+
remaining,
|
|
237
|
+
depth + 1,
|
|
238
|
+
maxDepth
|
|
239
|
+
);
|
|
240
|
+
if (result !== void 0) {
|
|
241
|
+
arrResult[i] = result;
|
|
242
|
+
hasResults = true;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return hasResults ? arrResult : void 0;
|
|
247
|
+
}
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
return void 0;
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// src/lib/object/clone.ts
|
|
254
|
+
var deepClone = (obj, skipKeys) => {
|
|
255
|
+
if (obj == null || typeof obj !== "object") {
|
|
256
|
+
return obj;
|
|
257
|
+
}
|
|
258
|
+
if (obj instanceof Date) {
|
|
259
|
+
return new Date(obj.getTime());
|
|
260
|
+
}
|
|
261
|
+
if (obj instanceof RegExp) {
|
|
262
|
+
return new RegExp(obj.source, obj.flags);
|
|
263
|
+
}
|
|
264
|
+
if (obj instanceof Map) {
|
|
265
|
+
const clone = /* @__PURE__ */ new Map();
|
|
266
|
+
obj.forEach((value, key) => {
|
|
267
|
+
if (!skipKeys || !skipKeys.some((k) => k.toString() === key.toString())) {
|
|
268
|
+
clone.set(key, deepClone(value));
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
return clone;
|
|
272
|
+
}
|
|
273
|
+
if (obj instanceof Set) {
|
|
274
|
+
const clone = /* @__PURE__ */ new Set();
|
|
275
|
+
obj.forEach((value) => {
|
|
276
|
+
clone.add(deepClone(value));
|
|
277
|
+
});
|
|
278
|
+
return clone;
|
|
279
|
+
}
|
|
280
|
+
if (Array.isArray(obj)) {
|
|
281
|
+
return Array.from(obj).map((item) => deepClone(item));
|
|
282
|
+
}
|
|
283
|
+
if (isObject(obj)) {
|
|
284
|
+
const clone = {};
|
|
285
|
+
for (const key in obj) {
|
|
286
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
287
|
+
if (!skipKeys || !skipKeys.some((k) => k.toString() === key.toString())) {
|
|
288
|
+
clone[key] = deepClone(obj[key]);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
const symbols = Object.getOwnPropertySymbols(obj);
|
|
293
|
+
for (const symbol of symbols) {
|
|
294
|
+
if (!skipKeys || !skipKeys.some((s) => s.toString() === symbol.toString())) {
|
|
295
|
+
clone[symbol] = deepClone(obj[symbol]);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return clone;
|
|
299
|
+
}
|
|
300
|
+
return obj;
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
// src/lib/object/diff.ts
|
|
304
|
+
var defaultEqualityFn = (a, b) => a === b;
|
|
305
|
+
var deepArrayEqual = (arr1, arr2) => {
|
|
306
|
+
if (arr1.length !== arr2.length) return false;
|
|
307
|
+
for (let i = 0; i < arr1.length; i++) {
|
|
308
|
+
if (Array.isArray(arr1[i]) && Array.isArray(arr2[i])) {
|
|
309
|
+
if (!deepArrayEqual(arr1[i], arr2[i])) return false;
|
|
310
|
+
} else if (isObject(arr1[i]) && isObject(arr2[i])) {
|
|
311
|
+
if (!deepObjectEqual(arr1[i], arr2[i])) return false;
|
|
312
|
+
} else if (arr1[i] !== arr2[i]) {
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return true;
|
|
317
|
+
};
|
|
318
|
+
var deepObjectEqual = (obj1, obj2) => {
|
|
319
|
+
const keys1 = Object.keys(obj1);
|
|
320
|
+
const keys2 = Object.keys(obj2);
|
|
321
|
+
if (keys1.length !== keys2.length) return false;
|
|
322
|
+
for (const key of keys1) {
|
|
323
|
+
if (!(key in obj2)) return false;
|
|
324
|
+
const val1 = obj1[key];
|
|
325
|
+
const val2 = obj2[key];
|
|
326
|
+
if (Array.isArray(val1) && Array.isArray(val2)) {
|
|
327
|
+
if (!deepArrayEqual(val1, val2)) return false;
|
|
328
|
+
} else if (isObject(val1) && isObject(val2)) {
|
|
329
|
+
if (!deepObjectEqual(val1, val2)) return false;
|
|
330
|
+
} else if (val1 !== val2) {
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return true;
|
|
335
|
+
};
|
|
336
|
+
var diffObject = (oldObj, newObj, options = {}) => {
|
|
337
|
+
const {
|
|
338
|
+
includeDeleted = false,
|
|
339
|
+
includeAdded = true,
|
|
340
|
+
deepArrayComparison = true,
|
|
341
|
+
equalityFn = defaultEqualityFn,
|
|
342
|
+
preserveStructure = false
|
|
343
|
+
} = options;
|
|
344
|
+
if (oldObj == null && newObj == null) {
|
|
345
|
+
return {};
|
|
346
|
+
}
|
|
347
|
+
if (oldObj == null) {
|
|
348
|
+
return includeAdded ? { ...newObj } : {};
|
|
349
|
+
}
|
|
350
|
+
if (newObj == null) {
|
|
351
|
+
if (includeDeleted) {
|
|
352
|
+
const result2 = {};
|
|
353
|
+
for (const key in oldObj) {
|
|
354
|
+
result2[key] = void 0;
|
|
355
|
+
}
|
|
356
|
+
return result2;
|
|
357
|
+
}
|
|
358
|
+
return {};
|
|
359
|
+
}
|
|
360
|
+
if (!isObject(oldObj) || !isObject(newObj)) {
|
|
361
|
+
return equalityFn(oldObj, newObj) ? {} : newObj;
|
|
362
|
+
}
|
|
363
|
+
const result = {};
|
|
364
|
+
const processedKeys = /* @__PURE__ */ new Set();
|
|
365
|
+
for (const key in newObj) {
|
|
366
|
+
processedKeys.add(key);
|
|
367
|
+
const oldValue = oldObj[key];
|
|
368
|
+
const newValue = newObj[key];
|
|
369
|
+
if (!(key in oldObj)) {
|
|
370
|
+
if (includeAdded) {
|
|
371
|
+
result[key] = newValue;
|
|
372
|
+
}
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
if (Array.isArray(oldValue) && Array.isArray(newValue)) {
|
|
376
|
+
if (deepArrayComparison) {
|
|
377
|
+
if (!deepArrayEqual(oldValue, newValue)) {
|
|
378
|
+
result[key] = newValue;
|
|
379
|
+
} else if (preserveStructure) {
|
|
380
|
+
result[key] = void 0;
|
|
381
|
+
}
|
|
382
|
+
} else {
|
|
383
|
+
if (oldValue !== newValue) {
|
|
384
|
+
result[key] = newValue;
|
|
385
|
+
} else if (preserveStructure) {
|
|
386
|
+
result[key] = void 0;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
if (isObject(oldValue) && isObject(newValue)) {
|
|
392
|
+
const nestedDiff = diffObject(oldValue, newValue, options);
|
|
393
|
+
if (Object.keys(nestedDiff).length > 0) {
|
|
394
|
+
result[key] = nestedDiff;
|
|
395
|
+
} else if (preserveStructure) {
|
|
396
|
+
result[key] = void 0;
|
|
397
|
+
}
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
if (!equalityFn(oldValue, newValue)) {
|
|
401
|
+
result[key] = newValue;
|
|
402
|
+
} else if (preserveStructure) {
|
|
403
|
+
result[key] = void 0;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
if (includeDeleted) {
|
|
407
|
+
for (const key in oldObj) {
|
|
408
|
+
if (!processedKeys.has(key)) {
|
|
409
|
+
result[key] = void 0;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return result;
|
|
414
|
+
};
|
|
415
|
+
var diffObjectDetailed = (oldObj, newObj, options = {}) => {
|
|
416
|
+
const added = [];
|
|
417
|
+
const deleted = [];
|
|
418
|
+
const modified = [];
|
|
419
|
+
const changes = {};
|
|
420
|
+
const {
|
|
421
|
+
includeDeleted = false,
|
|
422
|
+
includeAdded = true,
|
|
423
|
+
deepArrayComparison = true,
|
|
424
|
+
equalityFn = defaultEqualityFn
|
|
425
|
+
} = options;
|
|
426
|
+
if (Array.isArray(oldObj) && Array.isArray(newObj)) {
|
|
427
|
+
const maxLength = Math.max(oldObj.length, newObj.length);
|
|
428
|
+
const arrayChanges = [];
|
|
429
|
+
let hasArrayChanges = false;
|
|
430
|
+
for (let i = 0; i < maxLength; i++) {
|
|
431
|
+
const indexPath = `[${i}]`;
|
|
432
|
+
if (i >= oldObj.length) {
|
|
433
|
+
added.push(indexPath);
|
|
434
|
+
arrayChanges[i] = newObj[i];
|
|
435
|
+
hasArrayChanges = true;
|
|
436
|
+
} else if (i >= newObj.length) {
|
|
437
|
+
deleted.push(indexPath);
|
|
438
|
+
hasArrayChanges = true;
|
|
439
|
+
} else {
|
|
440
|
+
const oldElement = oldObj[i];
|
|
441
|
+
const newElement = newObj[i];
|
|
442
|
+
if (isObject(oldElement) && isObject(newElement)) {
|
|
443
|
+
const nestedDiff = diffObjectDetailed(
|
|
444
|
+
oldElement,
|
|
445
|
+
newElement,
|
|
446
|
+
options
|
|
447
|
+
);
|
|
448
|
+
if (nestedDiff.hasChanges) {
|
|
449
|
+
modified.push(indexPath);
|
|
450
|
+
arrayChanges[i] = newElement;
|
|
451
|
+
hasArrayChanges = true;
|
|
452
|
+
} else {
|
|
453
|
+
arrayChanges[i] = oldElement;
|
|
454
|
+
}
|
|
455
|
+
} else if (Array.isArray(oldElement) && Array.isArray(newElement)) {
|
|
456
|
+
const nestedDiff = diffObjectDetailed(
|
|
457
|
+
oldElement,
|
|
458
|
+
newElement,
|
|
459
|
+
options
|
|
460
|
+
);
|
|
461
|
+
if (nestedDiff.hasChanges) {
|
|
462
|
+
modified.push(indexPath);
|
|
463
|
+
arrayChanges[i] = newElement;
|
|
464
|
+
hasArrayChanges = true;
|
|
465
|
+
} else {
|
|
466
|
+
arrayChanges[i] = oldElement;
|
|
467
|
+
}
|
|
468
|
+
} else if (!equalityFn(oldElement, newElement)) {
|
|
469
|
+
modified.push(indexPath);
|
|
470
|
+
arrayChanges[i] = newElement;
|
|
471
|
+
hasArrayChanges = true;
|
|
472
|
+
} else {
|
|
473
|
+
arrayChanges[i] = oldElement;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
return {
|
|
478
|
+
changes: hasArrayChanges ? arrayChanges : {},
|
|
479
|
+
added,
|
|
480
|
+
deleted,
|
|
481
|
+
modified,
|
|
482
|
+
hasChanges: hasArrayChanges || deleted.length > 0
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
const collectDetailedPaths = (old, newVal, currentPath = "") => {
|
|
486
|
+
const result = {
|
|
487
|
+
added: [],
|
|
488
|
+
deleted: [],
|
|
489
|
+
modified: []
|
|
490
|
+
};
|
|
491
|
+
if (Array.isArray(old) && Array.isArray(newVal)) {
|
|
492
|
+
const maxLength = Math.max(old.length, newVal.length);
|
|
493
|
+
for (let i = 0; i < maxLength; i++) {
|
|
494
|
+
const indexPath = currentPath ? `${currentPath}[${i}]` : `[${i}]`;
|
|
495
|
+
if (i >= old.length) {
|
|
496
|
+
result.added.push(indexPath);
|
|
497
|
+
} else if (i >= newVal.length) {
|
|
498
|
+
result.deleted.push(indexPath);
|
|
499
|
+
} else {
|
|
500
|
+
const oldElement = old[i];
|
|
501
|
+
const newElement = newVal[i];
|
|
502
|
+
if (isObject(oldElement) && isObject(newElement)) {
|
|
503
|
+
const nested = collectDetailedPaths(
|
|
504
|
+
oldElement,
|
|
505
|
+
newElement,
|
|
506
|
+
indexPath
|
|
507
|
+
);
|
|
508
|
+
result.added.push(...nested.added);
|
|
509
|
+
result.deleted.push(...nested.deleted);
|
|
510
|
+
result.modified.push(...nested.modified);
|
|
511
|
+
} else if (Array.isArray(oldElement) && Array.isArray(newElement)) {
|
|
512
|
+
const nested = collectDetailedPaths(
|
|
513
|
+
oldElement,
|
|
514
|
+
newElement,
|
|
515
|
+
indexPath
|
|
516
|
+
);
|
|
517
|
+
result.added.push(...nested.added);
|
|
518
|
+
result.deleted.push(...nested.deleted);
|
|
519
|
+
result.modified.push(...nested.modified);
|
|
520
|
+
} else if (oldElement !== newElement) {
|
|
521
|
+
result.modified.push(indexPath);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
return result;
|
|
526
|
+
}
|
|
527
|
+
if (isObject(old) && isObject(newVal)) {
|
|
528
|
+
const allKeys = /* @__PURE__ */ new Set([
|
|
529
|
+
...Object.keys(old || {}),
|
|
530
|
+
...Object.keys(newVal || {})
|
|
531
|
+
]);
|
|
532
|
+
for (const key of allKeys) {
|
|
533
|
+
const oldValue = old?.[key];
|
|
534
|
+
const newValue = newVal?.[key];
|
|
535
|
+
const path = currentPath ? `${currentPath}.${key}` : key;
|
|
536
|
+
if (!(key in (old || {}))) {
|
|
537
|
+
result.added.push(path);
|
|
538
|
+
} else if (!(key in (newVal || {}))) {
|
|
539
|
+
result.deleted.push(path);
|
|
540
|
+
} else if (Array.isArray(oldValue) && Array.isArray(newValue)) {
|
|
541
|
+
if (!deepArrayEqual(oldValue, newValue)) {
|
|
542
|
+
const nested = collectDetailedPaths(oldValue, newValue, path);
|
|
543
|
+
result.added.push(...nested.added);
|
|
544
|
+
result.deleted.push(...nested.deleted);
|
|
545
|
+
result.modified.push(...nested.modified);
|
|
546
|
+
}
|
|
547
|
+
} else if (isObject(oldValue) && isObject(newValue)) {
|
|
548
|
+
const nested = collectDetailedPaths(oldValue, newValue, path);
|
|
549
|
+
result.added.push(...nested.added);
|
|
550
|
+
result.deleted.push(...nested.deleted);
|
|
551
|
+
result.modified.push(...nested.modified);
|
|
552
|
+
} else if (oldValue !== newValue) {
|
|
553
|
+
result.modified.push(path);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
return result;
|
|
558
|
+
};
|
|
559
|
+
if (oldObj == null && newObj == null) {
|
|
560
|
+
return { changes: {}, added, deleted, modified, hasChanges: false };
|
|
561
|
+
}
|
|
562
|
+
if (oldObj == null) {
|
|
563
|
+
if (includeAdded && newObj) {
|
|
564
|
+
for (const key in newObj) {
|
|
565
|
+
added.push(key);
|
|
566
|
+
changes[key] = newObj[key];
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
return {
|
|
570
|
+
changes,
|
|
571
|
+
added,
|
|
572
|
+
deleted,
|
|
573
|
+
modified,
|
|
574
|
+
hasChanges: added.length > 0
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
if (newObj == null) {
|
|
578
|
+
if (includeDeleted) {
|
|
579
|
+
for (const key in oldObj) {
|
|
580
|
+
deleted.push(key);
|
|
581
|
+
changes[key] = void 0;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
return {
|
|
585
|
+
changes,
|
|
586
|
+
added,
|
|
587
|
+
deleted,
|
|
588
|
+
modified,
|
|
589
|
+
hasChanges: deleted.length > 0
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
const processedKeys = /* @__PURE__ */ new Set();
|
|
593
|
+
for (const key in newObj) {
|
|
594
|
+
processedKeys.add(key);
|
|
595
|
+
const oldValue = oldObj[key];
|
|
596
|
+
const newValue = newObj[key];
|
|
597
|
+
if (!(key in oldObj)) {
|
|
598
|
+
if (includeAdded) {
|
|
599
|
+
added.push(key);
|
|
600
|
+
changes[key] = newValue;
|
|
601
|
+
}
|
|
602
|
+
continue;
|
|
603
|
+
}
|
|
604
|
+
let isDifferent = false;
|
|
605
|
+
if (Array.isArray(oldValue) && Array.isArray(newValue)) {
|
|
606
|
+
isDifferent = deepArrayComparison ? !deepArrayEqual(oldValue, newValue) : oldValue !== newValue;
|
|
607
|
+
if (isDifferent) {
|
|
608
|
+
const paths = collectDetailedPaths(oldValue, newValue, key);
|
|
609
|
+
added.push(...paths.added);
|
|
610
|
+
deleted.push(...paths.deleted);
|
|
611
|
+
modified.push(...paths.modified);
|
|
612
|
+
changes[key] = newValue;
|
|
613
|
+
}
|
|
614
|
+
} else if (isObject(oldValue) && isObject(newValue)) {
|
|
615
|
+
const nestedDiff = diffObject(oldValue, newValue, options);
|
|
616
|
+
isDifferent = Object.keys(nestedDiff).length > 0;
|
|
617
|
+
if (isDifferent) {
|
|
618
|
+
const paths = collectDetailedPaths(oldValue, newValue, key);
|
|
619
|
+
added.push(...paths.added);
|
|
620
|
+
deleted.push(...paths.deleted);
|
|
621
|
+
modified.push(...paths.modified);
|
|
622
|
+
changes[key] = nestedDiff;
|
|
623
|
+
}
|
|
624
|
+
} else {
|
|
625
|
+
isDifferent = !equalityFn(oldValue, newValue);
|
|
626
|
+
if (isDifferent) {
|
|
627
|
+
modified.push(key);
|
|
628
|
+
changes[key] = newValue;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
for (const key in oldObj) {
|
|
633
|
+
if (!processedKeys.has(key)) {
|
|
634
|
+
deleted.push(key);
|
|
635
|
+
changes[key] = void 0;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
return {
|
|
639
|
+
changes,
|
|
640
|
+
added,
|
|
641
|
+
deleted,
|
|
642
|
+
modified,
|
|
643
|
+
hasChanges: added.length > 0 || deleted.length > 0 || modified.length > 0
|
|
644
|
+
};
|
|
645
|
+
};
|
|
646
|
+
function isApplyDiff(value) {
|
|
647
|
+
if (value && (value.diff || value.changes) && (value.modified || value.deleted || value.hasChanges)) {
|
|
648
|
+
return true;
|
|
649
|
+
}
|
|
650
|
+
return false;
|
|
651
|
+
}
|
|
652
|
+
var applyDiff = (baseObj, option, keepRefParam) => {
|
|
653
|
+
if (!isApplyDiff(option)) {
|
|
654
|
+
const diff2 = option;
|
|
655
|
+
const shouldKeepRef2 = keepRefParam || false;
|
|
656
|
+
if (Array.isArray(baseObj) && Array.isArray(diff2)) {
|
|
657
|
+
const result3 = shouldKeepRef2 ? baseObj : [...baseObj];
|
|
658
|
+
if (diff2.length < result3.length) {
|
|
659
|
+
result3.length = diff2.length;
|
|
660
|
+
}
|
|
661
|
+
for (let i = 0; i < diff2.length; i++) {
|
|
662
|
+
const diffValue = diff2[i];
|
|
663
|
+
if (diffValue === void 0) {
|
|
664
|
+
continue;
|
|
665
|
+
}
|
|
666
|
+
if (isObject(result3[i]) && isObject(diffValue)) {
|
|
667
|
+
result3[i] = applyDiff(result3[i], diffValue, shouldKeepRef2);
|
|
668
|
+
} else if (Array.isArray(result3[i]) && Array.isArray(diffValue)) {
|
|
669
|
+
result3[i] = applyDiff(
|
|
670
|
+
result3[i],
|
|
671
|
+
diffValue,
|
|
672
|
+
shouldKeepRef2
|
|
673
|
+
);
|
|
674
|
+
} else {
|
|
675
|
+
result3[i] = diffValue;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
return result3;
|
|
679
|
+
}
|
|
680
|
+
if (!isObject(baseObj)) return diff2;
|
|
681
|
+
if (!isObject(diff2)) return baseObj;
|
|
682
|
+
const result2 = shouldKeepRef2 ? baseObj : { ...baseObj };
|
|
683
|
+
for (const key in diff2) {
|
|
684
|
+
const diffValue = diff2[key];
|
|
685
|
+
if (diffValue === void 0) {
|
|
686
|
+
delete result2[key];
|
|
687
|
+
} else if (Array.isArray(result2[key]) && Array.isArray(diffValue)) {
|
|
688
|
+
result2[key] = applyDiff(result2[key], diffValue, shouldKeepRef2);
|
|
689
|
+
} else if (isObject(result2[key]) && isObject(diffValue)) {
|
|
690
|
+
result2[key] = applyDiff(result2[key], diffValue, shouldKeepRef2);
|
|
691
|
+
} else {
|
|
692
|
+
result2[key] = diffValue;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
return result2;
|
|
696
|
+
}
|
|
697
|
+
const {
|
|
698
|
+
diff,
|
|
699
|
+
added = [],
|
|
700
|
+
deleted = [],
|
|
701
|
+
modified = [],
|
|
702
|
+
changes,
|
|
703
|
+
keepRef: keepRefOption
|
|
704
|
+
} = option;
|
|
705
|
+
const shouldKeepRef = keepRefParam !== void 0 ? keepRefParam : keepRefOption;
|
|
706
|
+
const diffToApply = changes || diff;
|
|
707
|
+
if (!diffToApply) return baseObj;
|
|
708
|
+
const addedSet = new Set(added);
|
|
709
|
+
const deletedSet = new Set(deleted);
|
|
710
|
+
const modifiedSet = new Set(modified);
|
|
711
|
+
const shouldApplyPath = (path) => {
|
|
712
|
+
if (added.length === 0 && deleted.length === 0 && modified.length === 0) {
|
|
713
|
+
return true;
|
|
714
|
+
}
|
|
715
|
+
const pathParts = path.split(/[.\[\]]+/).filter(Boolean);
|
|
716
|
+
for (let i = 0; i <= pathParts.length; i++) {
|
|
717
|
+
const partialPath = pathParts.slice(0, i).join(".");
|
|
718
|
+
const bracketPath = pathParts.slice(0, i).map((p, idx) => /^\d+$/.test(p) ? `[${p}]` : idx > 0 ? `.${p}` : p).join("");
|
|
719
|
+
if (addedSet.has(partialPath) || addedSet.has(bracketPath) || deletedSet.has(partialPath) || deletedSet.has(bracketPath) || modifiedSet.has(partialPath) || modifiedSet.has(bracketPath)) {
|
|
720
|
+
return true;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
return false;
|
|
724
|
+
};
|
|
725
|
+
if (Array.isArray(baseObj) && Array.isArray(diffToApply)) {
|
|
726
|
+
const result2 = shouldKeepRef ? baseObj : [...baseObj];
|
|
727
|
+
result2.length = diffToApply.length;
|
|
728
|
+
for (let i = 0; i < diffToApply.length; i++) {
|
|
729
|
+
const indexPath = `[${i}]`;
|
|
730
|
+
const diffValue = diffToApply[i];
|
|
731
|
+
if (diffValue === void 0) {
|
|
732
|
+
continue;
|
|
733
|
+
}
|
|
734
|
+
if (!shouldApplyPath(indexPath)) {
|
|
735
|
+
continue;
|
|
736
|
+
}
|
|
737
|
+
if (isObject(result2[i]) && isObject(diffValue)) {
|
|
738
|
+
result2[i] = applyDiff(result2[i], diffValue, shouldKeepRef);
|
|
739
|
+
} else if (Array.isArray(result2[i]) && Array.isArray(diffValue)) {
|
|
740
|
+
result2[i] = applyDiff(
|
|
741
|
+
result2[i],
|
|
742
|
+
diffValue,
|
|
743
|
+
shouldKeepRef
|
|
744
|
+
);
|
|
745
|
+
} else {
|
|
746
|
+
result2[i] = diffValue;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
return result2;
|
|
750
|
+
}
|
|
751
|
+
if (!isObject(baseObj)) return diffToApply;
|
|
752
|
+
if (!isObject(diffToApply)) return baseObj;
|
|
753
|
+
const result = shouldKeepRef ? baseObj : { ...baseObj };
|
|
754
|
+
for (const path of deleted) {
|
|
755
|
+
if (path.includes(".") || path.includes("[")) continue;
|
|
756
|
+
if (shouldApplyPath(path)) {
|
|
757
|
+
delete result[path];
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
for (const key in diffToApply) {
|
|
761
|
+
const diffValue = diffToApply[key];
|
|
762
|
+
if (!shouldApplyPath(key)) {
|
|
763
|
+
continue;
|
|
764
|
+
}
|
|
765
|
+
if (diffValue === void 0) {
|
|
766
|
+
delete result[key];
|
|
767
|
+
} else if (Array.isArray(result[key]) && Array.isArray(diffValue)) {
|
|
768
|
+
result[key] = applyDiff(result[key], diffValue, shouldKeepRef);
|
|
769
|
+
} else if (isObject(result[key]) && isObject(diffValue)) {
|
|
770
|
+
result[key] = applyDiff(result[key], diffValue, shouldKeepRef);
|
|
771
|
+
} else {
|
|
772
|
+
result[key] = diffValue;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
return result;
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
// src/lib/object/selector.ts
|
|
779
|
+
var parseSelector = (selector, options = {}) => {
|
|
780
|
+
const { type = "auto", throwOnError = false } = options;
|
|
781
|
+
if (!selector || typeof selector !== "string") {
|
|
782
|
+
return [];
|
|
783
|
+
}
|
|
784
|
+
const segments = [];
|
|
785
|
+
let current = "";
|
|
786
|
+
let inBrackets = false;
|
|
787
|
+
let inQuotes = false;
|
|
788
|
+
let quoteChar = "";
|
|
789
|
+
let bracketContent = "";
|
|
790
|
+
let bracketDepth = 0;
|
|
791
|
+
const detectType = (str) => {
|
|
792
|
+
if (str.includes("..")) return "descendant";
|
|
793
|
+
if (str.includes("[?(")) return "filter";
|
|
794
|
+
if (str.includes("[:") || str.includes("[0:")) return "slice";
|
|
795
|
+
if (str.includes("[,") || str.includes("[0,1]")) return "union";
|
|
796
|
+
if (str.includes("[*]") || str.includes(".*.")) return "wildcard";
|
|
797
|
+
if (str.includes("[]")) return "array-wildcard";
|
|
798
|
+
if (str.includes("[") && str.includes("]")) return "bracket";
|
|
799
|
+
return "dot";
|
|
800
|
+
};
|
|
801
|
+
const actualType = type === "auto" ? detectType(selector) : type;
|
|
802
|
+
const parseBracketContent = (content) => {
|
|
803
|
+
const trimmed = content.trim();
|
|
804
|
+
if (trimmed === "*" || trimmed === "") {
|
|
805
|
+
return {
|
|
806
|
+
type: "wildcard",
|
|
807
|
+
value: trimmed === "" ? "[]" : "*",
|
|
808
|
+
raw: trimmed === "" ? "[]" : content
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
if (trimmed === "[]") {
|
|
812
|
+
return { type: "wildcard", value: "[]", raw: content };
|
|
813
|
+
}
|
|
814
|
+
if (/^-?\d+$/.test(trimmed)) {
|
|
815
|
+
return { type: "index", value: parseInt(trimmed, 10), raw: content };
|
|
816
|
+
}
|
|
817
|
+
if (trimmed.includes(":")) {
|
|
818
|
+
const parts = trimmed.split(":").map((p) => p.trim());
|
|
819
|
+
const start = parts[0] === "" ? 0 : parseInt(parts[0], 10);
|
|
820
|
+
const end = parts[1] === "" ? Infinity : parseInt(parts[1], 10);
|
|
821
|
+
if (isNaN(start) || isNaN(end)) {
|
|
822
|
+
if (throwOnError) throw new Error(`Invalid slice notation: ${content}`);
|
|
823
|
+
return { type: "wildcard", value: "*", raw: content };
|
|
824
|
+
}
|
|
825
|
+
return { type: "slice", value: [start, end], raw: content };
|
|
826
|
+
}
|
|
827
|
+
if (trimmed.includes(",")) {
|
|
828
|
+
const indices = trimmed.split(",").map((p) => {
|
|
829
|
+
const num = parseInt(p.trim(), 10);
|
|
830
|
+
return isNaN(num) ? -1 : num;
|
|
831
|
+
}).filter((n) => n >= 0);
|
|
832
|
+
if (indices.length === 0) {
|
|
833
|
+
if (throwOnError) throw new Error(`Invalid union notation: ${content}`);
|
|
834
|
+
return { type: "wildcard", value: "*", raw: content };
|
|
835
|
+
}
|
|
836
|
+
return { type: "union", value: indices, raw: content };
|
|
837
|
+
}
|
|
838
|
+
if (trimmed.startsWith("?(") && trimmed.endsWith(")")) {
|
|
839
|
+
const expr = trimmed.slice(2, -1);
|
|
840
|
+
try {
|
|
841
|
+
const filterFn = createFilterFunction(expr);
|
|
842
|
+
return { type: "filter", value: filterFn, raw: content };
|
|
843
|
+
} catch (error) {
|
|
844
|
+
if (throwOnError) throw error;
|
|
845
|
+
return { type: "wildcard", value: "*", raw: content };
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'")) {
|
|
849
|
+
return { type: "property", value: trimmed.slice(1, -1), raw: content };
|
|
850
|
+
}
|
|
851
|
+
return { type: "property", value: trimmed, raw: content };
|
|
852
|
+
};
|
|
853
|
+
for (let i = 0; i < selector.length; i++) {
|
|
854
|
+
const char = selector[i];
|
|
855
|
+
const nextChar = selector[i + 1];
|
|
856
|
+
if ((char === '"' || char === "'") && !inQuotes) {
|
|
857
|
+
inQuotes = true;
|
|
858
|
+
quoteChar = char;
|
|
859
|
+
continue;
|
|
860
|
+
} else if (char === quoteChar && inQuotes) {
|
|
861
|
+
inQuotes = false;
|
|
862
|
+
quoteChar = "";
|
|
863
|
+
if (!(char === '"' || char === "'")) {
|
|
864
|
+
if (inBrackets) {
|
|
865
|
+
bracketContent += char;
|
|
866
|
+
} else {
|
|
867
|
+
current += char;
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
continue;
|
|
871
|
+
}
|
|
872
|
+
if (inQuotes) {
|
|
873
|
+
if (inBrackets) {
|
|
874
|
+
bracketContent += char;
|
|
875
|
+
} else {
|
|
876
|
+
current += char;
|
|
877
|
+
}
|
|
878
|
+
continue;
|
|
879
|
+
}
|
|
880
|
+
if (char === "[" && !inBrackets) {
|
|
881
|
+
if (current) {
|
|
882
|
+
segments.push({ type: "property", value: current, raw: current });
|
|
883
|
+
current = "";
|
|
884
|
+
}
|
|
885
|
+
inBrackets = true;
|
|
886
|
+
bracketContent = "";
|
|
887
|
+
continue;
|
|
888
|
+
}
|
|
889
|
+
if (char === "]" && inBrackets && !inQuotes) {
|
|
890
|
+
inBrackets = false;
|
|
891
|
+
const segment = parseBracketContent(bracketContent);
|
|
892
|
+
segments.push(segment);
|
|
893
|
+
continue;
|
|
894
|
+
}
|
|
895
|
+
let lastDot = segments.length > 0 ? segments[segments.length - 1] : null;
|
|
896
|
+
if (char === "." && !inBrackets && !inQuotes) {
|
|
897
|
+
if (nextChar === ".") {
|
|
898
|
+
const l = selector.split("..")[0];
|
|
899
|
+
segments.push({ type: "property", value: l, raw: l });
|
|
900
|
+
segments.push({ type: "descendant", value: "..", raw: ".." });
|
|
901
|
+
i++;
|
|
902
|
+
} else if (current) {
|
|
903
|
+
if (current === "*") {
|
|
904
|
+
segments.push({ type: "wildcard", value: current, raw: current });
|
|
905
|
+
} else {
|
|
906
|
+
segments.push({ type: "property", value: current, raw: current });
|
|
907
|
+
}
|
|
908
|
+
current = "";
|
|
909
|
+
}
|
|
910
|
+
continue;
|
|
911
|
+
}
|
|
912
|
+
if (inBrackets) {
|
|
913
|
+
bracketContent += char;
|
|
914
|
+
} else {
|
|
915
|
+
if (lastDot && lastDot.type !== "descendant") {
|
|
916
|
+
current += char;
|
|
917
|
+
} else {
|
|
918
|
+
const l = selector.split(lastDot?.raw)[1];
|
|
919
|
+
if (l !== void 0) {
|
|
920
|
+
current = l;
|
|
921
|
+
} else {
|
|
922
|
+
current += char;
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
if (current) {
|
|
928
|
+
segments.push({ type: "property", value: current, raw: current });
|
|
929
|
+
}
|
|
930
|
+
return segments.map((segment) => {
|
|
931
|
+
if (segment.type === "property" && typeof segment.value === "string") {
|
|
932
|
+
if (/^-?\d+$/.test(segment.value)) {
|
|
933
|
+
const num = parseInt(segment.value, 10);
|
|
934
|
+
if (!isNaN(num)) {
|
|
935
|
+
return { ...segment, type: "index", value: num };
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
return segment;
|
|
940
|
+
});
|
|
941
|
+
};
|
|
942
|
+
var createFilterFunction = (expr) => {
|
|
943
|
+
const safeExpr = expr.replace(/@\.([a-zA-Z_$][\w$]*)/g, (_, prop) => `item.${prop}`).replace(/@/g, "item");
|
|
944
|
+
try {
|
|
945
|
+
return new Function("item", `return ${safeExpr}`);
|
|
946
|
+
} catch (error) {
|
|
947
|
+
throw new Error(`Invalid filter expression: ${expr}`);
|
|
948
|
+
}
|
|
949
|
+
};
|
|
950
|
+
var stringifySelector = (segments) => {
|
|
951
|
+
const parts = [];
|
|
952
|
+
for (let i = 0; i < segments.length; i++) {
|
|
953
|
+
const segment = segments[i];
|
|
954
|
+
const prevSegment = i > 0 ? segments[i - 1] : null;
|
|
955
|
+
switch (segment.type) {
|
|
956
|
+
case "property":
|
|
957
|
+
const needsQuotes = /[\.\[\]\s]/.test(String(segment.value));
|
|
958
|
+
if (needsQuotes) {
|
|
959
|
+
parts.push(`["${segment.value}"]`);
|
|
960
|
+
} else {
|
|
961
|
+
if (prevSegment && prevSegment.type !== "descendant") {
|
|
962
|
+
parts.push(".");
|
|
963
|
+
}
|
|
964
|
+
parts.push(String(segment.value));
|
|
965
|
+
}
|
|
966
|
+
break;
|
|
967
|
+
case "index":
|
|
968
|
+
parts.push(`[${segment.value}]`);
|
|
969
|
+
break;
|
|
970
|
+
case "wildcard":
|
|
971
|
+
if (segment.value === "[]") {
|
|
972
|
+
parts.push("[]");
|
|
973
|
+
} else {
|
|
974
|
+
parts.push("[*]");
|
|
975
|
+
}
|
|
976
|
+
break;
|
|
977
|
+
case "slice":
|
|
978
|
+
const [start, end] = segment.value;
|
|
979
|
+
parts.push(`[${start}:${end === Infinity ? "" : end}]`);
|
|
980
|
+
break;
|
|
981
|
+
case "union":
|
|
982
|
+
const indices = segment.value;
|
|
983
|
+
parts.push(`[${indices.join(",")}]`);
|
|
984
|
+
break;
|
|
985
|
+
case "filter":
|
|
986
|
+
parts.push(`[?(${segment.raw?.slice(2, -1) || ""})]`);
|
|
987
|
+
break;
|
|
988
|
+
case "descendant":
|
|
989
|
+
parts.push("..");
|
|
990
|
+
break;
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
return parts.join("").replace(/\.\[/g, "[");
|
|
994
|
+
};
|
|
995
|
+
|
|
996
|
+
// src/lib/object/merge.ts
|
|
997
|
+
function mergeInPlace(target, source) {
|
|
998
|
+
for (const key in source) {
|
|
999
|
+
const tVal = target[key];
|
|
1000
|
+
const sVal = source[key];
|
|
1001
|
+
const diff = diffObjectDetailed(tVal, sVal);
|
|
1002
|
+
if (Array.isArray(tVal) && Array.isArray(sVal)) {
|
|
1003
|
+
tVal.length = 0;
|
|
1004
|
+
tVal.push(...sVal);
|
|
1005
|
+
} else if (typeof tVal === "object" && typeof sVal === "object" && tVal && sVal && diff.hasChanges) {
|
|
1006
|
+
applyDiff(tVal, sVal);
|
|
1007
|
+
} else {
|
|
1008
|
+
target[key] = sVal;
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
function deepMergeWithOptions(target, ...args) {
|
|
1013
|
+
if (args.length === 0) return deepClone(target);
|
|
1014
|
+
let options = { preserveTarget: false, strict: false };
|
|
1015
|
+
let sources = args;
|
|
1016
|
+
const lastArg = args[args.length - 1];
|
|
1017
|
+
if (lastArg && typeof lastArg === "object" && ("preserveTarget" in lastArg || "strict" in lastArg)) {
|
|
1018
|
+
options = { ...options, ...lastArg };
|
|
1019
|
+
sources = args.slice(0, -1);
|
|
1020
|
+
}
|
|
1021
|
+
const result = options.preserveTarget ? target : deepClone(target);
|
|
1022
|
+
const isArrayMerge = Array.isArray(result);
|
|
1023
|
+
for (const source of sources) {
|
|
1024
|
+
if (source && Array.isArray(source) !== isArrayMerge) {
|
|
1025
|
+
throw new Error("Cannot mix arrays and objects in deepMergeWithOptions");
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
for (const source of sources) {
|
|
1029
|
+
if (source == null) continue;
|
|
1030
|
+
if (isArrayMerge) {
|
|
1031
|
+
const resultArray = result;
|
|
1032
|
+
const sourceArray = source;
|
|
1033
|
+
if (options.strict) {
|
|
1034
|
+
for (let i = 0; i < resultArray.length && i < sourceArray.length; i++) {
|
|
1035
|
+
if (isPlainObject(resultArray[i]) && isPlainObject(sourceArray[i])) {
|
|
1036
|
+
resultArray[i] = deepMergeWithOptions(
|
|
1037
|
+
resultArray[i],
|
|
1038
|
+
sourceArray[i],
|
|
1039
|
+
options
|
|
1040
|
+
);
|
|
1041
|
+
} else {
|
|
1042
|
+
if (typeof resultArray[i] === typeof sourceArray[i]) {
|
|
1043
|
+
resultArray[i] = deepClone(sourceArray[i]);
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
} else {
|
|
1048
|
+
mergeInPlace(resultArray, sourceArray);
|
|
1049
|
+
}
|
|
1050
|
+
} else {
|
|
1051
|
+
if (!isPlainObject(source)) continue;
|
|
1052
|
+
const resultObj = result;
|
|
1053
|
+
const sourceObj = source;
|
|
1054
|
+
for (const key in sourceObj) {
|
|
1055
|
+
if (!Object.prototype.hasOwnProperty.call(sourceObj, key)) continue;
|
|
1056
|
+
const value = sourceObj[key];
|
|
1057
|
+
if (options.strict && !(key in resultObj)) {
|
|
1058
|
+
continue;
|
|
1059
|
+
}
|
|
1060
|
+
const existing = resultObj[key];
|
|
1061
|
+
if (existing === void 0) {
|
|
1062
|
+
resultObj[key] = deepClone(value);
|
|
1063
|
+
} else if (Array.isArray(value) && Array.isArray(existing)) {
|
|
1064
|
+
if (options.strict) {
|
|
1065
|
+
resultObj[key] = deepMergeWithOptions(existing, value, options);
|
|
1066
|
+
} else {
|
|
1067
|
+
resultObj[key] = [
|
|
1068
|
+
...existing,
|
|
1069
|
+
...value.map((item) => deepClone(item))
|
|
1070
|
+
];
|
|
1071
|
+
}
|
|
1072
|
+
} else if (isPlainObject(value) && isPlainObject(existing)) {
|
|
1073
|
+
resultObj[key] = deepMergeWithOptions(existing, value, options);
|
|
1074
|
+
} else {
|
|
1075
|
+
resultObj[key] = deepClone(value);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
const symbols = Object.getOwnPropertySymbols(sourceObj);
|
|
1079
|
+
for (const symbol of symbols) {
|
|
1080
|
+
if (options.strict && !(symbol in resultObj)) {
|
|
1081
|
+
continue;
|
|
1082
|
+
}
|
|
1083
|
+
const value = sourceObj[symbol];
|
|
1084
|
+
const existing = resultObj[symbol];
|
|
1085
|
+
if (existing === void 0) {
|
|
1086
|
+
resultObj[symbol] = deepClone(value);
|
|
1087
|
+
} else if (Array.isArray(value) && Array.isArray(existing)) {
|
|
1088
|
+
if (options.strict) {
|
|
1089
|
+
resultObj[symbol] = deepMergeWithOptions(
|
|
1090
|
+
existing,
|
|
1091
|
+
value,
|
|
1092
|
+
options
|
|
1093
|
+
);
|
|
1094
|
+
} else {
|
|
1095
|
+
resultObj[symbol] = [
|
|
1096
|
+
...existing,
|
|
1097
|
+
...value.map((item) => deepClone(item))
|
|
1098
|
+
];
|
|
1099
|
+
}
|
|
1100
|
+
} else if (isPlainObject(value) && isPlainObject(existing)) {
|
|
1101
|
+
resultObj[symbol] = deepMergeWithOptions(
|
|
1102
|
+
existing,
|
|
1103
|
+
value,
|
|
1104
|
+
options
|
|
1105
|
+
);
|
|
1106
|
+
} else {
|
|
1107
|
+
resultObj[symbol] = deepClone(value);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
return result;
|
|
1113
|
+
}
|
|
1114
|
+
function deepMergeKeepReference(target, ...sources) {
|
|
1115
|
+
return deepMergeWithOptions(target, ...sources, {
|
|
1116
|
+
preserveTarget: true
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1119
|
+
var mergeIntoStructure = (target, selector, value) => {
|
|
1120
|
+
const segments = parseSelector(selector);
|
|
1121
|
+
let current = target;
|
|
1122
|
+
for (let i = 0; i < segments.length; i++) {
|
|
1123
|
+
const segment = segments[i];
|
|
1124
|
+
const isLast = i === segments.length - 1;
|
|
1125
|
+
switch (segment.type) {
|
|
1126
|
+
case "property":
|
|
1127
|
+
if (isLast) {
|
|
1128
|
+
current[String(segment.value)] = value;
|
|
1129
|
+
} else {
|
|
1130
|
+
if (!current[String(segment.value)]) {
|
|
1131
|
+
const nextSegment = segments[i + 1];
|
|
1132
|
+
current[String(segment.value)] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
|
|
1133
|
+
}
|
|
1134
|
+
current = current[String(segment.value)];
|
|
1135
|
+
}
|
|
1136
|
+
break;
|
|
1137
|
+
case "index":
|
|
1138
|
+
if (!Array.isArray(current)) {
|
|
1139
|
+
current = [];
|
|
1140
|
+
}
|
|
1141
|
+
const index = segment.value;
|
|
1142
|
+
if (isLast) {
|
|
1143
|
+
if (index >= current.length) {
|
|
1144
|
+
for (let j = current.length; j <= index; j++) {
|
|
1145
|
+
current.push(void 0);
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
current[index] = value;
|
|
1149
|
+
} else {
|
|
1150
|
+
if (!current[index]) {
|
|
1151
|
+
const nextSegment = segments[i + 1];
|
|
1152
|
+
current[index] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
|
|
1153
|
+
}
|
|
1154
|
+
current = current[index];
|
|
1155
|
+
}
|
|
1156
|
+
break;
|
|
1157
|
+
case "wildcard":
|
|
1158
|
+
if (Array.isArray(current)) {
|
|
1159
|
+
if (isLast) {
|
|
1160
|
+
for (let j = 0; j < current.length; j++) {
|
|
1161
|
+
current[j] = value;
|
|
1162
|
+
}
|
|
1163
|
+
} else {
|
|
1164
|
+
const nextSegment = segments[i + 1];
|
|
1165
|
+
for (let j = 0; j < current.length; j++) {
|
|
1166
|
+
if (!current[j]) {
|
|
1167
|
+
current[j] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
if (current.length > 0) {
|
|
1171
|
+
current = current[0];
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
break;
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
};
|
|
1179
|
+
|
|
1180
|
+
// src/lib/object/getter-setter.ts
|
|
1181
|
+
function get(obj, selector, options = {}) {
|
|
1182
|
+
const {
|
|
1183
|
+
preserveStructure,
|
|
1184
|
+
multiple,
|
|
1185
|
+
throwOnError = false,
|
|
1186
|
+
defaultValue,
|
|
1187
|
+
maxDepth = 20
|
|
1188
|
+
} = options;
|
|
1189
|
+
if (!obj || typeof obj !== "object") {
|
|
1190
|
+
return defaultValue;
|
|
1191
|
+
}
|
|
1192
|
+
if (!selector) {
|
|
1193
|
+
return obj;
|
|
1194
|
+
}
|
|
1195
|
+
if (Array.isArray(selector)) {
|
|
1196
|
+
if (preserveStructure) {
|
|
1197
|
+
const result2 = {};
|
|
1198
|
+
for (const sel of selector) {
|
|
1199
|
+
const value = get(obj, sel, { ...options, preserveStructure: false });
|
|
1200
|
+
if (value !== void 0) {
|
|
1201
|
+
mergeIntoStructure(result2, sel, value);
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
return result2;
|
|
1205
|
+
} else {
|
|
1206
|
+
return selector.map(
|
|
1207
|
+
(sel) => get(obj, sel, { ...options, preserveStructure: false })
|
|
1208
|
+
);
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
const segments = parseSelector(selector, { ...options, throwOnError });
|
|
1212
|
+
if (segments.length === 0) {
|
|
1213
|
+
return obj;
|
|
1214
|
+
}
|
|
1215
|
+
if (typeof preserveStructure === "undefined" || preserveStructure === false) {
|
|
1216
|
+
const v = ValueOfKey(obj, selector);
|
|
1217
|
+
if (multiple === false && Array.isArray(v)) {
|
|
1218
|
+
return v[0];
|
|
1219
|
+
}
|
|
1220
|
+
if (v === void 0 && defaultValue !== void 0) {
|
|
1221
|
+
return defaultValue;
|
|
1222
|
+
}
|
|
1223
|
+
return v;
|
|
1224
|
+
}
|
|
1225
|
+
const result = traverseStructure(obj, segments, 0, maxDepth);
|
|
1226
|
+
if (result === void 0 && defaultValue !== void 0) {
|
|
1227
|
+
return defaultValue;
|
|
1228
|
+
}
|
|
1229
|
+
return result;
|
|
1230
|
+
}
|
|
1231
|
+
function ValueOfKey(obj, selector, options = {}) {
|
|
1232
|
+
const { createMissing = false, add = false, debug = false } = options;
|
|
1233
|
+
const segments = parseSelector(selector);
|
|
1234
|
+
let current = obj;
|
|
1235
|
+
let updateEvenIfNotlast = false;
|
|
1236
|
+
let chained_property = "";
|
|
1237
|
+
const stringify = selector;
|
|
1238
|
+
if (typeof current === "object" && !Array.isArray(current) && stringify.length > 0) {
|
|
1239
|
+
if (current[stringify]) {
|
|
1240
|
+
current = current[stringify];
|
|
1241
|
+
return current;
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
for (let i = 0; i < segments.length; i++) {
|
|
1245
|
+
const segment = segments[i];
|
|
1246
|
+
const isLast = segments.length > 1 ? i === segments.length - 1 : false;
|
|
1247
|
+
if (current === null && !createMissing) {
|
|
1248
|
+
return void 0;
|
|
1249
|
+
}
|
|
1250
|
+
const nextSegment = segments[i + 1];
|
|
1251
|
+
switch (segment.type) {
|
|
1252
|
+
case "property":
|
|
1253
|
+
if (current && typeof current === "object") {
|
|
1254
|
+
if (Array.isArray(current)) {
|
|
1255
|
+
if (typeof segment.value === "number") {
|
|
1256
|
+
const index = segment.value;
|
|
1257
|
+
if (createMissing && index >= current.length) {
|
|
1258
|
+
for (let j = current.length; j <= index; j++) {
|
|
1259
|
+
current.push(void 0);
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
if (createMissing && (current[index] === null || current[index] === void 0) && (!isLast || updateEvenIfNotlast)) {
|
|
1263
|
+
if (nextSegment) {
|
|
1264
|
+
current[index] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
|
|
1265
|
+
} else {
|
|
1266
|
+
current[index] = null;
|
|
1267
|
+
}
|
|
1268
|
+
updateEvenIfNotlast = false;
|
|
1269
|
+
}
|
|
1270
|
+
current = current[index];
|
|
1271
|
+
if (nextSegment) {
|
|
1272
|
+
updateEvenIfNotlast = true;
|
|
1273
|
+
continue;
|
|
1274
|
+
}
|
|
1275
|
+
} else if (add) {
|
|
1276
|
+
current.push({
|
|
1277
|
+
[String(segment.value)]: null
|
|
1278
|
+
});
|
|
1279
|
+
} else {
|
|
1280
|
+
current = current.map((item) => item[String(segment.value)]);
|
|
1281
|
+
}
|
|
1282
|
+
if (nextSegment) {
|
|
1283
|
+
continue;
|
|
1284
|
+
}
|
|
1285
|
+
return filterDefined(current);
|
|
1286
|
+
} else {
|
|
1287
|
+
if (current[chained_property] && chained_property.split(".").length >= 2) {
|
|
1288
|
+
current = current[chained_property];
|
|
1289
|
+
continue;
|
|
1290
|
+
}
|
|
1291
|
+
if (createMissing && (current[String(segment.value)] === null || current[String(segment.value)] === void 0) && (!isLast || updateEvenIfNotlast)) {
|
|
1292
|
+
if (nextSegment) {
|
|
1293
|
+
current[String(segment.value)] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
|
|
1294
|
+
} else {
|
|
1295
|
+
current[String(segment.value)] = null;
|
|
1296
|
+
}
|
|
1297
|
+
updateEvenIfNotlast = false;
|
|
1298
|
+
current = current[String(segment.value)];
|
|
1299
|
+
if (nextSegment) {
|
|
1300
|
+
updateEvenIfNotlast = true;
|
|
1301
|
+
continue;
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
if (!current) {
|
|
1305
|
+
current = { [String(segment.value)]: null };
|
|
1306
|
+
} else {
|
|
1307
|
+
if (!current[String(segment.value)] && createMissing) {
|
|
1308
|
+
current[String(segment.value)] = null;
|
|
1309
|
+
}
|
|
1310
|
+
current = current[String(segment.value)];
|
|
1311
|
+
}
|
|
1312
|
+
if (nextSegment) {
|
|
1313
|
+
continue;
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
} else if (createMissing) {
|
|
1317
|
+
current = {};
|
|
1318
|
+
current[String(segment.value)] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" || options.type === "array" ? [] : {};
|
|
1319
|
+
current = current[String(segment.value)];
|
|
1320
|
+
} else {
|
|
1321
|
+
return void 0;
|
|
1322
|
+
}
|
|
1323
|
+
break;
|
|
1324
|
+
case "index":
|
|
1325
|
+
case "wildcard":
|
|
1326
|
+
if (Array.isArray(current)) {
|
|
1327
|
+
if (segment.type === "index") {
|
|
1328
|
+
const index = segment.value;
|
|
1329
|
+
if (index < 0) {
|
|
1330
|
+
current = current[current.length - Math.abs(index)];
|
|
1331
|
+
continue;
|
|
1332
|
+
}
|
|
1333
|
+
if (createMissing && (index >= current.length || current[index] == null || current[index] == void 0) && !isLast) {
|
|
1334
|
+
for (let j = current.length; j <= index; j++) {
|
|
1335
|
+
current.push(void 0);
|
|
1336
|
+
}
|
|
1337
|
+
if (nextSegment) {
|
|
1338
|
+
current[index] = nextSegment.type === "index" || nextSegment.type === "slice" || nextSegment.type === "union" || nextSegment.type === "wildcard" ? [] : {};
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
current = current[index];
|
|
1342
|
+
} else {
|
|
1343
|
+
if (!isLast) {
|
|
1344
|
+
continue;
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
} else if (createMissing) {
|
|
1348
|
+
const nextSegment2 = segments[i + 1];
|
|
1349
|
+
current = [];
|
|
1350
|
+
const index = segment.value;
|
|
1351
|
+
for (let j = 0; j <= index; j++) {
|
|
1352
|
+
current.push(void 0);
|
|
1353
|
+
}
|
|
1354
|
+
current[index] = nextSegment2.type === "index" || nextSegment2.type === "slice" || nextSegment2.type === "union" || nextSegment2.type === "wildcard" || options.type === "array" ? [] : {};
|
|
1355
|
+
current = current[index];
|
|
1356
|
+
} else {
|
|
1357
|
+
if (segment.type === "index" && typeof current === "object") {
|
|
1358
|
+
if (current && current[String(segment.value)] !== void 0) {
|
|
1359
|
+
current = current[String(segment.value)];
|
|
1360
|
+
continue;
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
if (typeof current === "object") {
|
|
1364
|
+
const values = Object.values(current);
|
|
1365
|
+
current = values;
|
|
1366
|
+
continue;
|
|
1367
|
+
}
|
|
1368
|
+
return void 0;
|
|
1369
|
+
}
|
|
1370
|
+
break;
|
|
1371
|
+
default:
|
|
1372
|
+
return void 0;
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
return filterDefined(current);
|
|
1376
|
+
}
|
|
1377
|
+
function filterDefined(obj) {
|
|
1378
|
+
if (Array.isArray(obj)) {
|
|
1379
|
+
return obj.filter((item) => typeof item !== "undefined");
|
|
1380
|
+
}
|
|
1381
|
+
return obj;
|
|
1382
|
+
}
|
|
1383
|
+
var deletePath = (obj, selector, options = {}) => {
|
|
1384
|
+
const { throwOnError = false } = options;
|
|
1385
|
+
if (Array.isArray(selector)) {
|
|
1386
|
+
return selector.map((sel) => deletePath(obj, sel, options));
|
|
1387
|
+
}
|
|
1388
|
+
const segments = parseSelector(selector, { throwOnError });
|
|
1389
|
+
if (segments.length === 0) {
|
|
1390
|
+
return false;
|
|
1391
|
+
}
|
|
1392
|
+
const lastSegment = segments[segments.length - 1];
|
|
1393
|
+
if (segments.some(
|
|
1394
|
+
(s) => s.type === "wildcard" || s.type === "slice" || s.type === "union"
|
|
1395
|
+
)) {
|
|
1396
|
+
const paths = getPaths(obj, selector, options);
|
|
1397
|
+
let deleted = false;
|
|
1398
|
+
for (const path of paths) {
|
|
1399
|
+
if (deleteSinglePath(obj, path)) {
|
|
1400
|
+
deleted = true;
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
return deleted;
|
|
1404
|
+
}
|
|
1405
|
+
let current = obj;
|
|
1406
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
1407
|
+
const segment = segments[i];
|
|
1408
|
+
if (current == null) {
|
|
1409
|
+
return false;
|
|
1410
|
+
}
|
|
1411
|
+
switch (segment.type) {
|
|
1412
|
+
case "property":
|
|
1413
|
+
current = current[String(segment.value)];
|
|
1414
|
+
break;
|
|
1415
|
+
case "index":
|
|
1416
|
+
if (!Array.isArray(current)) return false;
|
|
1417
|
+
const index = segment.value;
|
|
1418
|
+
if (index < 0 || index >= current.length) return false;
|
|
1419
|
+
current = current[index];
|
|
1420
|
+
break;
|
|
1421
|
+
default:
|
|
1422
|
+
return false;
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
if (current == null) {
|
|
1426
|
+
return false;
|
|
1427
|
+
}
|
|
1428
|
+
switch (lastSegment.type) {
|
|
1429
|
+
case "property":
|
|
1430
|
+
if (String(lastSegment.value) in current) {
|
|
1431
|
+
delete current[String(lastSegment.value)];
|
|
1432
|
+
return true;
|
|
1433
|
+
}
|
|
1434
|
+
break;
|
|
1435
|
+
case "index":
|
|
1436
|
+
if (!Array.isArray(current)) return false;
|
|
1437
|
+
const index = lastSegment.value;
|
|
1438
|
+
if (index >= 0 && index < current.length) {
|
|
1439
|
+
current.splice(index, 1);
|
|
1440
|
+
return true;
|
|
1441
|
+
}
|
|
1442
|
+
break;
|
|
1443
|
+
}
|
|
1444
|
+
return false;
|
|
1445
|
+
};
|
|
1446
|
+
var deleteSinglePath = (obj, selector) => {
|
|
1447
|
+
const segments = parseSelector(selector);
|
|
1448
|
+
if (segments.length === 0) {
|
|
1449
|
+
return false;
|
|
1450
|
+
}
|
|
1451
|
+
const lastSegment = segments[segments.length - 1];
|
|
1452
|
+
let current = obj;
|
|
1453
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
1454
|
+
const segment = segments[i];
|
|
1455
|
+
if (current == null) {
|
|
1456
|
+
return false;
|
|
1457
|
+
}
|
|
1458
|
+
switch (segment.type) {
|
|
1459
|
+
case "property":
|
|
1460
|
+
current = current[String(segment.value)];
|
|
1461
|
+
break;
|
|
1462
|
+
case "index":
|
|
1463
|
+
if (!Array.isArray(current)) return false;
|
|
1464
|
+
const index = segment.value;
|
|
1465
|
+
if (index < 0 || index >= current.length) return false;
|
|
1466
|
+
current = current[index];
|
|
1467
|
+
break;
|
|
1468
|
+
default:
|
|
1469
|
+
return false;
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
if (current == null) {
|
|
1473
|
+
return false;
|
|
1474
|
+
}
|
|
1475
|
+
switch (lastSegment.type) {
|
|
1476
|
+
case "property":
|
|
1477
|
+
if (String(lastSegment.value) in current) {
|
|
1478
|
+
delete current[String(lastSegment.value)];
|
|
1479
|
+
return true;
|
|
1480
|
+
}
|
|
1481
|
+
break;
|
|
1482
|
+
case "index":
|
|
1483
|
+
if (!Array.isArray(current)) return false;
|
|
1484
|
+
const index = lastSegment.value;
|
|
1485
|
+
if (index >= 0 && index < current.length) {
|
|
1486
|
+
current.splice(index, 1);
|
|
1487
|
+
return true;
|
|
1488
|
+
}
|
|
1489
|
+
break;
|
|
1490
|
+
}
|
|
1491
|
+
return false;
|
|
1492
|
+
};
|
|
1493
|
+
var getPaths = (obj, selector, options = {}) => {
|
|
1494
|
+
const { format = "selector", maxDepth = 20 } = options;
|
|
1495
|
+
if (selector && Array.isArray(selector)) {
|
|
1496
|
+
const allPaths2 = [];
|
|
1497
|
+
for (const sel of selector) {
|
|
1498
|
+
const paths = getPaths(obj, sel, options);
|
|
1499
|
+
allPaths2.push(...paths);
|
|
1500
|
+
}
|
|
1501
|
+
return allPaths2;
|
|
1502
|
+
}
|
|
1503
|
+
if (selector) {
|
|
1504
|
+
const segments = parseSelector(selector, options);
|
|
1505
|
+
const results = traverseWithPaths(obj, segments, 0, maxDepth);
|
|
1506
|
+
return results.map(
|
|
1507
|
+
(r) => format === "selector" ? r.path : r.stringPath
|
|
1508
|
+
);
|
|
1509
|
+
}
|
|
1510
|
+
const allPaths = [];
|
|
1511
|
+
const traverseAll = (current, path = [], stringPath = [], depth = 0) => {
|
|
1512
|
+
if (depth > maxDepth) return;
|
|
1513
|
+
if (path.length > 0) {
|
|
1514
|
+
const pathStr = stringifySelector(path);
|
|
1515
|
+
allPaths.push({ path: pathStr, stringPath: stringPath.join(".") });
|
|
1516
|
+
}
|
|
1517
|
+
if (current && typeof current === "object") {
|
|
1518
|
+
if (Array.isArray(current)) {
|
|
1519
|
+
for (let i = 0; i < current.length; i++) {
|
|
1520
|
+
traverseAll(
|
|
1521
|
+
current[i],
|
|
1522
|
+
[...path, { type: "index", value: i, raw: `[${i}]` }],
|
|
1523
|
+
[...stringPath, `[${i}]`],
|
|
1524
|
+
depth + 1
|
|
1525
|
+
);
|
|
1526
|
+
}
|
|
1527
|
+
} else {
|
|
1528
|
+
for (const key in current) {
|
|
1529
|
+
if (current.hasOwnProperty(key)) {
|
|
1530
|
+
traverseAll(
|
|
1531
|
+
current[key],
|
|
1532
|
+
[...path, { type: "property", value: key, raw: key }],
|
|
1533
|
+
[...stringPath, key],
|
|
1534
|
+
depth + 1
|
|
1535
|
+
);
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
};
|
|
1541
|
+
traverseAll(obj);
|
|
1542
|
+
return allPaths.map(
|
|
1543
|
+
(p) => format === "selector" ? p.path : p.stringPath
|
|
1544
|
+
);
|
|
1545
|
+
};
|
|
1546
|
+
function traverseWithPaths(current, segments, depth, maxDepth, currentPath = [], currentStringPath = []) {
|
|
1547
|
+
if (depth > maxDepth) return [];
|
|
1548
|
+
if (segments.length === 0)
|
|
1549
|
+
return [
|
|
1550
|
+
{
|
|
1551
|
+
value: current,
|
|
1552
|
+
path: stringifySelector(currentPath),
|
|
1553
|
+
stringPath: currentStringPath.join(".")
|
|
1554
|
+
}
|
|
1555
|
+
];
|
|
1556
|
+
const segment = segments[0];
|
|
1557
|
+
const remaining = segments.slice(1);
|
|
1558
|
+
const results = [];
|
|
1559
|
+
if (segment.type === "descendant") {
|
|
1560
|
+
results.push(
|
|
1561
|
+
...traverseWithPaths(
|
|
1562
|
+
current,
|
|
1563
|
+
remaining,
|
|
1564
|
+
depth + 1,
|
|
1565
|
+
maxDepth,
|
|
1566
|
+
currentPath,
|
|
1567
|
+
currentStringPath
|
|
1568
|
+
)
|
|
1569
|
+
);
|
|
1570
|
+
if (current && typeof current === "object") {
|
|
1571
|
+
if (Array.isArray(current)) {
|
|
1572
|
+
for (let i = 0; i < current.length; i++) {
|
|
1573
|
+
results.push(
|
|
1574
|
+
...traverseWithPaths(
|
|
1575
|
+
current[i],
|
|
1576
|
+
segments,
|
|
1577
|
+
// Use same segments for recursion
|
|
1578
|
+
depth + 1,
|
|
1579
|
+
maxDepth,
|
|
1580
|
+
[...currentPath, { type: "index", value: i, raw: `[${i}]` }],
|
|
1581
|
+
[...currentStringPath, `[${i}]`]
|
|
1582
|
+
)
|
|
1583
|
+
);
|
|
1584
|
+
}
|
|
1585
|
+
} else {
|
|
1586
|
+
for (const key in current) {
|
|
1587
|
+
if (current.hasOwnProperty(key)) {
|
|
1588
|
+
results.push(
|
|
1589
|
+
...traverseWithPaths(
|
|
1590
|
+
current[key],
|
|
1591
|
+
segments,
|
|
1592
|
+
depth + 1,
|
|
1593
|
+
maxDepth,
|
|
1594
|
+
[...currentPath, { type: "property", value: key, raw: key }],
|
|
1595
|
+
[...currentStringPath, key]
|
|
1596
|
+
)
|
|
1597
|
+
);
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
return results;
|
|
1603
|
+
}
|
|
1604
|
+
switch (segment.type) {
|
|
1605
|
+
case "property":
|
|
1606
|
+
if (current && typeof current === "object" && String(segment.value) in current) {
|
|
1607
|
+
const next = current[String(segment.value)];
|
|
1608
|
+
results.push(
|
|
1609
|
+
...traverseWithPaths(
|
|
1610
|
+
next,
|
|
1611
|
+
remaining,
|
|
1612
|
+
depth + 1,
|
|
1613
|
+
maxDepth,
|
|
1614
|
+
[...currentPath, segment],
|
|
1615
|
+
[...currentStringPath, String(segment.value)]
|
|
1616
|
+
)
|
|
1617
|
+
);
|
|
1618
|
+
}
|
|
1619
|
+
break;
|
|
1620
|
+
case "index":
|
|
1621
|
+
if (Array.isArray(current)) {
|
|
1622
|
+
const index = segment.value;
|
|
1623
|
+
if (index >= 0 && index < current.length) {
|
|
1624
|
+
results.push(
|
|
1625
|
+
...traverseWithPaths(
|
|
1626
|
+
current[index],
|
|
1627
|
+
remaining,
|
|
1628
|
+
depth + 1,
|
|
1629
|
+
maxDepth,
|
|
1630
|
+
[...currentPath, segment],
|
|
1631
|
+
[...currentStringPath, `[${index}]`]
|
|
1632
|
+
)
|
|
1633
|
+
);
|
|
1634
|
+
}
|
|
1635
|
+
} else if (current && typeof current === "object") {
|
|
1636
|
+
const key = String(segment.value);
|
|
1637
|
+
if (key in current) {
|
|
1638
|
+
results.push(
|
|
1639
|
+
...traverseWithPaths(
|
|
1640
|
+
current[key],
|
|
1641
|
+
remaining,
|
|
1642
|
+
depth + 1,
|
|
1643
|
+
maxDepth,
|
|
1644
|
+
[...currentPath, { ...segment, type: "property" }],
|
|
1645
|
+
[...currentStringPath, key]
|
|
1646
|
+
)
|
|
1647
|
+
);
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
break;
|
|
1651
|
+
case "wildcard":
|
|
1652
|
+
if (current && typeof current === "object") {
|
|
1653
|
+
if (Array.isArray(current)) {
|
|
1654
|
+
for (let i = 0; i < current.length; i++) {
|
|
1655
|
+
results.push(
|
|
1656
|
+
...traverseWithPaths(
|
|
1657
|
+
current[i],
|
|
1658
|
+
remaining,
|
|
1659
|
+
depth + 1,
|
|
1660
|
+
maxDepth,
|
|
1661
|
+
[...currentPath, { type: "index", value: i, raw: `[${i}]` }],
|
|
1662
|
+
[...currentStringPath, `[${i}]`]
|
|
1663
|
+
)
|
|
1664
|
+
);
|
|
1665
|
+
}
|
|
1666
|
+
} else {
|
|
1667
|
+
for (const key in current) {
|
|
1668
|
+
if (current.hasOwnProperty(key)) {
|
|
1669
|
+
results.push(
|
|
1670
|
+
...traverseWithPaths(
|
|
1671
|
+
current[key],
|
|
1672
|
+
remaining,
|
|
1673
|
+
depth + 1,
|
|
1674
|
+
maxDepth,
|
|
1675
|
+
[...currentPath, { type: "property", value: key, raw: key }],
|
|
1676
|
+
[...currentStringPath, key]
|
|
1677
|
+
)
|
|
1678
|
+
);
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
}
|
|
1683
|
+
break;
|
|
1684
|
+
case "slice":
|
|
1685
|
+
if (Array.isArray(current)) {
|
|
1686
|
+
const [start, end] = segment.value;
|
|
1687
|
+
const actualStart = Math.max(0, start);
|
|
1688
|
+
const actualEnd = Math.min(
|
|
1689
|
+
current.length,
|
|
1690
|
+
end === Infinity ? current.length : end
|
|
1691
|
+
);
|
|
1692
|
+
for (let i = actualStart; i < actualEnd; i++) {
|
|
1693
|
+
results.push(
|
|
1694
|
+
...traverseWithPaths(
|
|
1695
|
+
current[i],
|
|
1696
|
+
remaining,
|
|
1697
|
+
depth + 1,
|
|
1698
|
+
maxDepth,
|
|
1699
|
+
[...currentPath, { type: "index", value: i, raw: `[${i}]` }],
|
|
1700
|
+
[...currentStringPath, `[${i}]`]
|
|
1701
|
+
)
|
|
1702
|
+
);
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
break;
|
|
1706
|
+
case "union":
|
|
1707
|
+
if (Array.isArray(current)) {
|
|
1708
|
+
const indices = segment.value;
|
|
1709
|
+
for (const index of indices) {
|
|
1710
|
+
if (index >= 0 && index < current.length) {
|
|
1711
|
+
results.push(
|
|
1712
|
+
...traverseWithPaths(
|
|
1713
|
+
current[index],
|
|
1714
|
+
remaining,
|
|
1715
|
+
depth + 1,
|
|
1716
|
+
maxDepth,
|
|
1717
|
+
[
|
|
1718
|
+
...currentPath,
|
|
1719
|
+
{ type: "index", value: index, raw: `[${index}]` }
|
|
1720
|
+
],
|
|
1721
|
+
[...currentStringPath, `[${index}]`]
|
|
1722
|
+
)
|
|
1723
|
+
);
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
break;
|
|
1728
|
+
case "filter":
|
|
1729
|
+
if (Array.isArray(current)) {
|
|
1730
|
+
const filterFn = segment.value;
|
|
1731
|
+
for (let i = 0; i < current.length; i++) {
|
|
1732
|
+
if (filterFn(current[i])) {
|
|
1733
|
+
results.push(
|
|
1734
|
+
...traverseWithPaths(
|
|
1735
|
+
current[i],
|
|
1736
|
+
remaining,
|
|
1737
|
+
depth + 1,
|
|
1738
|
+
maxDepth,
|
|
1739
|
+
[...currentPath, { type: "index", value: i, raw: `[${i}]` }],
|
|
1740
|
+
[...currentStringPath, `[${i}]`]
|
|
1741
|
+
)
|
|
1742
|
+
);
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
break;
|
|
1747
|
+
}
|
|
1748
|
+
return results;
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
// src/lib/object/omit.ts
|
|
1752
|
+
function omit(obj, keys) {
|
|
1753
|
+
if (!isObject(obj)) {
|
|
1754
|
+
return {};
|
|
1755
|
+
}
|
|
1756
|
+
const result = { ...obj };
|
|
1757
|
+
for (const key of keys) {
|
|
1758
|
+
delete result[key];
|
|
1759
|
+
}
|
|
1760
|
+
return result;
|
|
1761
|
+
}
|
|
1762
|
+
function deepOmit(obj, keys) {
|
|
1763
|
+
if (obj === null || obj === void 0 || typeof obj !== "object") {
|
|
1764
|
+
return obj;
|
|
1765
|
+
}
|
|
1766
|
+
if (Array.isArray(obj)) {
|
|
1767
|
+
return obj.map((item) => deepOmit(item, keys));
|
|
1768
|
+
}
|
|
1769
|
+
const result = {};
|
|
1770
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
1771
|
+
if (!keys.includes(key)) {
|
|
1772
|
+
result[key] = deepOmit(value, keys);
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
return result;
|
|
1776
|
+
}
|
|
1777
|
+
function createOmitter(keys) {
|
|
1778
|
+
return (obj) => {
|
|
1779
|
+
if (!isObject(obj)) {
|
|
1780
|
+
return {};
|
|
1781
|
+
}
|
|
1782
|
+
const result = { ...obj };
|
|
1783
|
+
for (const key of keys) {
|
|
1784
|
+
if (key in result) {
|
|
1785
|
+
delete result[key];
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
return result;
|
|
1789
|
+
};
|
|
1790
|
+
}
|
|
1791
|
+
function omitBy(obj, predicate) {
|
|
1792
|
+
if (!isObject(obj)) {
|
|
1793
|
+
return {};
|
|
1794
|
+
}
|
|
1795
|
+
const result = {};
|
|
1796
|
+
for (const key in obj) {
|
|
1797
|
+
if (Object.prototype.hasOwnProperty.call(obj, key) && !predicate(obj[key], key, obj)) {
|
|
1798
|
+
result[key] = obj[key];
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
return result;
|
|
1802
|
+
}
|
|
1803
|
+
function omitNil(obj) {
|
|
1804
|
+
return omitBy(obj, (value) => value === null || value === void 0);
|
|
1805
|
+
}
|
|
1806
|
+
function pick(obj, keys) {
|
|
1807
|
+
if (!isObject(obj)) {
|
|
1808
|
+
return {};
|
|
1809
|
+
}
|
|
1810
|
+
const result = {};
|
|
1811
|
+
for (const key of keys) {
|
|
1812
|
+
if (key in obj) {
|
|
1813
|
+
result[key] = obj[key];
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
return result;
|
|
1817
|
+
}
|
|
1818
|
+
function pickBy(obj, predicate) {
|
|
1819
|
+
if (!isObject(obj)) {
|
|
1820
|
+
return {};
|
|
1821
|
+
}
|
|
1822
|
+
const result = {};
|
|
1823
|
+
for (const key in obj) {
|
|
1824
|
+
if (Object.prototype.hasOwnProperty.call(obj, key) && predicate(obj[key], key, obj)) {
|
|
1825
|
+
result[key] = obj[key];
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
return result;
|
|
1829
|
+
}
|
|
1830
|
+
function omitPath(obj, paths, transform) {
|
|
1831
|
+
if (!isObject(obj)) {
|
|
1832
|
+
return {};
|
|
1833
|
+
}
|
|
1834
|
+
const result = JSON.parse(JSON.stringify(obj));
|
|
1835
|
+
const pathArray = Array.isArray(paths) ? paths : [paths];
|
|
1836
|
+
for (let i = 0; i < pathArray.length; i++) {
|
|
1837
|
+
const path = pathArray[i];
|
|
1838
|
+
const nextPath = pathArray[i + 1];
|
|
1839
|
+
if (!path || path === "") continue;
|
|
1840
|
+
const segments = parseSelector(path);
|
|
1841
|
+
if (path.includes("*") || path.includes("[") || segments.length > 1) {
|
|
1842
|
+
let collectPaths2 = function(obj2, currentPath = "") {
|
|
1843
|
+
if (!isObject(obj2)) return;
|
|
1844
|
+
if (Array.isArray(obj2)) {
|
|
1845
|
+
obj2.forEach((item, index) => {
|
|
1846
|
+
collectPaths2(
|
|
1847
|
+
item,
|
|
1848
|
+
currentPath ? `${currentPath}[${index}]` : `[${index}]`
|
|
1849
|
+
);
|
|
1850
|
+
});
|
|
1851
|
+
return;
|
|
1852
|
+
}
|
|
1853
|
+
for (const key in obj2) {
|
|
1854
|
+
if (Object.prototype.hasOwnProperty.call(obj2, key)) {
|
|
1855
|
+
const fullPath = currentPath ? `${currentPath}.${key}` : key;
|
|
1856
|
+
pathsToProcess.push({
|
|
1857
|
+
fullPath,
|
|
1858
|
+
segments: parseSelector(fullPath)
|
|
1859
|
+
});
|
|
1860
|
+
collectPaths2(obj2[key], fullPath);
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
};
|
|
1864
|
+
var collectPaths = collectPaths2;
|
|
1865
|
+
const value = get(result, path, { preserveStructure: true });
|
|
1866
|
+
if (value === void 0) {
|
|
1867
|
+
continue;
|
|
1868
|
+
}
|
|
1869
|
+
const pathsToProcess = [];
|
|
1870
|
+
collectPaths2(value);
|
|
1871
|
+
for (const { fullPath, segments: pathSegments } of pathsToProcess) {
|
|
1872
|
+
const pathSegmentsCopy = [...pathSegments];
|
|
1873
|
+
const lastSegment = pathSegmentsCopy.pop();
|
|
1874
|
+
if (!lastSegment) continue;
|
|
1875
|
+
const parentPath = pathSegmentsCopy.map((s) => {
|
|
1876
|
+
if (s.type === "index") return `[${s.value}]`;
|
|
1877
|
+
return s.value;
|
|
1878
|
+
}).join(".").replace(/\.\[/g, "[");
|
|
1879
|
+
const fg = get(result, parentPath.length > 0 ? parentPath : fullPath, {
|
|
1880
|
+
preserveStructure: true
|
|
1881
|
+
});
|
|
1882
|
+
let parent = parentPath ? fg : result;
|
|
1883
|
+
if (!parent) {
|
|
1884
|
+
continue;
|
|
1885
|
+
}
|
|
1886
|
+
const propertyKey = String(lastSegment.value);
|
|
1887
|
+
const currentValue = parent[propertyKey];
|
|
1888
|
+
if (transform) {
|
|
1889
|
+
const transformResult = transform(currentValue, fullPath, result);
|
|
1890
|
+
if (transformResult === true) {
|
|
1891
|
+
if (lastSegment.type === "index" && Array.isArray(parent)) {
|
|
1892
|
+
const index = lastSegment.value;
|
|
1893
|
+
if (index >= 0 && index < parent.length) {
|
|
1894
|
+
parent.splice(index, 1);
|
|
1895
|
+
}
|
|
1896
|
+
} else {
|
|
1897
|
+
deletePath(result, pathArray[i]);
|
|
1898
|
+
}
|
|
1899
|
+
} else if (transformResult !== false) {
|
|
1900
|
+
parent[propertyKey] = transformResult;
|
|
1901
|
+
}
|
|
1902
|
+
} else {
|
|
1903
|
+
if (lastSegment.type === "index" && Array.isArray(parent)) {
|
|
1904
|
+
const index = lastSegment.value;
|
|
1905
|
+
if (index >= 0 && index < parent.length) {
|
|
1906
|
+
parent.splice(index, 1);
|
|
1907
|
+
}
|
|
1908
|
+
} else {
|
|
1909
|
+
deletePath(result, pathArray[i]);
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
} else {
|
|
1914
|
+
const key = path;
|
|
1915
|
+
if (typeof key === "string" && key in result) {
|
|
1916
|
+
if (transform) {
|
|
1917
|
+
const transformResult = transform(result[key], path, result);
|
|
1918
|
+
if (transformResult === true) {
|
|
1919
|
+
delete result[key];
|
|
1920
|
+
} else if (transformResult !== false) {
|
|
1921
|
+
result[key] = transformResult;
|
|
1922
|
+
}
|
|
1923
|
+
} else {
|
|
1924
|
+
deletePath(result, pathArray[i]);
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
return result;
|
|
1930
|
+
}
|
|
1931
|
+
function pickPath(obj, paths, transform) {
|
|
1932
|
+
if (!isObject(obj)) {
|
|
1933
|
+
return {};
|
|
1934
|
+
}
|
|
1935
|
+
if (Array.isArray(paths)) {
|
|
1936
|
+
const result = {};
|
|
1937
|
+
for (const path of paths) {
|
|
1938
|
+
const pathValue = get(obj, path, { preserveStructure: true });
|
|
1939
|
+
if (pathValue === void 0) {
|
|
1940
|
+
continue;
|
|
1941
|
+
}
|
|
1942
|
+
if (transform) {
|
|
1943
|
+
const transformValue = (value2, currentPath) => {
|
|
1944
|
+
if (isObject(value2)) {
|
|
1945
|
+
if (Array.isArray(value2)) {
|
|
1946
|
+
return value2.map(
|
|
1947
|
+
(item, index) => transformValue(item, `${currentPath}[${index}]`)
|
|
1948
|
+
);
|
|
1949
|
+
}
|
|
1950
|
+
const result2 = {};
|
|
1951
|
+
for (const key in value2) {
|
|
1952
|
+
if (Object.prototype.hasOwnProperty.call(value2, key)) {
|
|
1953
|
+
const nestedPath = currentPath ? `${currentPath}.${key}` : key;
|
|
1954
|
+
result2[key] = transformValue(value2[key], nestedPath);
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
return result2;
|
|
1958
|
+
}
|
|
1959
|
+
return transform(value2, currentPath, obj);
|
|
1960
|
+
};
|
|
1961
|
+
const transformedValue = transformValue(pathValue, path);
|
|
1962
|
+
deepMergeKeepReference(result, transformedValue);
|
|
1963
|
+
} else {
|
|
1964
|
+
Object.assign(result, deepMergeKeepReference(result, pathValue));
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
return result;
|
|
1968
|
+
}
|
|
1969
|
+
const pathString = Array.isArray(paths) ? paths[0] : paths;
|
|
1970
|
+
const value = get(obj, pathString, { preserveStructure: true });
|
|
1971
|
+
if (value === void 0) {
|
|
1972
|
+
return {};
|
|
1973
|
+
}
|
|
1974
|
+
if (transform) {
|
|
1975
|
+
const transformValue = (value2, currentPath) => {
|
|
1976
|
+
if (isObject(value2)) {
|
|
1977
|
+
if (Array.isArray(value2)) {
|
|
1978
|
+
return value2.map(
|
|
1979
|
+
(item, index) => transformValue(item, `${currentPath}[${index}]`)
|
|
1980
|
+
);
|
|
1981
|
+
}
|
|
1982
|
+
const result = {};
|
|
1983
|
+
for (const key in value2) {
|
|
1984
|
+
if (Object.prototype.hasOwnProperty.call(value2, key)) {
|
|
1985
|
+
const nestedPath = currentPath ? `${currentPath}.${key}` : key;
|
|
1986
|
+
result[key] = transformValue(value2[key], nestedPath);
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
return result;
|
|
1990
|
+
}
|
|
1991
|
+
return transform(value2, currentPath, obj);
|
|
1992
|
+
};
|
|
1993
|
+
return transformValue(value, pathString);
|
|
1994
|
+
}
|
|
1995
|
+
return value;
|
|
1996
|
+
}
|
|
1997
|
+
function deepOmitBy(obj, predicate) {
|
|
1998
|
+
if (!isObject(obj)) {
|
|
1999
|
+
return obj;
|
|
2000
|
+
}
|
|
2001
|
+
if (Array.isArray(obj)) {
|
|
2002
|
+
return obj.map((item) => deepOmitBy(item, predicate));
|
|
2003
|
+
}
|
|
2004
|
+
const result = {};
|
|
2005
|
+
for (const key in obj) {
|
|
2006
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
2007
|
+
continue;
|
|
2008
|
+
}
|
|
2009
|
+
const value = obj[key];
|
|
2010
|
+
if (predicate(value, key, obj)) {
|
|
2011
|
+
continue;
|
|
2012
|
+
}
|
|
2013
|
+
if (isObject(value)) {
|
|
2014
|
+
result[key] = deepOmitBy(value, predicate);
|
|
2015
|
+
} else if (Array.isArray(value)) {
|
|
2016
|
+
result[key] = value.map((item) => deepOmitBy(item, predicate));
|
|
2017
|
+
} else {
|
|
2018
|
+
result[key] = value;
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
return result;
|
|
2022
|
+
}
|