Created
March 18, 2021 11:34
-
-
Save dzek69/6f02ca65e1a2ae2b798faa47fe71621d to your computer and use it in GitHub Desktop.
Save / restore all localStorage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const save = () => JSON.stringify(Object.keys(localStorage).reduce((acc, curr) => { acc[curr] = localStorage.getItem(curr); return acc; }, {})); | |
// Usage in console: | |
copy(save()); | |
// new console | |
o = CTRL+V | |
restore(o); | |
const clean = () => { Object.keys(localStorage).forEach(k => localStorage.removeItem(k)); return true }; | |
const restore = (o) => clean() && Object.entries(o).forEach(([key, val]) => localStorage.setItem(key, val)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment