MCPcopy Create free account
hub / github.com/bywwcnll/StreamPanel / decodeEscapedText

Function decodeEscapedText

devtools/modules/eventHandlers.js:312–337  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

310}
311
312function decodeEscapedText(text) {
313 if (!text) return '';
314
315 const trimmed = text.trim();
316 if (trimmed.length >= 2 && trimmed.startsWith('"') && trimmed.endsWith('"')) {
317 try {
318 return JSON.parse(trimmed);
319 } catch (error) {
320 // Fall back to tolerant decoding below.
321 }
322 }
323
324 return text
325 .replace(/\\u\{([0-9a-fA-F]+)\}/g, (_, hex) => {
326 const codePoint = parseInt(hex, 16);
327 return Number.isFinite(codePoint) ? String.fromCodePoint(codePoint) : _;
328 })
329 .replace(/\\u([0-9a-fA-F]{4})/g, (_, hex) => String.fromCharCode(parseInt(hex, 16)))
330 .replace(/\\x([0-9a-fA-F]{2})/g, (_, hex) => String.fromCharCode(parseInt(hex, 16)))
331 .replace(/\\n/g, '\n')
332 .replace(/\\r/g, '\r')
333 .replace(/\\t/g, '\t')
334 .replace(/\\"/g, '"')
335 .replace(/\\'/g, "'")
336 .replace(/\\\\/g, '\\');
337}
338
339function setupModalClickHandlers() {
340 elements.presetModal.addEventListener('click', (e) => {

Callers 1

updateTextDecodeOutputFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected