{"_id":"isostore","_rev":"3184286","name":"isostore","description":"A simple isomorphic key-value store with a Map-like API for persisting data.","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"fabiospampinato","email":"spampinabio@gmail.com"}],"time":{"modified":"2023-12-06T08:50:13.000Z","created":"2023-02-15T01:36:54.331Z","1.0.0":"2023-02-15T01:36:54.331Z"},"users":{},"repository":{"type":"git","url":"git+https://github.com/fabiospampinato/isostore.git"},"versions":{"1.0.0":{"name":"isostore","repository":{"type":"git","url":"git+https://github.com/fabiospampinato/isostore.git"},"description":"A simple isomorphic key-value store with a Map-like API for persisting data.","version":"1.0.0","type":"module","main":"dist/node.js","types":"./dist/node.d.ts","sideEffects":false,"exports":{"node":"./dist/node.js","default":"./dist/browser.js"},"scripts":{"clean":"tsex clean","compile":"tsex compile","compile:watch":"tsex compile --watch","test":"tsex test","test:watch":"tsex test --watch","prepublishOnly":"tsex prepare"},"keywords":["isomorphic","key","value","store","storage"],"dependencies":{"atomically":"^2.0.1","memoization-registry":"^1.0.1","when-exit":"^2.1.0"},"devDependencies":{"@types/node":"^18.13.0","fava":"^0.1.2","tsex":"^2.1.0","typescript":"^4.9.5"},"gitHead":"059cd11e0364ad961951b490db217d3cfdf109f2","bugs":{"url":"https://github.com/fabiospampinato/isostore/issues"},"homepage":"https://github.com/fabiospampinato/isostore#readme","_id":"isostore@1.0.0","_nodeVersion":"18.12.0","_npmVersion":"8.19.2","dist":{"shasum":"7618d9ccbe6bafac787023191824f2cbb85bd02f","size":8426,"noattachment":false,"key":"/isostore/-/isostore-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/isostore/download/isostore-1.0.0.tgz"},"_npmUser":{"name":"fabiospampinato","email":"spampinabio@gmail.com"},"directories":{},"maintainers":[{"name":"fabiospampinato","email":"spampinabio@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/isostore_1.0.0_1676425014159_0.6613261185070998"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-02-15T01:36:54.331Z","publish_time":1676425014331,"_cnpm_publish_time":1676425014331}},"readme":"# IsoStore\n\nA simple isomorphic key-value store with a Map-like API for persisting data.\n\n## Features\n\n- All stores run everywhere, they just have different backends under the hood.\n- All stores are not intended for performance-critical use cases, since the entire store is saved when a change is made in it.\n- Store saves are batched automatically within a microtask, so performance is not as bad as it could be.\n- When instantiating multiple stores of the same type and with the same id you'll actually always receive the same instance back.\n- Only alphanumeric store ids are allowed, the library will throw on invalid ids.\n\n## Stores\n\nThe following stores are provided:\n\n- `AbstractStore`: A generic store with no backend, for using a custom persistence mechanism.\n- `MemoryStore`: An in-memory store, useful if you don't need persistence, but you want to use the same API.\n- `LocalStore`: A store for persisting data reliably and indefinitely.\n  - Node: it will atomically write a file to disk, in a non-temporary path that depends on your OS.\n  - Browser: it will use the `localStorage` API.\n- `SessionStore`: A store per persisting data somewhat unreliably and/or not indefinitely.\n  - Node: it will non-atomically write a temporary file to disk, which could be deleted at any time.\n  - Browser: it will use the `sessionStorage` API.\n\n## Install\n\n```sh\nnpm install --save isostore\n```\n\n## Usage\n\n```ts\nimport {AbstractStore, LocalStore, MemoryStore, SessionStore} from 'isostore';\n\n// Creating a local store, for indefinite persistence\n\nconst store = new LocalStore ( 'my-store' ); // The id of the store decides the name of the file on disk\n\nstore.has ( 'foo' ); // => false\nstore.set ( 'foo', 'some_string' ); // => store\nstore.get ( 'foo' ); // => 'some_string'\nstore.delete ( 'foo' ); // => true\n\n// Creating another local store, with the same id\n\nconst store2 = new LocalStore ( 'my-store' );\n\nconsole.log ( store === store2 ); // => true, with ???? magic ????\n\n// Creating a session store, for temporary persistence\n\nconst store3 = new SessionStore ( 'my-store' );\n\n// Creating an in-memory store, for no persistence\n\nconst store4 = new MemoryStore ();\n\n// Creating a custom store, with a custom backend\n\nconst MY_BACKEND = { // It's important to define this outside of the store class\n  read ( id ) {\n    // Return a [string, string][]\n  },\n  write ( id, entries ) {\n    // Write the entries somewhere\n  }\n};\n\nclass MyStore extends AbstractStore {\n  constructor ( id ) {\n    super ({\n      id,\n      backend: MY_BACKEND\n    });\n  }\n}\n\nconst store5 = new MyStore ( 'my-store' );\n```\n\n## License\n\nMIT © Fabio Spampinato\n","_attachments":{},"homepage":"https://github.com/fabiospampinato/isostore#readme","bugs":{"url":"https://github.com/fabiospampinato/isostore/issues"}}