UNPKG

@jecloud/utils

Version:

JECloud 工具库

1 lines 817 B
import{forEach as n,isArray as r}from"./lodash";var t=function(n){return function(r,t,c,a){var i=c||{},o=i.children||"children";return n(null,r,t,a,[],[],o,i)}};function c(n,r,t,a,i,o,e,u){var l,f,v,d,h,m;if(r)for(f=0,v=r.length;f<v;f++){if(l=r[f],d=i.concat([""+f]),h=o.concat([l]),t.call(a,l,f,r,d,n,h))return{index:f,item:l,path:d,items:r,parent:n,nodes:h};if(e&&l&&(m=c(l,l[e],t,a,d.concat([e]),h,e,u)))return m}}var a=t(c);function i(n,r,t,c,a,o,e,u){var l,f,v,d=u.mapChildren||e;return r.map((function(h,m){return l=a.concat([""+m]),f=o.concat([h]),(v=t.call(c,h,m,r,l,n,f))&&h&&e&&h[e]&&(v[d]=i(h,h[e],t,c,l,f,e,u)),v}))}var o=t(i),e=function(t,c){var a=r(t)?t:[t];n(a,(function(n){var r;if(!1===c(n))return!1;e(null!==(r=n.children)&&void 0!==r?r:[],c)}))};export{a as findTree,o as mapTree,e as cascadeTree};