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

Function extractJsonStringFieldPrefix

src/utils/sessionStorage.ts:4921–4949  ·  view source on GitHub ↗

* Like extractJsonStringField but returns the first `maxLen` characters of the * value even when the closing quote is missing (truncated buffer). Newline * escapes are replaced with spaces and the result is trimmed.

(
  text: string,
  key: string,
  maxLen: number,
)

Source from the content-addressed store, hash-verified

4919 * escapes are replaced with spaces and the result is trimmed.
4920 */
4921function extractJsonStringFieldPrefix(
4922 text: string,
4923 key: string,
4924 maxLen: number,
4925): string {
4926 const patterns = [`"${key}":"`, `"${key}": "`]
4927 for (const pattern of patterns) {
4928 const idx = text.indexOf(pattern)
4929 if (idx < 0) continue
4930
4931 const valueStart = idx + pattern.length
4932 // Grab up to maxLen characters from the value, stopping at closing quote
4933 let i = valueStart
4934 let collected = 0
4935 while (i < text.length && collected < maxLen) {
4936 if (text[i] === '\\') {
4937 i += 2 // skip escaped char
4938 collected++
4939 continue
4940 }
4941 if (text[i] === '"') break
4942 i++
4943 collected++
4944 }
4945 const raw = text.slice(valueStart, i)
4946 return raw.replace(/\\n/g, ' ').replace(/\\t/g, ' ').trim()
4947 }
4948 return ''
4949}
4950
4951/**
4952 * Deduplicates logs by sessionId, keeping the entry with the newest

Callers 1

readLiteMetadataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected