-
Notifications
You must be signed in to change notification settings - Fork 0
/
leet.ts
46 lines (40 loc) · 973 Bytes
/
leet.ts
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
// leet.json generator
// deno run --allow-read --allow-write leet.ts
const REPLACEMENTS = {
I: '1',
R: '2',
E: '3',
A: '4',
S: '5',
G: '6',
T: '7',
B: '8',
O: '0'
}
function encode(input: string) {
return input.toUpperCase()
.split('')
.map(x => {
// @ts-expect-error a
if (REPLACEMENTS[x]) {
// @ts-expect-error a
return REPLACEMENTS[x]
}
return x;
})
.join('')
}
const text = await Deno.readTextFile("./en.json");
const data = JSON.parse(text);
function recurse(obj: { [key: string]: any }) {
for (const key of Object.keys(obj)) {
if (key === 'dayjs') continue;
if (typeof obj[key] === 'object') {
recurse(obj[key]);
} else {
obj[key] = encode(obj[key]);
}
}
}
recurse(data);
await Deno.writeTextFile("./leet.json", JSON.stringify(data, null, 4));