-
Notifications
You must be signed in to change notification settings - Fork 3
/
lorem.go
74 lines (63 loc) · 1.92 KB
/
lorem.go
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package faker
import "strings"
// Loremer Interface
type Loremer interface {
Lines(lineCount int) string
Paragraph(sentenceCount int) string
Paragraphs(sentenceCount int, separator string) string
Sentence(wordCount int) string
Sentences(sentenceCount int, separator string) string
Slug(wordCount int) string
Word() string
Words(num int) string
}
// Lorem struct
type Lorem struct {
*Fake
}
// Lines returns lines of lorem separated by `'\n'`
func (l *Lorem) Lines(lineCount int) string {
return l.Lorem().Sentences(lineCount, "\n")
}
// Paragraph returns a paragraph
func (l *Lorem) Paragraph(sentenceCount int) string {
return l.Lorem().Sentences(sentenceCount+random(3), " ")
}
// Paragraphs returns n paragraph(s)
func (l *Lorem) Paragraphs(sentenceCount int, separator string) string {
paragraphs := []string{}
for count := sentenceCount; count > 0; count-- {
paragraphs = append(paragraphs, l.Lorem().Paragraph(3))
}
return strings.Join(paragraphs, "\n \r")
}
// Sentence returns a sentence of n words
func (l *Lorem) Sentence(wordCount int) string {
sentence := l.Lorem().Words(wordCount)
return strings.ToUpper(string(sentence[0])) + string(sentence[1:]) + "."
}
// Sentences returns sentences divided by a separator
func (l *Lorem) Sentences(sentenceCount int, separator string) string {
sentences := []string{}
for count := sentenceCount; count > 0; count-- {
wc := randomIntRange(3, 10)
sentences = append(sentences, l.Lorem().Sentence(wc))
}
return strings.Join(sentences, separator)
}
// Slug returns a slugged sentence
func (l *Lorem) Slug(wordCount int) string {
return slugify(l.Lorem().Words(wordCount))
}
// Word returns a random word
func (l *Lorem) Word() string {
return l.pick(loremPrefix + "/words")
}
// Words returns an amount of words
func (l *Lorem) Words(num int) string {
words := []string{}
for i := 0; i < num; i++ {
words = append(words, l.Lorem().Word())
}
return strings.Join(words, " ")
}