MCPcopy
hub / github.com/baidu/amis / deepRemove

Function deepRemove

packages/amis-editor/src/plugin/CRUD2/utils.ts:27–69  ·  view source on GitHub ↗
(
  obj: any,
  predicate: (obj: any) => boolean,
  checkAll: boolean = false
)

Source from the content-addressed store, hash-verified

25
26/** 深度删除 */
27export 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
71export const findObj = (
72 obj: any,

Callers 4

Table2PluginClass · 0.90
updateFuzzyQueryMethod · 0.90
handleDeleteMethod · 0.90

Calls 5

removeFunction · 0.85
forEachMethod · 0.80
entriesMethod · 0.80
pushMethod · 0.65
isObjectFunction · 0.50

Tested by

no test coverage detected