utils.CenterString   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
package utils
2
3
import "strings"
4
5
func CenterString(str string, width int) string {
6
	spaces := int(float64(width-len(str)) / 2)
7
	// If the string is longer than the width, return the string as is
8
	if spaces < 0 {
9
		return str
10
	}
11
	return strings.Repeat(" ", spaces) + str + strings.Repeat(" ", width-(spaces+len(str)))
12
}
13
14
// ObscureToken Obscure a token by replacing the middle characters with "..."
15
func ObscureToken(token string) string {
16
	if len(token) < 8 {
17
		return token
18
	}
19
	return token[:14] + "..." + token[len(token)-4:]
20
}
21