This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvaporwave.js
42 lines (35 loc) · 1.63 KB
/
vaporwave.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
// returns text composed of full-width characters
module.exports.toVaporwave = function (txt) {
// split into a char array
const chars = txt.split('');
// convert each character into full width equivalent & recombine
return chars.map(toFullWidth).join('');
}
// returns the full-width version of the character c
const fw_chars = {
'`': '`', '1': '1', '2': '2', '3': '3', '4': '4', '5': '5',
'6': '6', '7': '7', '8': '8', '9': '9', '0': '0', '-': '-',
'=': '=', '~': '~', '!': '!', '@': '@', '#': '#', '$': '$',
'%': '%', '^': '^', '&': '&', '*': '*', '(': '(', ')': ')',
'_': '_', '+': '+',
'q': 'q', 'w': 'w', 'e': 'e', 'r': 'r', 't': 't', 'y': 'y',
'u': 'u', 'i': 'i', 'o': 'o', 'p': 'p', '[': '[', ']': ']',
'\\': '\', 'Q': 'Q', 'W': 'W', 'E': 'E', 'R': 'R', 'T': 'T',
'Y': 'Y', 'U': 'U', 'I': 'I', 'O': 'O', 'P': 'P', '{': '{',
'}': '}', '|': '|',
'a': 'a', 's': 's', 'd': 'd', 'f': 'f', 'g': 'g', 'h': 'h',
'j': 'j', 'k': 'k', 'l': 'l', ';': ';', '\'': ''', 'A': 'A',
'S': 'S', 'D': 'D', 'F': 'F', 'G': 'G', 'H': 'H', 'J': 'J',
'K': 'K', 'L': 'L', ':': ':', '\"': '“',
'z': 'z', 'x': 'x', 'c': 'c', 'v': 'v', 'b': 'b', 'n': 'n',
'm': 'm', ',': ',', '.': '.', '/': '/', 'Z': 'Z', 'X': 'X',
'C': 'C', 'V': 'V', 'B': 'B', 'N': 'N', 'M': 'M', '<': '<',
'>': '>', '?': '?', ' ': ' '
};
function toFullWidth(c,i,a) {
return fw_chars[c] || `${
i != 0 ? a[i - 1] == ' ' ? '' : ' ' : ''
}${c}${
i + 1 < a.length ? a[i + 1] == ' ' ? '' : ' ' : ''
}`;
}