-
Notifications
You must be signed in to change notification settings - Fork 1
/
symbols.js
76 lines (70 loc) · 1.53 KB
/
symbols.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
const mongoose = require("mongoose");
const db = require('./config/keys').mongoURI;
const Wine = require('./models/Wine')
mongoose
.connect(db, { useNewUrlParser: true })
.then(() => console.log("Connected to mongoDB"))
.catch(err => console.log(err));
// chart for mac roman encoding errors (mojibake)
// note: Buffer.from and JSON.stringify did not work
const chars = {
"‚Äî": "—",
"–": "-",
"“": '"',
"”": '"',
'√Å': 'Á',
'√Ç': 'Â',
'√Ä': 'À',
'√Ö': 'Å',
'√°': 'á',
'√¢': 'â',
'√†': 'à',
'√§': 'ä',
'√•': 'å',
'√£': 'ã',
'√¶': 'æ',
'√á': 'Ç',
'√ß': 'ç',
'√â': 'É',
'√à': 'È',
'√©': 'é',
'√™': 'ê',
'√®': 'è',
'√´': 'ë',
'√≠': 'í',
'√Æ': 'î',
'√¨': 'ì',
'√Ø': 'ï',
'√±': 'ñ',
'√ì': 'Ó',
'√î': 'Ô',
'√í': 'Ò',
'√ñ': 'Ö',
'√ò': 'Ø',
'√≥': 'ó',
'√¥': 'ô',
'√≤': 'ò',
'√∂': 'ö',
'√∞': 'ð',
'√∏': 'ø',
'√ü': 'ß',
'√û': 'Þ',
'√ú': 'Ü',
'√∫': 'ú',
'√ª': 'û',
'√π': 'ù',
'√º': 'ü',
'√Ω': 'ý'
};
const convert = str => (str.replace(/(√\W)|(,\S\S)/g, exp => chars[exp]))
Wine.find()
.then(wines => {
wines.forEach(wine => {
wine.title = convert(wine.title);
wine.description = convert(wine.description);
wine.variety = convert(wine.variety);
wine.winery = convert(wine.winery);
wine.save()
})
console.log('done')
})