|
1 | | -import { PuidEncoder } from "../../types/puid" |
| 1 | +import { PuidEncoder } from '../../types/puid' |
| 2 | + |
| 3 | +// n: 012 3456 7 8 901 2 34 567 8 9 0 123 4 567 890 1 |
| 4 | +// c: 234 6789 b d fgh j mn pqr t B D FGH J LMN PQR T |
2 | 5 |
|
3 | 6 | export default (): PuidEncoder => { |
4 | 7 | const two = '2'.charCodeAt(0) |
5 | | - const six = '6'.charCodeAt(0) - 3 |
| 8 | + const six = '6'.charCodeAt(0) |
6 | 9 | const b = 'b'.charCodeAt(0) |
7 | 10 | const d = 'd'.charCodeAt(0) |
8 | | - const f = 'f'.charCodeAt(0) - 9 |
| 11 | + const f = 'f'.charCodeAt(0) |
9 | 12 | const j = 'j'.charCodeAt(0) |
10 | | - const m = 'm'.charCodeAt(0) - 13 |
11 | | - const p = 'p'.charCodeAt(0) - 15 |
| 13 | + const m = 'm'.charCodeAt(0) |
| 14 | + const p = 'p'.charCodeAt(0) |
12 | 15 | const t = 't'.charCodeAt(0) |
13 | 16 | const B = 'B'.charCodeAt(0) |
14 | 17 | const D = 'D'.charCodeAt(0) |
15 | | - const F = 'F'.charCodeAt(0) - 21 |
| 18 | + const F = 'F'.charCodeAt(0) |
16 | 19 | const J = 'J'.charCodeAt(0) |
17 | | - const L = 'L'.charCodeAt(0) - 25 |
18 | | - const P = 'P'.charCodeAt(0) - 28 |
| 20 | + const L = 'L'.charCodeAt(0) |
| 21 | + const P = 'P'.charCodeAt(0) |
19 | 22 | const T = 'T'.charCodeAt(0) |
20 | 23 |
|
21 | 24 | return (n: number) => { |
22 | 25 | if (n < 3) return n + two |
23 | | - if (n < 7) return n + six |
| 26 | + if (n < 7) return n - 3 + six |
24 | 27 | if (n === 7) return b |
25 | 28 | if (n === 8) return d |
26 | | - if (n < 12) return n + f |
| 29 | + if (n < 12) return n - 9 + f |
27 | 30 | if (n === 12) return j |
28 | | - if (n < 15) return n + m |
29 | | - if (n < 18) return n + p |
| 31 | + if (n < 15) return n - 13 + m |
| 32 | + if (n < 18) return n - 15 + p |
30 | 33 | if (n === 18) return t |
31 | 34 | if (n === 19) return B |
32 | 35 | if (n === 20) return D |
33 | | - if (n < 24) return n + F |
| 36 | + if (n < 24) return n - 21 + F |
34 | 37 | if (n === 24) return J |
35 | | - if (n < 28) return n + L |
36 | | - if (n < 31) return n + P |
37 | | - return T |
| 38 | + if (n < 28) return n - 25 + L |
| 39 | + if (n < 31) return n - 28 + P |
| 40 | + if (n === 31) return T |
| 41 | + return NaN |
38 | 42 | } |
39 | 43 | } |
0 commit comments