File size: 884 Bytes
83a59ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package emails

import (
	"fmt"
	"net/http"
	"strconv"

	"github.com/nyaruka/phonenumbers"
)

type factory struct{}

func (factory *factory) formatPhoneNumber(number string) string {
	value, _ := phonenumbers.Parse(number, phonenumbers.UNKNOWN_REGION)
	return phonenumbers.Format(value, phonenumbers.INTERNATIONAL)
}

func (factory *factory) formatBool(value bool) string {
	if value == true {
		return "Yes"
	}
	return "No"
}

func (factory *factory) formatQuantity(value uint) string {
	formatted := strconv.FormatUint(uint64(value), 10)
	for index := len(formatted) - 3; index > 0; index -= 3 {
		formatted = formatted[:index] + "," + formatted[index:]
	}

	return formatted
}

func (factory *factory) formatHTTPResponseCode(code *int) string {
	responseCode := "-"
	if code != nil {
		responseCode = fmt.Sprintf("%d - %s", *code, http.StatusText(*code))
	}
	return responseCode
}