github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/pkg/utils/formatted.go (about)

     1  // Copyright 2021 The TrueBlocks Authors. All rights reserved.
     2  // Use of this source code is governed by a license that can
     3  // be found in the LICENSE file.
     4  
     5  package utils
     6  
     7  import (
     8  	"strings"
     9  )
    10  
    11  func FormattedCode(verbose bool, code string) string {
    12  	codeLen := len(code)
    13  	if verbose || codeLen <= 128 {
    14  		return code
    15  	}
    16  
    17  	return strings.Join(
    18  		[]string{
    19  			code[:15],
    20  			code[codeLen-15:],
    21  		},
    22  		"...",
    23  	)
    24  }
    25  
    26  func FormattedHash(verbose bool, code string) string {
    27  	codeLen := len(code)
    28  	if verbose || codeLen <= 11 {
    29  		return code
    30  	}
    31  
    32  	return strings.Join(
    33  		[]string{
    34  			code[:6],
    35  			code[codeLen-4:],
    36  		},
    37  		"...",
    38  	)
    39  }