From 419df6b20cd52f62fb35d0f9e7b01493f766fe33 Mon Sep 17 00:00:00 2001 From: Christian Bager Bach Houmann Date: Wed, 14 Feb 2024 20:49:02 +0100 Subject: [PATCH] refactor: better `getLinesInString` fn --- src/utility.ts | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/utility.ts b/src/utility.ts index 878da54..595e817 100644 --- a/src/utility.ts +++ b/src/utility.ts @@ -3,18 +3,7 @@ export function waitFor(ms: number): Promise { } export function getLinesInString(input: string) { - const lines: string[] = []; - let tempString = input; - - while (tempString.includes("\n")) { - const lineEndIndex = tempString.indexOf("\n"); - lines.push(tempString.slice(0, lineEndIndex)); - tempString = tempString.slice(lineEndIndex + 1); - } - - lines.push(tempString); - - return lines; + return input.split("\n"); } // https://stackoverflow.com/questions/3115150/how-to-escape-regular-expression-special-characters-using-javascript