INNER CODE UNIT · JavaScript
sanitizeSettings
kevinchin12/ImageLens · background.js:373
function sanitizeSettings(payload) {
const next = {};
for (const [key, value] of Object.entries(payload)) {
if (!(key in DEFAULT_SETTINGS)) continue;
if (typeof DEFAULT_SETTINGS[key] === "boolean") {
next[key] = Boolean(value);
continue;
}
if (typeof DEFAULT_SETTINGS[key] === "number") {
next[key] = Number(value);
continue;
}
if (isPlainObject(DEFAULT_SETTINGS[key])) {
next[key] = isPlainObject(value) ? value : {};
continue;
}
next[key] = String(value ?? "");