Say we're given a string that itself contains ASCII escape characters, such as "\x64" (note that this is the contents of the string, not what it would be in code). Is there an easy way in JavaScript to parse this to its actual character?
There's the old trick of using JSON.parse but that seems to only work with unicode escape sequences and can't recognize ASCII ones, as in:
JSON.parse(`"\\u0064"`); // Output: "d" (as expected)
JSON.parse(`"\\x64"`); // ERROR: Unexpected token x
Is there an equivalent that would work for the ASCII escape sequence? I know that using eval() works but I'd really rather not use eval.
EDIT: To clarify, some characters in the original string may not be escaped; as we may need to parse "Hello Worl\x64", for instance.