Is there a standard way in JavaScript to get a human-readable version of a special character automatically?
I need to report some invalid symbols after parsing, which also includes such symbols as \r
, \n
, \t
.
When I encounter a regular character, I just want to display it as is, like this:
Invalid character 'a' at position 123
But when, for example, I encounter \t
, I want to report it as:
Invalid character '\t' at position 123
and not as
Invalid character ' ' at position 123
Is there a standard way in JavaScript to do this, or do I have to code around this?