aboutsummaryrefslogtreecommitdiff
path: root/src/client/northstar/utils/Extensions.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/northstar/utils/Extensions.ts')
-rw-r--r--src/client/northstar/utils/Extensions.ts9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/client/northstar/utils/Extensions.ts b/src/client/northstar/utils/Extensions.ts
index 71bcadf89..7c2b7fc9d 100644
--- a/src/client/northstar/utils/Extensions.ts
+++ b/src/client/northstar/utils/Extensions.ts
@@ -1,5 +1,6 @@
interface String {
ReplaceAll(toReplace: string, replacement: string): string;
+ Truncate(length: number, replacement: string): String;
}
String.prototype.ReplaceAll = function (toReplace: string, replacement: string): string {
@@ -7,6 +8,14 @@ String.prototype.ReplaceAll = function (toReplace: string, replacement: string):
return target.split(toReplace).join(replacement);
}
+String.prototype.Truncate = function (length: number, replacement: string): String {
+ var target = this;
+ if (target.length >= length) {
+ target = target.slice(0, Math.max(0, length - replacement.length)) + replacement;
+ }
+ return target;
+}
+
interface Math {
log10(val: number): number;
}