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

Function parseJsonPath

Rewrite-Parser.beta.js:2884–2903  ·  view source on GitHub ↗
(_path)

Source from the content-addressed store, hash-verified

2882 }
2883}
2884function parseJsonPath(_path) {
2885 const path = _path.trim()
2886 const output = []
2887 const regex = /\.?([^\.\[\]]+)|\[(['"])(.*?)\2\]|\[(\d+)\]/g
2888 let match
2889
2890 while ((match = regex.exec(path)) !== null) {
2891 if (match[1] !== undefined) {
2892 // 匹配点符号或初始键
2893 output.push(match[1])
2894 } else if (match[3] !== undefined) {
2895 // 匹配带引号的括号表示法
2896 output.push(match[3])
2897 } else if (match[4] !== undefined) {
2898 // 数组索引,转换为整数
2899 output.push(parseInt(match[4], 10))
2900 }
2901 }
2902 return output
2903}
2904
2905// 解析规则
2906function parseRule(input) {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected