mirror of https://github.com/gobeam/stringy.git
commit
21f56c647b
11
README.md
11
README.md
|
@ -55,7 +55,7 @@ Convert string to camel case, snake case, kebab case / slugify, custom delimiter
|
|||
<tr>
|
||||
<td><a href="#suffixstring-string">Suffix</a></td>
|
||||
<td><a href="#acronym-string">Acronym</a></td>
|
||||
<td></td>
|
||||
<td><a href="#title-string">Title</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
@ -306,6 +306,15 @@ Tease takes two params length and indicator and it shortens given string on pass
|
|||
fmt.Println(teaseString.Tease(20, "...")) // Hello My name is Ros...
|
||||
```
|
||||
|
||||
#### Title() string
|
||||
|
||||
Title returns string with first letter of each word in uppercase it can be chained on function which return StringManipulation interface.
|
||||
|
||||
```go
|
||||
title := stringy.New("hello roshan")
|
||||
fmt.Println(title.Title()) // Hello Roshan
|
||||
```
|
||||
|
||||
|
||||
#### ToLower() string
|
||||
|
||||
|
|
|
@ -83,4 +83,7 @@ func main() {
|
|||
|
||||
acronym := stringy.New("Laugh Out Loud")
|
||||
fmt.Println(acronym.Acronym().ToLower()) // lol
|
||||
|
||||
title := stringy.New("this is just AN eXample")
|
||||
fmt.Println(title.Title()) // This Is Just An Example
|
||||
}
|
||||
|
|
12
stringy.go
12
stringy.go
|
@ -39,6 +39,7 @@ type StringManipulation interface {
|
|||
Surround(with string) string
|
||||
SnakeCase(rule ...string) StringManipulation
|
||||
Tease(length int, indicator string) string
|
||||
Title() string
|
||||
ToLower() string
|
||||
ToUpper() string
|
||||
UcFirst() string
|
||||
|
@ -337,6 +338,17 @@ func (i *input) ToLower() (result string) {
|
|||
return strings.ToLower(input)
|
||||
}
|
||||
|
||||
// Title makes first letter of each word of user input to uppercase
|
||||
// it can be chained on function which return StringManipulation interface
|
||||
func (i *input) Title() (result string) {
|
||||
input := getInput(*i)
|
||||
wordArray := strings.Split(input, " ")
|
||||
for i, word := range wordArray {
|
||||
wordArray[i] = strings.ToUpper(string(word[0])) + strings.ToLower(word[1:])
|
||||
}
|
||||
return strings.Join(wordArray, " ")
|
||||
}
|
||||
|
||||
// ToUpper makes all string of user input to uppercase
|
||||
// it can be chained on function which return StringManipulation interface
|
||||
func (i *input) ToUpper() string {
|
||||
|
|
|
@ -292,6 +292,14 @@ func TestInput_TeaseEmpty(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestInput_Title(t *testing.T) {
|
||||
str := New("this is just AN eXample")
|
||||
against := "This Is Just An Example"
|
||||
if val := str.Title(); val != against {
|
||||
t.Errorf("Expected: to be %s but got: %s", against, val)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInput_UcFirst(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
Loading…
Reference in New Issue