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

Function parseJsonPath

scripts/body-rewrite.js:87–106  ·  view source on GitHub ↗
(_path)

Source from the content-addressed store, hash-verified

85 $.done(result)
86 })
87function parseJsonPath(_path) {
88 const path = _path.trim()
89 const output = []
90 const regex = /\.?([^\.\[\]]+)|\[(['"])(.*?)\2\]|\[(\d+)\]/g
91 let match
92
93 while ((match = regex.exec(path)) !== null) {
94 if (match[1] !== undefined) {
95 // 匹配点符号或初始键
96 output.push(match[1])
97 } else if (match[3] !== undefined) {
98 // 匹配带引号的括号表示法
99 output.push(match[3])
100 } else if (match[4] !== undefined) {
101 // 数组索引,转换为整数
102 output.push(parseInt(match[4], 10))
103 }
104 }
105 return output
106}
107function unset(object, path) {
108 if (object == null) {
109 return true

Callers 1

unsetFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected