escape
In addition to the usual escapable characters (for example, \\, " certain whitespace characters), this escape function also handles lone surrogates.
\\
"
It compares characters via char-code in hexadecimal form, to speed up comparisons.
This could be further optimized by switching on the length of the inputs, and using a regular expression if the input is over a certain length.
From MDN:
leading surrogates (a.k.a "high-surrogate" code units) have values between 0xD800 and 0xDBFF, inclusive
trailing surrogates (a.k.a. "low-surrogate" code units) have values between 0xDC00 and 0xDFFF, inclusive
See also:
escape
In addition to the usual escapable characters (for example,
\\
,"
certain whitespace characters), this escape function also handles lone surrogates.It compares characters via char-code in hexadecimal form, to speed up comparisons.
This could be further optimized by switching on the length of the inputs, and using a regular expression if the input is over a certain length.
From MDN:
See also: