We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0d7c36a commit df1848aCopy full SHA for df1848a
src/index.ts
@@ -245,12 +245,14 @@ function stringifyString(str: string) {
245
result += '\\"';
246
} else if (char in escaped) {
247
result += escaped[char];
248
- } else if (code >= 0xD800 && code <= 0xDBFF) {
+ } else if (code >= 0xd800 && code <= 0xdfff) {
249
const next = str.charCodeAt(i + 1);
250
- if (next >= 0xDC00 && next <= 0xDFFF) {
+
251
+ // If this is the beginning of a [low, high] surrogate pair,
252
+ // add the next two characters, otherwise escape
253
+ if (code <= 0xdbff && (next >= 0xdc00 && next <= 0xdfff)) {
254
result += char + str[++i];
255
} else {
- // lone surrogates
256
result += `\\u${code.toString(16).toUpperCase()}`;
257
}
258
0 commit comments