{"id":25902781,"url":"https://github.com/scriptraccoon/local-storage-stores","last_synced_at":"2026-05-31T01:31:37.277Z","repository":{"id":213996398,"uuid":"735443432","full_name":"ScriptRaccoon/local-storage-stores","owner":"ScriptRaccoon","description":"Svelte stores that sync with localStorage","archived":false,"fork":false,"pushed_at":"2024-01-26T00:04:15.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-05-30T16:49:56.203Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://localstoragestore.netlify.app","language":"Svelte","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ScriptRaccoon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-12-25T00:36:19.000Z","updated_at":"2023-12-25T00:36:50.000Z","dependencies_parsed_at":"2023-12-25T01:41:05.967Z","dependency_job_id":"5a1991f0-8552-4935-b306-3d0226ea582a","html_url":"https://github.com/ScriptRaccoon/local-storage-stores","commit_stats":null,"previous_names":["scriptraccoon/local-storage-stores"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScriptRaccoon%2Flocal-storage-stores","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScriptRaccoon%2Flocal-storage-stores/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScriptRaccoon%2Flocal-storage-stores/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScriptRaccoon%2Flocal-storage-stores/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ScriptRaccoon","download_url":"https://codeload.github.com/ScriptRaccoon/local-storage-stores/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241600473,"owners_count":19988715,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-03T03:17:20.820Z","updated_at":"2026-05-31T01:31:37.265Z","avatar_url":"https://github.com/ScriptRaccoon.png","language":"Svelte","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Local Storage Stores in Svelte\n\nThis repo provides a general function `local_store` in `src/lib/stores.ts` (see also below) that generates stores that will be synced with the browser's localStorage. This can be used to persist user preferences easily. The Svelte app demonstrates this with a couple of examples.\n\nhttps://localstoragestore.netlify.app\n\n## Code\n\n```typescript\nfunction local_store\u003cT\u003e(\n\tkey: string,\n\tdefault_value: T,\n\tupdate: (value: T) =\u003e void = () =\u003e {}\n): Writable\u003cT\u003e {\n\tlet initial_value: T\n\ttry {\n\t\tconst has_stored_value = localStorage.getItem(key) !== null\n\t\tinitial_value = has_stored_value\n\t\t\t? JSON.parse(localStorage.getItem(key)!)\n\t\t\t: default_value\n\t} catch (_) {\n\t\tinitial_value = default_value\n\t}\n\n\tconst store = writable\u003cT\u003e(initial_value)\n\n\tstore.subscribe((value: T) =\u003e {\n\t\tlocalStorage.setItem(key, JSON.stringify(value))\n\t\tupdate(value)\n\t})\n\n\treturn store\n}\n```\n\n## SvelteKit considerations\n\nFor SvelteKit applications, make sure to always check if `browser=true` before using the localStorage, since otherwise you will run into an error: the server has no `localStorage` global.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscriptraccoon%2Flocal-storage-stores","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscriptraccoon%2Flocal-storage-stores","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscriptraccoon%2Flocal-storage-stores/lists"}