(s: string | any)
| 64 | } |
| 65 | |
| 66 | export function unescapeJsonString(s: string | any): string { |
| 67 | if (typeof s !== 'string') return s; |
| 68 | if (!/[\\]/.test(s)) return s; |
| 69 | |
| 70 | const result: string[] = []; |
| 71 | for (let i = 0; i < s.length; i++) { |
| 72 | const c = s[i]; |
| 73 | if (c !== '\\') result.push(c); |
| 74 | else { |
| 75 | const cNext = s[++i]; |
| 76 | if (cNext === 'u') { |
| 77 | if (i + 4 >= s.length) return s; |
| 78 | const code = c[i + 1] + c[i + 2] + c[i + 3] + c[i + 4]; |
| 79 | i += 4; |
| 80 | result.push(String.fromCharCode(Number.parseInt(code, 16))); |
| 81 | } else if (cNext === 'b') result.push('\u0008'); |
| 82 | else if (cNext === 't') result.push('\u0009'); |
| 83 | else if (cNext === 'n') result.push('\u000a'); |
| 84 | else if (cNext === 'f') result.push('\u000c'); |
| 85 | else if (cNext === 'r') result.push('\u000d'); |
| 86 | else if (cNext === '"') result.push('"'); |
| 87 | else if (cNext === '\\') result.push('\\'); |
| 88 | } |
| 89 | } |
| 90 | return result.join(''); |
| 91 | } |
nothing calls this directly
no outgoing calls
no test coverage detected