( obj: any, predicate: (obj: any) => boolean, checkAll: boolean = false )
| 25 | |
| 26 | /** 深度删除 */ |
| 27 | export const deepRemove = ( |
| 28 | obj: any, |
| 29 | predicate: (obj: any) => boolean, |
| 30 | checkAll: boolean = false |
| 31 | ): any => { |
| 32 | const waitProcess = [obj]; |
| 33 | let find = false; |
| 34 | |
| 35 | while (waitProcess.length) { |
| 36 | if (find) { |
| 37 | break; |
| 38 | } |
| 39 | |
| 40 | let item: any = waitProcess.pop(); |
| 41 | if (Array.isArray(item)) { |
| 42 | remove(item as any, (val: any) => { |
| 43 | const res = predicate(val); |
| 44 | |
| 45 | if (res && !checkAll) { |
| 46 | find = true; |
| 47 | } |
| 48 | |
| 49 | return res; |
| 50 | }); |
| 51 | waitProcess.push(...item); |
| 52 | continue; |
| 53 | } |
| 54 | |
| 55 | if (!isObject(item)) { |
| 56 | continue; |
| 57 | } |
| 58 | |
| 59 | Object.entries(item).forEach(([key, value]) => { |
| 60 | if (isObject(value) && predicate(value)) { |
| 61 | delete (item as any)[key]; |
| 62 | checkAll || (find = true); |
| 63 | } |
| 64 | waitProcess.push(value); |
| 65 | }); |
| 66 | } |
| 67 | |
| 68 | return find; |
| 69 | }; |
| 70 | |
| 71 | export const findObj = ( |
| 72 | obj: any, |
no test coverage detected