Skip to content

Commit

Permalink
Add substringBetween string extension
Browse files Browse the repository at this point in the history
  • Loading branch information
FirentisTFW committed Nov 1, 2023
1 parent 6be9d45 commit 477bb8a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ declare global {

substringAfter(text: string): string;

substringBetween(start: string, end: string): string;

substringUpTo(text: string): string;

substringUpToAndIncluding(text: string): string;
Expand Down
6 changes: 5 additions & 1 deletion src/util/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};
Expand All @@ -25,7 +29,7 @@ String.prototype.substringUpToAndIncluding = function (text: string) {
return this.substring(0, this.indexOf(text) + text.length);
};

Array.prototype.whereType = function <T>() {
Array.prototype.whereType = function <T>(): Array<T> {
return this.filter((element): element is T => !!element);
};

Expand Down

0 comments on commit 477bb8a

Please sign in to comment.