UNPKG

@deltares/fews-pi-requests

Version:

Library for making requests to the FEWS PI webservice

53 lines 2.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.filterToParams = void 0; function filterArgToStrings(key, value) { const result = []; if (value instanceof Array) { for (const item of value) { result.push(`${encodeURIComponent(key)}=${encodeURIComponent(item)}`); } } else { result.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`); } return result; } function filterToParams(filter) { const filterArgs = []; for (const [parameter, values] of Object.entries(filter)) { if (values === undefined) continue; if (parameter === 'attribute' || parameter === 'properties') { const prefixMap = { 'attribute': 'attribute', 'properties': 'property' }; const prefix = prefixMap[parameter]; for (const [key, value] of Object.entries(values)) { const strings = filterArgToStrings(`${prefix}(${key})`, value); filterArgs.push(...strings); } } else if (parameter === "qualifierIds" && typeof values === "object" && !Array.isArray(values)) { for (const [key, value] of Object.entries(values)) { const strings = filterArgToStrings(`${parameter}`, `${key}=` + value); filterArgs.push(...strings); } } else if (parameter === 'bbox') { const value = `${encodeURIComponent(values[0])},${encodeURIComponent(values[1])},${encodeURIComponent(values[2])},${encodeURIComponent(values[3])}`; const strings = filterArgToStrings(parameter, value); filterArgs.push(...strings); } else { const strings = filterArgToStrings(parameter, values); filterArgs.push(...strings); } } return filterArgs.length ? '?' + filterArgs.join('&') : ''; } exports.filterToParams = filterToParams; //# sourceMappingURL=filterToParams.js.map