MCPcopy
hub / github.com/codeaashu/claude-code / extractLastJsonStringField

Function extractLastJsonStringField

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

Source from the content-addressed store, hash-verified

80 * Useful for fields that are appended (customTitle, tag, etc.).
81 */
82export function extractLastJsonStringField(
83 text: string,
84 key: string,
85): string | undefined {
86 const patterns = [`"${key}":"`, `"${key}": "`]
87 let lastValue: string | undefined
88 for (const pattern of patterns) {
89 let searchFrom = 0
90 while (true) {
91 const idx = text.indexOf(pattern, searchFrom)
92 if (idx < 0) break
93
94 const valueStart = idx + pattern.length
95 let i = valueStart
96 while (i < text.length) {
97 if (text[i] === '\\') {
98 i += 2
99 continue
100 }
101 if (text[i] === '"') {
102 lastValue = unescapeJsonString(text.slice(valueStart, i))
103 break
104 }
105 i++
106 }
107 searchFrom = i + 1
108 }
109 }
110 return lastValue
111}
112
113// ---------------------------------------------------------------------------
114// First prompt extraction from head chunk

Callers 3

readLiteMetadataFunction · 0.85
parseSessionInfoFromLiteFunction · 0.85

Calls 1

unescapeJsonStringFunction · 0.85

Tested by

no test coverage detected