-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.js
63 lines (62 loc) · 1.42 KB
/
mod.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
// deno-fmt-ignore-file
// deno-lint-ignore-file
// This code was bundled using `deno bundle` and it's not recommended to edit it manually
const hangzhou = [
"〇",
"〡",
"〢",
"〣",
"〤",
"〥",
"〦",
"〧",
"〨",
"〩",
];
const hangzhou_alternative = [
"一",
"二",
"三",
];
function decodeSequence(seq) {
return seq.map((c)=>{
if (hangzhou_alternative.includes(c)) {
return hangzhou_alternative.indexOf(c) + 1;
} else {
return hangzhou.indexOf(c);
}
});
}
function decode(s) {
const h = [
...s
];
const digits = decodeSequence(h);
return digits.join("");
}
function toNumber(s, radix = 10) {
return parseInt(decode(s), radix);
}
function rewrite_with_alternatives(h) {
h.forEach((c, i, arr)=>{
const one_two_three = hangzhou.slice(1, 4);
if (one_two_three.includes(c)) {
if (one_two_three.includes(arr[i - 1])) {
arr[i] = hangzhou_alternative[hangzhou.indexOf(c) - 1];
}
}
});
return h;
}
function encode(n) {
return rewrite_with_alternatives([
...n.toString()
].map((d)=>hangzhou[parseInt(d)])).join("");
}
function fromNumber(n, radix = 10) {
return encode(n.toString(radix));
}
export { decode as decode };
export { toNumber as toNumber };
export { encode as encode };
export { fromNumber as fromNumber };