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

Function parseJsonPath

Rewrite-Parser.js:2472–2491  ·  view source on GitHub ↗
(_path)

Source from the content-addressed store, hash-verified

2470 }
2471}
2472function parseJsonPath(_path) {
2473 const path = _path.trim()
2474 const output = []
2475 const regex = /\.?([^\.\[\]]+)|\[(['"])(.*?)\2\]|\[(\d+)\]/g
2476 let match
2477
2478 while ((match = regex.exec(path)) !== null) {
2479 if (match[1] !== undefined) {
2480 // 匹配点符号或初始键
2481 output.push(match[1])
2482 } else if (match[3] !== undefined) {
2483 // 匹配带引号的括号表示法
2484 output.push(match[3])
2485 } else if (match[4] !== undefined) {
2486 // 数组索引,转换为整数
2487 output.push(parseInt(match[4], 10))
2488 }
2489 }
2490 return output
2491}
2492
2493// 解析规则
2494function parseRule(input) {

Callers 1

Rewrite-Parser.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected