* Escape a character as a unicode escape sequence if it is a control character.
(ch: string)
| 105 | * Escape a character as a unicode escape sequence if it is a control character. |
| 106 | */ |
| 107 | function escapeControlChar(ch: string): string { |
| 108 | const code = ch.charCodeAt(0); |
| 109 | if (code <= 0x1f || code === 0x7f) { |
| 110 | return "\\u" + code.toString(16).padStart(4, "0"); |
| 111 | } |
| 112 | return ch; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Quote a property name if needed. |
no test coverage detected