ui: fix tests

This commit is contained in:
Matthew Penner 2023-01-12 12:44:49 -07:00
parent 155d7bb876
commit 7e1aa8d7e2
No known key found for this signature in database
4 changed files with 23 additions and 3 deletions

View file

@ -27,8 +27,12 @@ function bytesToString(bytes: number, decimals = 2): string {
* Formats an IPv4 or IPv6 address.
*/
function ip(value: string): string {
// noinspection RegExpSimplifiable
return /^([a-f0-9:]+:+)+[a-f0-9]+$/.test(value) ? `[${value}]` : value;
// Check if the value is already formatted.
if (value.length > 0 && value[0] === '[') {
return value;
}
return /([a-f0-9:]+:+)+[a-f0-9]+/.test(value) ? `[${value}]` : value;
}
export { ip, mbToBytes, bytesToString };