forked from TheaMorin/us-to-uk-json-steno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_uk.js
52 lines (47 loc) · 1.37 KB
/
make_uk.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
import main_dict from './main.json'
import { readFileSync } from 'fs'
// Exceptions, manual definitions.
const staticUk =
{ 'KH*EBG': 'cheque'
, 'KH*EBGS': 'cheques'
, 'KHEBG': 'check'
, 'PHUPL': 'mum'
, 'PRA*PL': 'program'
, 'SKWRAE*UL': 'gaol'
, 'SPELT': 'spelt'
, 'TAO*EUR': 'tyre'
, 'TAOEUR': 'tire'
, 'TK*EUFK/AO*ET': 'diskette'
, 'TKAOEUL/O*G': 'dialog'
, 'TKEUFK/AO*ET': 'diskette'
, 'TKPWRA*EU': 'gray'
, 'TKRA*FT': 'draught'
, 'TO*PB': 'ton'
}
const usWords = readFileSync('wordlists/us', 'utf-8')
.split('\n')
.reduce((result, usWord, index) => {
return Object.assign(result, { [usWord]: index })
}, {}) // Object: { usWord: indexOfWord }
// Array of UK words (same order, size, index as US words)
const ukWords =
readFileSync('wordlists/uk', 'utf-8')
.split('\n')
const ukDictionary =
Object.assign(
Object.keys(main_dict).reduce(
(result, currentKey) => {
// Get the word from the main dictionary.
const ploverWord = main_dict[currentKey]
// See if the US word exists.
const wordIndex = usWords[ploverWord]
if (wordIndex) { // It does.
// Get the UK version
result[currentKey] = ukWords[wordIndex]
}
return result // Next word.
}, {}
), staticUk // Apply overrides.
)
// Output to console.
console.log(JSON.stringify(ukDictionary, null, 2))