Skip to content

Commit e858af7

Browse files
committed
feat: basic lorem ipsum generation
1 parent 26af795 commit e858af7

4 files changed

Lines changed: 430 additions & 10 deletions

File tree

LICENCE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2019 Daniel Knell, http://danielknell.co.uk
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the “Software”), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,57 @@
1-
# Taylor
1+
# Taylor.swift
22

3-
A description of this package.
3+
Taylor makes beautiful words happen, a Lorem Ipsum generator for Swift.
4+
5+
## Installing
6+
7+
Taylor can be installed using Swift Package Manager.
8+
9+
## Usage
10+
11+
Taylor provides static methods for generating different types of text.
12+
13+
### Words
14+
15+
Generate lowercase words of either a fixed or random length seperated by a space.
16+
17+
```swift
18+
let one = Taylor.word()
19+
let ten = Taylor.words(10)
20+
let fiveToTen = Taylor.words(5...10)
21+
```
22+
23+
### Sentences
24+
25+
Generate capitalised sentences of either fixed or random length, each ending in a period.
26+
27+
```swift
28+
let one = Taylor.sentence()
29+
let ten = Taylor.sentences(10)
30+
let fiveToTen = Taylor.sentences(5...10)
31+
```
32+
33+
### Paragraphs
34+
35+
Generate paragraphs of sentences, either fixed or random length, each seperated by a newline.
36+
37+
```swift
38+
let one = Taylor.paragraph()
39+
let ten = Taylor.paragraphs(10)
40+
let fiveToTen = Taylor.paragraphs(5...10)
41+
```
42+
43+
### Titles
44+
45+
Generate a capitalised title.
46+
47+
```swift
48+
let title = Taylor.title()
49+
```
50+
51+
## Licence
52+
53+
This project is licensed under the [MIT licence](http://dan.mit-license.org/).
54+
55+
## Meta
56+
57+
This project uses [Semantic Versioning](http://semver.org/).

Sources/Taylor/Taylor.swift

Lines changed: 132 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,133 @@
1-
struct Taylor {
2-
var text = "Hello, World!"
1+
import Foundation
2+
3+
public final class Taylor {
4+
public static func word() -> String {
5+
return bucket.randomElement()!
6+
}
7+
8+
public static func words(_ count: Int) -> String {
9+
return (1...count).map { _ in word() }.joined(separator: " ")
10+
}
11+
12+
public static func words(_ range: Range<Int>) -> String {
13+
return words(Int.random(in: range))
14+
}
15+
16+
public static func words(_ range: ClosedRange<Int>) -> String {
17+
return words(Int.random(in: range))
18+
}
19+
20+
public static func sentence() -> String {
21+
let result = words(Int.random(in: wordsPerSentence))
22+
23+
return result.prefix(1).capitalized + result.dropFirst() + "."
24+
}
25+
26+
public static func sentences(_ count: Int) -> String {
27+
return (1...count).map { _ in sentence() }.joined(separator: " ")
28+
}
29+
30+
public static func sentences(_ range: Range<Int>) -> String {
31+
return sentences(Int.random(in: range))
32+
}
33+
34+
public static func sentences(_ range: ClosedRange<Int>) -> String {
35+
return sentences(Int.random(in: range))
36+
}
37+
38+
public static func paragraph() -> String {
39+
return sentences(Int.random(in: sentencesPerParagraph))
40+
}
41+
42+
public static func paragraphs(_ count: Int) -> String {
43+
return (1...count).map { _ in paragraph() }.joined(separator: "\n")
44+
}
45+
46+
public static func paragraphs(_ range: Range<Int>) -> String {
47+
return paragraphs(Int.random(in: range))
48+
}
49+
50+
public static func paragraphs(_ range: ClosedRange<Int>) -> String {
51+
return paragraphs(Int.random(in: range))
52+
}
53+
54+
public static func title() -> String {
55+
return words(Int.random(in: wordsPerTitle)).capitalized
56+
}
57+
58+
fileprivate static let wordsPerSentence = 5...15
59+
fileprivate static let sentencesPerParagraph = 3...7
60+
fileprivate static let wordsPerTitle = 2...6
61+
62+
fileprivate static let bucket = [
63+
"lorem",
64+
"ipsum",
65+
"dolor",
66+
"sit",
67+
"amet",
68+
"consectetur",
69+
"adipiscing",
70+
"elit",
71+
"sed",
72+
"do",
73+
"eiusmod",
74+
"tempor",
75+
"incididunt",
76+
"ut",
77+
"labore",
78+
"et",
79+
"dolore",
80+
"magna",
81+
"aliqua",
82+
"ut",
83+
"enim",
84+
"ad",
85+
"minim",
86+
"veniam",
87+
"quis",
88+
"nostrud",
89+
"exercitation",
90+
"ullamco",
91+
"laboris",
92+
"nisi",
93+
"ut",
94+
"aliquip",
95+
"ex",
96+
"ea",
97+
"commodo",
98+
"consequat",
99+
"duis",
100+
"aute",
101+
"irure",
102+
"dolor",
103+
"in",
104+
"reprehenderit",
105+
"in",
106+
"voluptate",
107+
"velit",
108+
"esse",
109+
"cillum",
110+
"dolore",
111+
"eu",
112+
"fugiat",
113+
"nulla",
114+
"pariatur",
115+
"excepteur",
116+
"sint",
117+
"occaecat",
118+
"cupidatat",
119+
"non",
120+
"proident",
121+
"sunt",
122+
"in",
123+
"culpa",
124+
"qui",
125+
"officia",
126+
"deserunt",
127+
"mollit",
128+
"anim",
129+
"id",
130+
"est",
131+
"laborum"
132+
]
3133
}

0 commit comments

Comments
 (0)