-
Notifications
You must be signed in to change notification settings - Fork 2
/
toki-pona-names.ts
60 lines (49 loc) · 1.21 KB
/
toki-pona-names.ts
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
// Generates random toki pona-style names.
import { randomItem } from "./random-item.js"
const VOWELS = "aeiou"
const CONSONANTS = "jklmnpstw"
const CONSONANTS_WITHOUT_MN = "jklpstw"
const MAYBE_N = ["", "", "", "n"] as const
export function createRandomTokiPonaName(
minSyllables: number,
maxSyllables: number,
) {
const syllableCount = Math.floor(
Math.random() * (maxSyllables - minSyllables) + minSyllables,
)
let name = ""
if (Math.random() < 0.5) {
name += randomItem(VOWELS)
}
for (let i = 0; i < syllableCount; i++) {
let output
if (name.endsWith("n")) {
output =
randomItem(CONSONANTS_WITHOUT_MN) +
randomItem(VOWELS) +
randomItem(MAYBE_N)
} else {
output = randomItem(CONSONANTS) + randomItem(VOWELS) + randomItem(MAYBE_N)
}
if (
output.includes("ji") ||
output.includes("ti") ||
output.includes("wo") ||
output.includes("wu")
) {
i--
continue
}
name += output
}
return name
}
export function generateMany(
count: number,
minSyllables: number,
maxSyllables: number,
) {
return Array.from({ length: count }, () =>
createRandomTokiPonaName(minSyllables, maxSyllables),
)
}