Skip to content

Commit

Permalink
\\n should be changed to \n only when escapeSpecialCharacters is set
Browse files Browse the repository at this point in the history
  • Loading branch information
fuenfundachtzig committed Mar 31, 2024
1 parent e634f0e commit 8f29383
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dedent",
"version": "1.5.1",
"version": "1.5.2",
"description": "A string tag that strips indentation from multi-line strings. ⬅️",
"keywords": [
"dedent",
Expand Down
15 changes: 8 additions & 7 deletions src/dedent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ function createDedent(options: DedentOptions) {
.join("\n");
}

return (
result
// dedent eats leading and trailing whitespace too
.trim()
// handle escaped newlines at the end to ensure they don't get stripped too
.replace(/\\n/g, "\n")
);
// dedent eats leading and trailing whitespace too
result = result.trim();
if (escapeSpecialCharacters) {
// handle escaped newlines at the end to ensure they don't get stripped too
result = result.replace(/\\n/g, "\n");
}

return result;
}
}

0 comments on commit 8f29383

Please sign in to comment.