-
Notifications
You must be signed in to change notification settings - Fork 0
/
hex.ts
39 lines (27 loc) · 842 Bytes
/
hex.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
import { getSelectionString, setSelectionString } from './utils';
// 'JKL' -> '4a4b4c'
export function hexEncode () {
let theString = getSelectionString();
if (!theString)
{return;}
let theArrary = Buffer.from(theString, 'ascii');
let hexArrary: string[] = [];
theArrary.forEach(value => {
hexArrary.push(value.toString(16));
});
const resultString = hexArrary.join('');
setSelectionString(resultString);
}
// '4a4b4c' -> 'JKL'
export function hexDecode () {
let theString = getSelectionString();
if (!theString)
{return;}
let theArrary = Buffer.from(theString, 'hex');
let charArrary: string[] = [];
theArrary.forEach(value => {
charArrary.push(String.fromCharCode(value));
});
const resultString = charArrary.join('');
setSelectionString(resultString);
}