@deltares/fews-pi-requests
Version:
Library for making requests to the FEWS PI webservice
49 lines • 1.92 kB
JavaScript
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;
}
export 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('&') : '';
}
//# sourceMappingURL=filterToParams.js.map