{"id":16440834,"url":"https://github.com/idevelopthings/typesafe-local-storage","last_synced_at":"2026-06-11T02:31:25.540Z","repository":{"id":110819090,"uuid":"394380072","full_name":"iDevelopThings/typesafe-local-storage","owner":"iDevelopThings","description":"TypeSafe local storage implementation with a few additional helpers.","archived":false,"fork":false,"pushed_at":"2021-08-11T14:32:48.000Z","size":120,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-26T01:31:57.465Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iDevelopThings.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-09T17:22:22.000Z","updated_at":"2021-08-11T14:32:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"ff1b85b8-1460-4d39-8763-181e8075d039","html_url":"https://github.com/iDevelopThings/typesafe-local-storage","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/iDevelopThings/typesafe-local-storage","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iDevelopThings%2Ftypesafe-local-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iDevelopThings%2Ftypesafe-local-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iDevelopThings%2Ftypesafe-local-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iDevelopThings%2Ftypesafe-local-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iDevelopThings","download_url":"https://codeload.github.com/iDevelopThings/typesafe-local-storage/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iDevelopThings%2Ftypesafe-local-storage/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34180147,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2024-10-11T09:13:09.361Z","updated_at":"2026-06-11T02:31:25.535Z","avatar_url":"https://github.com/iDevelopThings.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Typesafe Local Storage\n\nA nice easy api for interacting with localStorage and keeping type safety.\n\n# Install the package:\n\n```shell\nyarn add typesafe-local-storage \nnpm install typesafe-local-storage\n```\n\n**You can also use Memory Storage**\nThis follows the same api as LocalStorage, but just uses memory.\n```ts\nimport {MemoryStorage} from 'typesafe-local-storage';\n\nMemoryStorage.set(...)\nMemoryStorage.get(...)\n// etc\n\n```\n# WIP:\n\nEvents for change, update, delete actions.\n\nExample:\n\n```ts\nimport {LocalStorage} from 'typesafe-local-storage';\n\nLocalStorage.onChange('test-item', (oldValue, newValue) =\u003e {\n\tconsole.log(oldValue, newValue);\n\t// emits:\n\t// \"hello\"\n\t// \"hello world\"\n});\nLocalStorage.onAny((type, key, value, oldValue) =\u003e {\n\tconsole.log(type, key, value, oldValue);\n\t// emits:\n\t// \"add\", \"test-item\", \"hello\", undefined\n\t// \"change\", \"test-item\", \"hello world\", \"hello\"\n});\n\nLocalStorage.set('test-item', 'hello');\nLocalStorage.set('test-item', 'hello world');\n\n```\n\n# Some examples:\n\n**Set an item**\n\n```ts\nimport {LocalStorage} from 'typesafe-local-storage';\n\nLocalStorage.set('test', {testing : true});\n```\n\n**Set an item which expires**\n\nTakes a \"Date\" object, which I might re-work in the future, it looks messy like this... but not sure how else to do it.\n\n```ts\nimport {LocalStorage} from 'typesafe-local-storage';\n\nLocalStorage.set('test', {testing : true}, new Date(new Date().getTime() + 5000));\n\nLocalStorage.get('test'); // returns {testing : true}\nsetTimeout(() =\u003e {\n\tLocalStorage.get('test'); // returns undefined\n}, 6000);\n```\n\n**Get an item**\n\n```ts\nimport {LocalStorage} from 'typesafe-local-storage';\n\ntype Testing = { testing: true };\n\nLocalStorage.get\u003cTesting\u003e('test');\n\n// Set a default return type if it doesn't exist.\n\nLocalStorage.get\u003cTesting\u003e('dfjhfsdh', null) === null;\n```\n\n**Delete an item**\n\n```ts\nimport {LocalStorage} from 'typesafe-local-storage';\n\nLocalStorage.delete('test');\n```\n\n**Set localstorage prefix for all items**\n\n```ts\nimport {LocalStorage} from 'typesafe-local-storage';\n\n// Default is \"ls:\"\nLocalStorage.setPrefix('typesafe-local-storage:');\n\nLocalStorage.set('testing');\n\n// Will exist in localStorage as \"typesafe-local-storage:testing\"\n```\n\n**Check if item exists**\n\n```ts\nimport {LocalStorage} from 'typesafe-local-storage';\n\nLocalStorage.exists('testing');\n```\n\n**Get item, create if it doesn't exist.**\n\n```ts\nimport {LocalStorage} from 'typesafe-local-storage';\n\nconst test = LocalStorage.getOrCreate('testing', {testing : true});\n```\n\n**Update item, then return it.**\n\n```ts\nimport {LocalStorage} from 'typesafe-local-storage';\n\nconst test = LocalStorage.getOrUpdate('testing', {testing : false});\n```\n\n**Delete all items of the specified prefix from localStorage**\n\n```ts\nimport {LocalStorage} from 'typesafe-local-storage';\n\nLocalStorage.clear();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidevelopthings%2Ftypesafe-local-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidevelopthings%2Ftypesafe-local-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidevelopthings%2Ftypesafe-local-storage/lists"}