MCPcopy Create free account
hub / github.com/Script-Hub-Org/Script-Hub / unset

Function unset

scripts/body-rewrite.js:107–140  ·  view source on GitHub ↗
(object, path)

Source from the content-addressed store, hash-verified

105 return output
106}
107function unset(object, path) {
108 if (object == null) {
109 return true
110 }
111
112 const paths = parseJsonPath(path)
113
114 var current = object
115 for (var i = 0; i < paths.length - 1; i++) {
116 var key = paths[i]
117 if (!(key in current)) {
118 return true
119 }
120 current = current[key]
121 if (current == null) {
122 return true
123 }
124 }
125
126 var finalKey = paths[paths.length - 1]
127
128 // 处理数组的情况
129 if (Array.isArray(current)) {
130 var index = parseInt(finalKey, 10)
131 if (!isNaN(index)) {
132 current.splice(index, 1)
133 return true
134 }
135 }
136
137 // 处理对象的属性删除
138 delete current[finalKey]
139 return true
140}
141// 通知
142async function notify(title, subt, desc, opts) {
143 $.msg(title, subt, desc, opts)

Callers 1

body-rewrite.jsFile · 0.85

Calls 1

parseJsonPathFunction · 0.70

Tested by

no test coverage detected