-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhaikuWriter.js
100 lines (93 loc) · 2.42 KB
/
haikuWriter.js
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const Hypher = require('hypher')
const english = require('hyphenation.en-us')
const h = new Hypher(english)
const syllable = require('syllable')
const formattedWordArray = require('./formatter.js')
var wordArray = []
// once this works, it needs to become an npm module
module.exports = msg => {
var fiveSyl1Count = 0
var sevenSylCount = 0
var fiveSyl2Count = 0
var fiveSyl1 = []
var sevenSyl = []
var fiveSyl2 = []
// create an array of words
wordArray = msg.split(' ')
wordArray.map(word => {
var not51 = true
var not7 = true
var not52 = true
formattedWord = h.hyphenate(word)
console.log('formattedWord', formattedWord)
z = formattedWordArray(formattedWord)
console.log('z', z)
if (fiveSyl1Count <= 4 && sevenSylCount === 0 && fiveSyl2Count === 0) {
fiveSyl1.push(z.word)
fiveSyl1Count = z.sylbs + fiveSyl1Count
console.log('fiveSyl1Count', fiveSyl1Count)
if (fiveSyl1Count === 5) {
not51 = false
}
}
if (
not51 &&
fiveSyl1Count === 5 &&
sevenSylCount <= 6 &&
fiveSyl2Count === 0
) {
// this one is really broken
if (sevenSylCount === 6 && h.hyphenate(z.word) < 1) {
sevenSyl.push(formattedWord[0])
if (formattedWord[1]) {
fiveSyl2.push(formattedWord[1])
fiveSyl2Count++
}
if (formattedWord[2]) {
fiveSyl2.push(formattedWord[2])
fiveSyl2Count++
}
if (formattedWord[3]) {
fiveSyl2.push(formattedWord[3])
fiveSyl2Count++
}
if (formattedWord[4]) {
fiveSyl2.push(formattedWord[4])
fiveSyl2Count++
}
} else {
sevenSyl.push(z.word)
sevenSylCount = sevenSylCount + z.sylbs
console.log('evenSylCount', sevenSylCount)
}
if (sevenSylCount === 7) {
not7 = false
}
}
if (
not51 &&
not7 &&
fiveSyl1Count === 5 &&
sevenSylCount === 7 &&
!sevenSylCount <= 6
) {
fiveSyl2.push(z.word)
fiveSyl2Count = fiveSyl2Count + z.sylbs
console.log('fiveSyl2Count', fiveSyl2Count)
if (fiveSyl2Count === 5) {
fiveSyl1Count = 0
sevenSylCount = 0
fiveSyl2Count = 0
}
}
})
return {
msg:
fiveSyl1.join(' ') +
'\n' +
sevenSyl.join(' ') +
'\n' +
fiveSyl2.join(' '),
arrays: { fiveSyl1, sevenSyl, fiveSyl2 }
}
}