UNPKG

1.76 kBJavaScriptView Raw
1import { parse } from '../fsw/fsw-parse';
2
3/**
4 * Function to convert an FSW sign to a query string
5 *
6 * For the flags parameter, use one or more of the following.
7 * - A: exact symbol in temporal prefix
8 * - a: general symbol in temporal prefix
9 * - S: exact symbol in spatial signbox
10 * - s: general symbol in spatial signbox
11 * - L: spatial signbox symbol at location
12 * @function fswquery.fsw2query
13 * @param {string} fswSign - FSW sign
14 * @param {string} flags - flags for query string creation
15 * @returns {string} FSW query string
16 * @example
17 * fswquery.fsw2query('AS10011S10019S2e704S2e748M525x535S2e748483x510S10011501x466S2e704510x500S10019476x475', 'ASL')
18 *
19 * return 'QAS10011S10019S2e704S2e748TS2e748483x510S10011501x466S2e704510x500S10019476x475'
20 */
21const fsw2query = (fswSign, flags) => {
22 let query = '';
23 const parsed = parse.sign(fswSign);
24
25 if (parsed.box) {
26 const A_flag = flags.indexOf('A') > -1;
27 const a_flag = flags.indexOf('a') > -1;
28 const S_flag = flags.indexOf('S') > -1;
29 const s_flag = flags.indexOf('s') > -1;
30 const L_flag = flags.indexOf('L') > -1;
31
32 if (A_flag || a_flag || S_flag || s_flag) {
33 if ((A_flag || a_flag) && parsed.sequence) {
34 query += 'A';
35 query += parsed.sequence.map(sym => sym.slice(0, 4) + (a_flag ? 'uu' : sym.slice(4, 6))).join('');
36 query += 'T';
37 }
38
39 if ((S_flag || s_flag) && parsed.spatials) {
40 query += parsed.spatials.map(spatial => spatial.symbol.slice(0, 4) + (s_flag ? 'uu' : spatial.symbol.slice(4, 6)) + (L_flag ? spatial.coord.join('x') : '')).join('');
41 }
42 }
43 return query ? "Q" + query : undefined;
44 } else {
45 return undefined;
46 }
47}
48
49export { fsw2query }
\No newline at end of file