/
index.js
56 lines (50 loc) · 1.76 KB
/
index.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
// import methods from '../../methods/index.js'
import switches from './_data.js'
import { unpack } from 'efrt'
const toTitleCase = function (str) {
return str.replace(/\w\S*/g, txt => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase())
}
const titleCase = function (obj) {
return Object.keys(obj).reduce((h, key) => {
let name = toTitleCase(key).replace(/tense$/, 'Tense')
name = toTitleCase(key).replace(/noun$/, 'Noun')
h[name] = obj[key]
return h
}, {})
}
// make a copy of nounVerb called 'presentPlural'
const copySwitch = function (from) {
const presentPlural = Object.assign({}, from)
presentPlural.fallback = 'PresentTense'
let keys = ['beforeTags', 'afterTags', 'beforeWords', 'afterWords', 'ownTags']
keys.forEach(k => {
presentPlural[k] = Object.assign({}, from[k])
Object.keys(presentPlural[k]).forEach(key => {
presentPlural[k][key] = presentPlural[k][key] === 'Infinitive' ? 'PresentTense' : 'Plural'
})
})
let words = {}
Object.keys(presentPlural.words).forEach(str => {
words[str + 's'] = true
})
presentPlural.words = words
return presentPlural
}
// unpack our lexicon of ambiguous-words
// (found in ./lib/switches/)
// add compressed word-data
Object.keys(switches).forEach(k => {
Object.keys(switches[k]).forEach(key => {
if (switches[k][key] !== '' && key !== 'fallback') {
switches[k][key] = unpack(switches[k][key])
}
})
switches[k].beforeTags = titleCase(switches[k].beforeTags)
switches[k].afterTags = titleCase(switches[k].afterTags)
switches[k].ownTags = titleCase(switches[k].ownTags)
})
switches.presentPlural = copySwitch(switches.nounVerb)
// random ad-hoc changes -
// 'was time' vs 'was working'
switches.gerundNoun.beforeWords.was = 'Gerund'
export default switches