{"id":25207978,"url":"https://github.com/jesusgraterol/browser-keyval-stores","last_synced_at":"2025-07-03T14:04:44.423Z","repository":{"id":272603103,"uuid":"917143694","full_name":"jesusgraterol/browser-keyval-stores","owner":"jesusgraterol","description":"The browser-keyval-stores package offers a clean and unified API to interact with browser storage mechanisms (localStorage, sessionStorage, and indexedDB) from your applications. It streamlines development and eliminates the need for browser-specific code when working with client-side data storage.","archived":false,"fork":false,"pushed_at":"2025-02-06T18:17:33.000Z","size":89,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-15T06:11:34.009Z","etag":null,"topics":["browser","database","indexeddb","localstorage","sessionstorage","storage"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/browser-keyval-stores","language":"TypeScript","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/jesusgraterol.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-01-15T12:45:50.000Z","updated_at":"2025-02-06T18:17:43.000Z","dependencies_parsed_at":"2025-01-16T15:07:12.187Z","dependency_job_id":"ac65ad54-6cca-4884-a59f-47600aa223b1","html_url":"https://github.com/jesusgraterol/browser-keyval-stores","commit_stats":null,"previous_names":["jesusgraterol/browser-dbs","jesusgraterol/browser-keyval-stores"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/jesusgraterol/browser-keyval-stores","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jesusgraterol%2Fbrowser-keyval-stores","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jesusgraterol%2Fbrowser-keyval-stores/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jesusgraterol%2Fbrowser-keyval-stores/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jesusgraterol%2Fbrowser-keyval-stores/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jesusgraterol","download_url":"https://codeload.github.com/jesusgraterol/browser-keyval-stores/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jesusgraterol%2Fbrowser-keyval-stores/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263339819,"owners_count":23451512,"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":["browser","database","indexeddb","localstorage","sessionstorage","storage"],"created_at":"2025-02-10T12:17:49.724Z","updated_at":"2025-07-03T14:04:44.393Z","avatar_url":"https://github.com/jesusgraterol.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Browser KeyVal Stores\n\nThe `browser-keyval-stores` package offers a clean and unified API to interact with browser storage mechanisms ([`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage), [`sessionStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage), and [`indexedDB`](https://developer.mozilla.org/en-US/docs/Web/API/Window/indexedDB)) from your applications. It streamlines development and eliminates the need for browser-specific code when working with client-side data storage.\n\n\n\n\n\n\u003c/br\u003e\n\n## Getting Started\n\nInstall the package:\n```bash\nnpm install -S browser-keyval-stores\n```\n\n\n### Usage\n\n#### `localStorage` Store\n\n```typescript\nimport { LocalStorageStore } from 'browser-keyval-stores';\n\ntype IUserPreferences = {\n  language: string,\n  theme: string\n};\n\nconst store = new LocalStorageStore\u003cIUserPreferences\u003e('userPreferences');\n\nconst uid = '2d22df80-fc4b-498a-a4a7-734daa71c8dd';\n\nstore.get(uid);\n// undefined\n\nstore.set(uid, { language: 'en', theme: 'dark' });\nstore.get(uid);\n// { language: 'en', theme: 'dark' }\n\nstore.set(uid, { language: 'es', theme: 'light' });\nstore.get(uid);\n// { language: 'es', theme: 'light' }\n\nstore.del(uid);\nstore.get(uid);\n// undefined\n```\n\n#### `sessionStorage` Store\n\n```typescript\nimport { SessionStorageStore } from 'browser-keyval-stores';\n\ntype IApplicationFormData = {\n  fullName: string,\n  passportNum: string,\n};\n\nconst store = new SessionStorageStore\u003cIApplicationFormData\u003e('applicationForm');\n\nstore.get();\n// undefined\n\nstore.set(undefined, { fullName: 'Jess Grateol', passportNum: 'P4366918' });\nstore.get();\n// { fullName: 'Jess Grateol', passportNum: 'P4366918' }\n\nstore.set(undefined, { fullName: 'Jesus Graterol', passportNum: 'LA080402' });\nstore.get();\n// { fullName: 'Jesus Graterol', passportNum: 'LA080402' }\n\nstore.del();\nstore.get();\n// undefined\n```\n\n#### `indexedDB` Store\n\n```typescript\nimport { IndexedDBStore } from 'browser-keyval-stores';\n\ntype IBlogPost = {\n  id: number,\n  title: string,\n  content: string,\n};\n\nconst store = new IndexedDBStore\u003cIBlogPost\u003e('blogPosts');\n\nawait store.set(1, { id: 1, title: 'Test title', content: 'This is the ...'});\nawait store.get(1);\n// { id: 1, title: 'Test title', content: 'This is the ...'}\n\nawait store.del(1);\nawait store.get(1);\n// undefined\n```\n\n\n\n### Types\n\n\u003cdetails\u003e\n  \u003csummary\u003e\u003ccode\u003eIStoreMechanism\u003c/code\u003e\u003c/summary\u003e\n\n  The supported browser storage mechanisms.\n  ```typescript\n  type IStoreMechanism = 'tempMemory' | 'localStorage' | 'sessionStorage' | 'indexedDB';\n  ```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003e\u003ccode\u003eIRecordID\u003c/code\u003e\u003c/summary\u003e\n\n  The identifier used to manage records. The store behaves differently based on the type:\n  - `undefined`: the data will be stored at the root of the store\n  - `string` | `number`: the value will be coerced into a string and can be used to locate the data\n  ```typescript\n  type IRecordID = undefined | string | number;\n  ```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003e\u003ccode\u003eIWebStorageStore\u003cT\u003e\u003c/code\u003e\u003c/summary\u003e\n\n  Object in charge of interacting with the Browser's Storage API. This API is used by [`Window.localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) \u0026 [`Window.sessionStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage).\n  ```typescript\n  interface IWebStorageStore\u003cT\u003e {\n    // properties\n    id: string;\n\n    // methods\n    isCompatible: () =\u003e boolean;\n    get: (id?: IRecordID) =\u003e T | undefined;\n    set: (id: IRecordID, data: T) =\u003e void;\n    del: (id?: IRecordID) =\u003e void;\n  }\n\n  interface ILocalStorageStore\u003cT\u003e extends IWebStorageStore\u003cT\u003e {\n    // ...\n  }\n\n  interface ISessionStorageStore\u003cT\u003e extends IWebStorageStore\u003cT\u003e {\n    // ...\n  }\n  ```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003e\u003ccode\u003eIIndexedDBStore\u003cT\u003e\u003c/code\u003e\u003c/summary\u003e\n\n  Object in charge of charge of interacting with the Browser's `IndexedDB` implementation.\n  ```typescript\n  interface IIndexedDBStore\u003cT\u003e {\n    // properties\n    id: string;\n\n    // methods\n    isCompatible(): Promise\u003cboolean\u003e;\n    get: (id?: IRecordID) =\u003e Promise\u003cT | undefined\u003e;\n    set: (id: IRecordID, data: T) =\u003e Promise\u003cvoid\u003e;\n    del: (id?: IRecordID) =\u003e Promise\u003cvoid\u003e;\n  }\n  ```\n\u003c/details\u003e\n\n\n\n\n\n\u003cbr/\u003e\n\n## Built With\n\n- TypeScript\n\n\n\n\n\n\u003cbr/\u003e\n\n## Running the Tests\n\n```bash\n# integration tests\nnpm run test:integration\n\n# unit tests\nnpm run test:unit\n```\n\n\n\n\n\n\u003cbr/\u003e\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n\n\n\n\n\n\u003cbr/\u003e\n\n## Deployment\n\nInstall dependencies:\n```bash\nnpm install\n```\n\n\nBuild the library:\n```bash\nnpm start\n```\n\n\nPublish to `npm`:\n```bash\nnpm publish\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjesusgraterol%2Fbrowser-keyval-stores","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjesusgraterol%2Fbrowser-keyval-stores","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjesusgraterol%2Fbrowser-keyval-stores/lists"}