From 26a3f096d35f9b653bd83eefe044db35142534b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Stenhaug?= Date: Wed, 22 Jan 2025 22:33:27 +0100 Subject: [PATCH] Normalize whitespace characters that occur alone This seems more consistent. --- index.js | 2 +- test.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index bdcb4bd..3bfb230 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ "use strict"; -const pattern = /[\f\n\r\t\v ]{2,}/g; +const pattern = /[\f\n\r\t\v ]+/g; const replacement = " "; const normalize = str => str.replace(pattern, replacement); diff --git a/test.js b/test.js index d60f72b..be4699a 100644 --- a/test.js +++ b/test.js @@ -10,3 +10,8 @@ it("works", () => expect( normalize(" \u00a0 \ufeff \u200b asdf") ).to.equal(" \u00a0 \ufeff \u200b asdf"); }); + +it("normalizes solitary whitespace characters", () => +{ + expect( normalize("asdf\nasdf\tasdf ") ).to.equal("asdf asdf asdf "); +});