( id: string, prefix: string, expectedSegments: number, )
| 38 | * Parse a compound ID, returning null if prefix doesn't match or segments are invalid. |
| 39 | */ |
| 40 | export function parseCompoundId( |
| 41 | id: string, |
| 42 | prefix: string, |
| 43 | expectedSegments: number, |
| 44 | ): readonly string[] | null { |
| 45 | if (!id.startsWith(`${prefix}:`)) return null; |
| 46 | const body = id.slice(prefix.length + 1); |
| 47 | const parts = body.split(":"); |
| 48 | if (parts.length !== expectedSegments) return null; |
| 49 | const decoded: string[] = []; |
| 50 | for (const part of parts) { |
| 51 | if (part.length === 0) return null; |
| 52 | const d = decodeIdSegment(part); |
| 53 | if (d === null) return null; |
| 54 | decoded.push(d); |
| 55 | } |
| 56 | return decoded; |
| 57 | } |
no test coverage detected