{"id":16412818,"url":"https://github.com/script47/local-storage","last_synced_at":"2025-10-26T19:30:57.736Z","repository":{"id":62130666,"uuid":"556458249","full_name":"Script47/local-storage","owner":"Script47","description":"A handy wrapper around localStorage.","archived":false,"fork":false,"pushed_at":"2022-11-01T01:01:42.000Z","size":80,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-31T22:38:22.677Z","etag":null,"topics":["local-storage","local-storage-api","localstorage","ls","persistance","persistant-storage","persistantstorage","storage"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/Script47.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-10-23T22:23:36.000Z","updated_at":"2023-01-18T19:01:34.000Z","dependencies_parsed_at":"2022-10-27T00:01:02.289Z","dependency_job_id":null,"html_url":"https://github.com/Script47/local-storage","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Script47%2Flocal-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Script47%2Flocal-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Script47%2Flocal-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Script47%2Flocal-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Script47","download_url":"https://codeload.github.com/Script47/local-storage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238386403,"owners_count":19463357,"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":["local-storage","local-storage-api","localstorage","ls","persistance","persistant-storage","persistantstorage","storage"],"created_at":"2024-10-11T06:49:52.666Z","updated_at":"2025-10-26T19:30:57.345Z","avatar_url":"https://github.com/Script47.png","language":"JavaScript","readme":"# `@script47/local-storage`\n\nA handy wrapper around localStorage.\n\n- What you see is what you get; Simple and clean wrapper, nothing extra\n- Respects types; no longer do you have to worry about casting items after retrieving them\n- Custom events on actions; listen to events on `set`, `remove`, and `clear`\n\n**Note:** This wrapper will not work if the `localStorage` API is not available.\n\n## Contents\n\n- [Installation](#installation)\n- [API](#api)\n- [Playground](https://jsfiddle.net/m2ewytr6/)\n\n## Installation\n\n#### via NPM\n\n```shell\nnpm i @script47/local-storage\n```\n\n#### via CDN\n\n```html\n\u003cscript src=\"https://unpkg.com/@script47/local-storage\"\u003e\u003c/script\u003e\n```\n\n## API\n\n#### Set or get a key using the quick accessor:\n\n```javascript\nls(key, value);\n```\n\n#### Example\n\n```javascript\nls('key', 'value'); // true\n// or\nls({\n   key: 'value'\n});\nls('key'); // 'value'\n```\n\n---\n\n#### Set a local storage item:\n\n```javascript\nset(key, value);\n```\n\n#### Example\n\n```javascript\nls.set('key', 'value'); // true\n// or\nls.set({\n    key: 'value'\n})\n```\n\n---\n\n#### Get a local storage item:\n\n```javascript\nget(key, def = undefined);\n```\n\n#### Example\n\n```javascript\nls.set('key', 'value'); // true\nls.set('key', 'default value'); // 'value'\nls.get('i-dont-exist', 'default value'); // 'default value'\nls.get('i-dont-exist'); // undefined\n```\n\n---\n\n#### Remove a local storage item:\n\n```javascript\nremove(key);\n```\n\n#### Example\n\n```javascript\nls.set('key', 'value'); // true\nls.get('key'); // 'value'\nls.remove('key'); // true\n// or\nls.remove(['key']);\nls.get('key'); // undefined\n```\n\n---\n\n#### Clear local storage completely:\n\n```javascript\nclear();\n```\n\n#### Example\n\n```javascript\nls.set('key', 'value'); // true\nls.set('another-key', 'another-value'); // true\nls.clear(); // true\nls.get('key'); // undefined\nls.get('another-key'); // undefined\n```\n\n---\n\n#### Listen to events attached to localStorage actions by the package:\n\n```javascript\non(type, listener);\n```\n\n#### Example\n\n```javascript\nls.on('ls.set', ({detail}) =\u003e {\n    console.log(`${detail.key}=${detail.value}`);\n});\n\nls.on('ls.remove', ({detail}) =\u003e {\n    console.log(`${detail.key} was removed.`);\n});\n\nls.on('ls.clear', () =\u003e {\n    console.log('localStorage was cleared.');\n})\n\nls.set('name', 'John Doe');\nls.set('age', 35);\n\nsetTimeout(() =\u003e {\n    ls.remove('name');\n\n    setTimeout(() =\u003e {\n        ls.clear();\n    }, 2500);\n}, 2500);\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscript47%2Flocal-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscript47%2Flocal-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscript47%2Flocal-storage/lists"}