This commit is contained in:
parent
40e5379eb3
commit
de63c48da2
9 changed files with 415 additions and 1 deletions
27
site/queued-pastes/prefs.mjs
Normal file
27
site/queued-pastes/prefs.mjs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// 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 };
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue