(data: unknown, dotpath?: string)
| 150 | * display string. Numeric segments index arrays. Returns undefined when the |
| 151 | * path is empty, missing, or lands on a non-scalar. */ |
| 152 | export const extractIdentity = (data: unknown, dotpath?: string): string | undefined => { |
| 153 | if (dotpath == null || dotpath.length === 0) return undefined; |
| 154 | let current: unknown = data; |
| 155 | for (const segment of dotpath.split(".")) { |
| 156 | if (current == null) return undefined; |
| 157 | if (Array.isArray(current)) { |
| 158 | const index = Number(segment); |
| 159 | if (!Number.isInteger(index) || index < 0 || index >= current.length) return undefined; |
| 160 | current = current[index]; |
| 161 | continue; |
| 162 | } |
| 163 | if (typeof current !== "object") return undefined; |
| 164 | current = (current as Record<string, unknown>)[segment]; |
| 165 | } |
| 166 | if (typeof current === "string") return current; |
| 167 | if (typeof current === "number" || typeof current === "boolean") return String(current); |
| 168 | return undefined; |
| 169 | }; |
| 170 | |
| 171 | /** The best identity tier among a candidate's response fields, or -1 when its |
| 172 | * schema exposes nothing account-naming. Feeds the identity-aware ranking: |
no outgoing calls
no test coverage detected