From 8f293832dc4457532cd307562d3816cea430e9ef Mon Sep 17 00:00:00 2001 From: Alexander Mann <8006302+fuenfundachtzig@users.noreply.github.com> Date: Sun, 31 Mar 2024 18:35:30 +0200 Subject: [PATCH] \\n should be changed to \n only when escapeSpecialCharacters is set --- package.json | 2 +- src/dedent.ts | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index dc8537b..826c96e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/dedent.ts b/src/dedent.ts index 88c5caf..eb3a62b 100644 --- a/src/dedent.ts +++ b/src/dedent.ts @@ -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; } }