Skip to content

Commit

Permalink
add trim hash util
Browse files Browse the repository at this point in the history
  • Loading branch information
michavie committed Jul 29, 2022
1 parent 3ffedc6 commit 73c3e87
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Utils/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,12 @@ public static function numberToHumanReadableShort(int $num): string

return $num;
}

public static function trimHash(string $hash, int $keep = 10): string
{
$start = substr($hash, 0, $keep);
$end = substr($hash, -$keep);

return "{$start}...{$end}";
}
}
9 changes: 9 additions & 0 deletions tests/Utils/FormatterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

use Superciety\ElrondSdk\Utils\Formatter;

it('trims a hash', function () {
$actual = Formatter::trimHash('4a770452b02f8511ebda39f9de29b8b7c3478cf87c64287d3bca7fd96a0595b9', 4);

expect($actual)->toBe('4a77...95b9');
});

0 comments on commit 73c3e87

Please sign in to comment.