commit 5337501ba9d60ea914c7cb6b5b545a21516c76c4
parent d97d40348a407ee4b8c56c2c2549acbbd4bcf692
Author: Jackson G. Kaindume <seestem@merely.tech>
Date: Mon, 4 Jul 2022 13:21:31 +0200
Add StrFmt.shrtMidDot() function
Diffstat:
2 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/lib/src/drtx_base.dart b/lib/src/drtx_base.dart
@@ -0,0 +1,15 @@
+// Public facing types
+
+/// Functions for string formating
+class StrFmt {
+ /// if a string is has 13 characters or more it return the first 5 characters
+ /// with 3 (...) dots and the last 5 characters
+ static String shrtMidDot(String str) {
+ if (str.length > 13) {
+ final start = str.substring(0, 5);
+ final end = str.substring(str.length - 5);
+ return "$start...$end";
+ }
+ return str;
+ }
+}
diff --git a/test/drtx_test.dart b/test/drtx_test.dart
@@ -0,0 +1,19 @@
+import 'package:drtx/drtx.dart';
+import 'package:test/test.dart';
+
+void main() {
+ group('StrFmt tests', () {
+ setUp(() {
+ // Additional setup goes here.
+ });
+
+ test('shrtMidDot', () {
+ expect(StrFmt.shrtMidDot("0123456789"), "0123456789");
+ expect(StrFmt.shrtMidDot("0123456789ABCDE"), "01234...ABCDE");
+ expect(
+ StrFmt.shrtMidDot(
+ "0123456kfjdffdfaunfdfnhjfdhfdfdkjdfdfkdfnngfdfjgghjfghfjhgffghfghhjfghjfgjhfghfghjfghgjfghjfghjfghrbebqjewe83929odf;****3774743g789ABCDE"),
+ "01234...ABCDE");
+ });
+ });
+}