UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

43 lines 1.2 kB
const FORBIDDEN_KEYS = new Set(['__proto__', 'constructor', 'prototype']); export 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