ray-template/js/deep-pick-omit@1.2.1-B1UrSIxj.js

2 lines
1.1 KiB
JavaScript

function u(r,n){if(r==null)return;let e=r;for(let t=0;t<n.length;t++){if(e==null||e[n[t]]==null)return;e=e[n[t]]}return e}function i(r,n,e){if(e.length===0)return n;const t=e[0];return e.length>1&&(n=i(typeof r!="object"||r===null||!Object.prototype.hasOwnProperty.call(r,t)?Number.isInteger(Number(e[1]))?[]:{}:r[t],n,Array.prototype.slice.call(e,1))),Number.isInteger(Number(t))&&Array.isArray(r)?r.slice()[t]:Object.assign({},r,{[t]:n})}function l(r,n){if(r==null||n.length===0)return r;if(n.length===1){if(r==null)return r;if(Number.isInteger(n[0])&&Array.isArray(r))return Array.prototype.slice.call(r,0).splice(n[0],1);const e={};for(const t in r)e[t]=r[t];return delete e[n[0]],e}if(r[n[0]]==null){if(Number.isInteger(n[0])&&Array.isArray(r))return Array.prototype.concat.call([],r);const e={};for(const t in r)e[t]=r[t];return e}return i(r,l(r[n[0]],Array.prototype.slice.call(n,1)),[n[0]])}function s(r,n){return n.map(e=>e.split(".")).map(e=>[e,u(r,e)]).filter(e=>e[1]!==void 0).reduce((e,t)=>i(e,t[1],t[0]),{})}function c(r,n){return n.map(e=>e.split(".")).reduce((e,t)=>l(e,t),r)}export{c as a,s as d};