Closed cohix closed 9 years ago
What’s your use case exactly?
I have a field in my database that I want to allow real newline characters.
For now this can be solved with:
var escaped = string.split('\n').map(function(line) {
return jsesc(line);
}).join('\n');
I’m worried that this is not common enough to extend the API for. Also, allowNewlines
seems like too specific an option. If we decide to add something like this, maybe add a whitelist
property instead?
Yeah I like the whitelist idea. Good call.
jsesc should have an option to allow newline characters:
So if the string contains a newline character (
\n
), it would not be replaced by\\n