aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-07-03 12:46:22 +0200
committerlonkaars <loek@pipeframe.xyz>2023-07-03 12:46:22 +0200
commit5c9bebac4078ee053c5048e4de2a3ed5afed4e24 (patch)
tree6afc0bf8e0d8db373bb080567c6db56b78b4440a /util
parentfa68eb21bf1d0460303cae3a0233e2d6cefd00ca (diff)
fix furigana for known working sentence
Diffstat (limited to 'util')
-rw-r--r--util/string.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/util/string.ts b/util/string.ts
index 934963e..bb6bc0f 100644
--- a/util/string.ts
+++ b/util/string.ts
@@ -43,6 +43,12 @@ declare global {
* @param position index to search from (0 by default = start of string)
*/
cmpLen(searchString: string, position?: number): number;
+
+ /** @summary remove `length` characters from end of string */
+ removeEnd(length: number): string;
+
+ /** @summary replace last instance of `searchString` with `replaceValue` */
+ replaceLast(searchString: string, replaceValue: string): string;
}
}
@@ -129,7 +135,18 @@ String.prototype.cmpLen = function(searchString, position = 0) {
for (let i = 0; i < searchString.length; i++) {
if (i + position >= this.length) break;
if (this[i + position] == searchString[i]) len++;
+ else break;
}
return len;
}
+String.prototype.removeEnd = function(length) {
+ return this.substring(0, this.length - length);
+}
+
+String.prototype.replaceLast = function(find, replace) {
+ var i = this.lastIndexOf(find);
+ if (i == -1) return this as string; // not found
+ return this.substring(0, i) + replace + this.substring(i + find.length);
+}
+