MCPcopy Index your code
hub / github.com/codeaashu/claude-code / extractJsonStringField

Function extractJsonStringField

src/utils/sessionStoragePortable.ts:53–76  ·  view source on GitHub ↗
(
  text: string,
  key: string,
)

Source from the content-addressed store, hash-verified

51 * Returns the first match, or undefined if not found.
52 */
53export function extractJsonStringField(
54 text: string,
55 key: string,
56): string | undefined {
57 const patterns = [`"${key}":"`, `"${key}": "`]
58 for (const pattern of patterns) {
59 const idx = text.indexOf(pattern)
60 if (idx < 0) continue
61
62 const valueStart = idx + pattern.length
63 let i = valueStart
64 while (i < text.length) {
65 if (text[i] === '\\') {
66 i += 2
67 continue
68 }
69 if (text[i] === '"') {
70 return unescapeJsonString(text.slice(valueStart, i))
71 }
72 i++
73 }
74 }
75 return undefined
76}
77
78/**
79 * Like extractJsonStringField but finds the LAST occurrence.

Callers 2

readLiteMetadataFunction · 0.85
parseSessionInfoFromLiteFunction · 0.85

Calls 1

unescapeJsonStringFunction · 0.85

Tested by

no test coverage detected