forked from unicorncoding/monotext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
44 lines (38 loc) · 887 Bytes
/
app.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
var app = new Vue({
el: '#app',
data: {
text: '',
monotext: ''
},
watch: {
text(newValue) {
this.monotext = mono(newValue);
}
}
})
function mono(text) {
function special(c) {
const chars = {
' ': String.fromCodePoint(0x2000),
'-': String.fromCodePoint(0x2013)
}
return chars[c] || c;
}
function char(c) {
const charOffset = 0x1d670;
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
return chars.includes(c) ? String.fromCodePoint(chars.indexOf(c) + charOffset) : c;
}
function num(c) {
const numOffset = 0x1d7f6;
const numbers = '0123456789';
return numbers.includes(c) ? String.fromCodePoint(numbers.indexOf(c) + numOffset) : c;
}
return Array
.from(text)
.map(c => special(c))
.map(c => char(c))
.map(c => num(c))
.map(c => c)
.join('');
}