Skip to content

Instantly share code, notes, and snippets.

@Dinir
Created January 26, 2021 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dinir/a72b0f35f074c2cf1de3351aeff7f3c1 to your computer and use it in GitHub Desktop.
Save Dinir/a72b0f35f074c2cf1de3351aeff7f3c1 to your computer and use it in GitHub Desktop.
Copy whole local storage to import it somewhere else.
const replaceStorage = doubleStringifiedStorage => {
// copy storage with `copy(JSON.stringify(JSON.stringify(window.localStorage)))`
window.localStorage.clear()
const imported = JSON.parse(doubleStringifiedStorage)
for (const n in imported) {
localStorage.setItem(n, imported[n])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment