@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
49 lines (48 loc) • 1.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.sanitizeUrlFilters = sanitizeUrlFilters;
const FORBIDDEN_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
function sanitizeUrlFilters(raw) {
if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
return {};
}
const result = {};
for (const key of Object.keys(raw)) {
if (FORBIDDEN_KEYS.has(key)) {
continue;
}
const entry = raw[key];
if (!isFilterValue(entry)) {
continue;
}
const picked = {
value: entry.value,
label: entry.label
};
if (entry.categoryLabel !== undefined) {
picked.categoryLabel = entry.categoryLabel;
}
result[key] = picked;
}
return result;
}
function isFilterValue(val) {
if (val === null || typeof val !== 'object' || Array.isArray(val)) {
return false;
}
const obj = val;
if (typeof obj.label !== 'string') {
return false;
}
if (obj.categoryLabel !== undefined && typeof obj.categoryLabel !== 'string') {
return false;
}
const v = obj.value;
if (typeof v !== 'string' && typeof v !== 'number' && typeof v !== 'boolean' && (v === null || typeof v !== 'object' || Array.isArray(v))) {
return false;
}
return true;
}
//# sourceMappingURL=sanitizeUrlFilters.js.map