webtools/site/queued-pastes/prefs.mjs
Leon Mika de63c48da2
Some checks failed
/ publish (push) Failing after 1m21s
Added Queued Pastes
2026-09-16 21:52:03 +10:00

27 lines
743 B
JavaScript

// Serialization for the Queued Pastes preferences stored in localStorage
// under the key 'queued-paste-prefs'. Pure functions so they can be unit
// tested under Node (see prefs.test.mjs).
const DEFAULTS = { newLines: false, advanceFocus: false };
export function serializePrefs(prefs) {
return JSON.stringify({
'new-lines': Boolean(prefs.newLines),
'advance-focus': Boolean(prefs.advanceFocus),
});
}
export function parsePrefs(json) {
try {
const obj = JSON.parse(json);
if (obj === null || typeof obj !== 'object') {
return { ...DEFAULTS };
}
return {
newLines: obj['new-lines'] === true,
advanceFocus: obj['advance-focus'] === true,
};
} catch {
return { ...DEFAULTS };
}
}