(basePath: string, relativePath: string)
| 561 | * @returns 合并后的路径 |
| 562 | */ |
| 563 | export function joinPaths(basePath: string, relativePath: string): string { |
| 564 | if (!isValidJsonPointer(basePath)) { |
| 565 | throw new PathError( |
| 566 | `Invalid base path: "${basePath}"`, |
| 567 | PathErrorCodes.INVALID_PATH, |
| 568 | { basePath }, |
| 569 | ); |
| 570 | } |
| 571 | |
| 572 | // 如果相对路径是绝对路径,直接返回 |
| 573 | if (relativePath.startsWith('/')) { |
| 574 | return relativePath; |
| 575 | } |
| 576 | |
| 577 | const baseTokens = parseJsonPointer(basePath); |
| 578 | const relativeTokens = relativePath.split('/').map(decodeJsonPointerToken); |
| 579 | |
| 580 | return toJsonPointer([...baseTokens, ...relativeTokens]); |
| 581 | } |
no test coverage detected