This repository was archived by the owner on Feb 18, 2025. It is now read-only.
This repository was archived by the owner on Feb 18, 2025. It is now read-only.
Escape (whitespace) control characters #30
Closed
Description
- Improves readability
- Avoids issues with
eval
(and many other functions based on common assumptions)
Specifically, I'm looking at linebreaks:
> /\n/g.toString()
"/\n/"
> new RegExp("\\n").toString()
"/\n/"
> new RegExp("\n").toString()
"/
/"
I'd love RegExp.escape("\n")
to yield "\\n"
, not the linebreak "\n"
. Same for all other control characters code units like \r
and \t
. The algorithm might be based on JSON string escaping, though not using the short form for backspace (\b
).