(path: string)
| 92 | * @throws {PathError} 如果路径无效 |
| 93 | */ |
| 94 | export function parseJsonPointer(path: string): string[] { |
| 95 | if (!isValidJsonPointer(path)) { |
| 96 | throw new PathError( |
| 97 | `Invalid JSON Pointer: "${path}". Path must be empty or start with "/"`, |
| 98 | PathErrorCodes.INVALID_PATH, |
| 99 | { path }, |
| 100 | ); |
| 101 | } |
| 102 | |
| 103 | // 空字符串表示根路径 |
| 104 | if (path === '') { |
| 105 | return []; |
| 106 | } |
| 107 | |
| 108 | // 移除开头的 "/" 并分割 |
| 109 | const tokens = path.slice(1).split('/'); |
| 110 | |
| 111 | // 解码每个路径段 |
| 112 | return tokens.map(decodeJsonPointerToken); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * 将路径段数组转换为 JSON Pointer 路径 |
no test coverage detected