From 477bb8abf225b7ef27d47ab99d125de0cc86ac75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Jakubowski?= Date: Wed, 1 Nov 2023 13:09:58 +0100 Subject: [PATCH] Add substringBetween string extension --- src/global.d.ts | 2 ++ src/util/extensions.ts | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/global.d.ts b/src/global.d.ts index 195f9b9..a83983c 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -8,6 +8,8 @@ declare global { substringAfter(text: string): string; + substringBetween(start: string, end: string): string; + substringUpTo(text: string): string; substringUpToAndIncluding(text: string): string; diff --git a/src/util/extensions.ts b/src/util/extensions.ts index 51b9ce5..ceb2a4d 100644 --- a/src/util/extensions.ts +++ b/src/util/extensions.ts @@ -17,6 +17,10 @@ String.prototype.substringAfter = function (text: string) { return this.substring(this.indexOf(text) + text.length); }; +String.prototype.substringBetween = function (start: string, end: string) { + return this.substring(this.indexOf(start) + start.length, this.indexOf(end)); +}; + String.prototype.substringUpTo = function (text: string) { return this.substring(0, this.indexOf(text)); }; @@ -25,7 +29,7 @@ String.prototype.substringUpToAndIncluding = function (text: string) { return this.substring(0, this.indexOf(text) + text.length); }; -Array.prototype.whereType = function () { +Array.prototype.whereType = function (): Array { return this.filter((element): element is T => !!element); };