-
Notifications
You must be signed in to change notification settings - Fork 3
/
aprs-symbols.js
49 lines (47 loc) · 1.78 KB
/
aprs-symbols.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
/**
* Returns address of symbol in tables or false if not found
*
* @param {string} symbol
* @return {array|boolean} address in tables or false
* */
function getAPRSSymbolAddress(symbol) {
const tableSymbol = symbol.charAt(0);
const table = tableSymbol === '/' ? 0 : (tableSymbol === '\\' ? 1 : 2);
const search = symbol.charAt(1);
const translation = [
'!"#$%&\'()*+,-./0', '123456789:;<=>?@', 'ABCDEFGHIJKLMNOP', 'QRSTUVWXYZ[\\]^_`', 'abcdefghijklmnop', 'qrstuvwxyz{|}~'
];
for (let row = 0; row < translation.length; row++) {
const rowData = translation[row];
for (let col = 0; col < rowData.length; col++) {
if (rowData[col] === search) {
return [table, row, col];
}
}
}
return false;
}
/**
* Returns <i> tag with propper classes for given address, or false if the address is not correctly provided
*
* @param {array} address
* @param {number} size grid size, either 24, 48, 64 or 128
* @return {string|boolean} image tag or false on failure
* */
function getAPRSSymbolImageTagByAddress(address, size = 24) {
if (typeof address === 'undefined' || !Array.isArray(address) || address.length !== 3) {
return false;
}
return "<i class='aprs-table" + address[0] + "-" + size + " aprs-address-" + size + "-" + address[1] + "-" + address[2] + "'></i>";
}
/**
* Either you can get image tag generated by passing symbol only (such as "/["), or you can get the image tag by providing its address
*
* @param {string} symbol
* @param {number} size
* @return {string|boolean} image tag, if address was found, false otherwise
* */
function getAPRSSymbolImageTag(symbol, size = 24) {
const address = getAPRSSymbolAddress(symbol);
return getAPRSSymbolImageTagByAddress(address, size);
}