{"_id":"@alsolovyev/local-storage","_rev":"6-fd29aa2e06ea527fe280d42446c2df46","name":"@alsolovyev/local-storage","dist-tags":{"latest":"0.2.1"},"versions":{"0.1.0":{"name":"@alsolovyev/local-storage","description":"Simplified local storage API for any environment","version":"0.1.0","license":"ISC","author":{"name":"Aleksey Solovyev","email":"solovyev.a@icloud.com","url":"https://alsolovyev.github.io"},"homepage":"https://github.com/alsolovyev/npm-packages/tree/master/packages/local-storage#readme","bugs":{"url":"https://github.com/alsolovyev/npm-packages/issues","email":"solovyev.a@icloud.com"},"keywords":["storage","localstorage","local-storage"],"scripts":{"build":"pnpm run build:types && pnpm run build:pkg","build:pkg":"node scripts/build.js","build:types":"tsc --project ./tsconfig.types.json && node scripts/renameModuleName.js","test":"jest"},"publishConfig":{"access":"public"},"main":"dist/cjs/index.js","module":"dist/esm/index.js","types":"types/index.d.ts","exports":{".":{"types":"./types/index.d.ts","require":"./dist/cjs/index.js","import":"./dist/esm/index.js"}},"devDependencies":{"@swc/cli":"^0.1.57","@swc/core":"^1.3.23","typescript":"^4.9.4"},"gitHead":"51b45e96ab7c57eb116b3dfad258c42f5e7128c1","_id":"@alsolovyev/local-storage@0.1.0","_nodeVersion":"18.4.0","_npmVersion":"8.12.1","dist":{"integrity":"sha512-fWSxZi+VN8yhHczHs00u+1137qeHwi2nzbTM6X/1j4yJkgCqLg5/n4rbxXfqT0Zy8EGpqQOu8p4Kjiqzk4ZzkQ==","shasum":"4825c9519e4f3a21ecf28448a421e9f900624b81","tarball":"https://registry.npmjs.org/@alsolovyev/local-storage/-/local-storage-0.1.0.tgz","fileCount":5,"unpackedSize":16251,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDB5DL2m51uN4vGfMBlK9nmSqetWhBRezaCC0XgcY+2qAiEA5AG3ECXeeSTO3cxAd5WlJNjuF1jgqdZL7arQmHri4Yg="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjqC+OACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmqm4hAAi3yDQEvjZcFV5dA4X73Uaz3jHBDi+19YW7IHfbCGoFV+qWw/\r\nA1r8fvcXYqqAsMgJCw6WBdjgiS1Z+CnlwY9HeNesA+NBVi/0Om4WnJ0oVo3n\r\nHNsS9mTPU1obyBkPTeMkeija9C6PmgrM28rBuIIla7M32Uxuvt9RYdIMDYsN\r\nMj/vLsq0Yd0/sAanLMoh1cFCKkqYZNT1RtCOnaFg30G4Z0zy1dgy3EglQzxr\r\nFSSKihHmhqc1ND/shJhxtt8Lpag7ur/add6Kpjg3A50V+VbkD4ZA9wWgpqz8\r\n/zI5ggxa2Yqj0mvvIGDQi+fq2Qa4oMb3oiA57+1vQ7kT3vPejx108du/PnAe\r\nkqXQzdpc/5QtwaMiN076LJPSUeTA96e1s8dvKYjhb9mE1oP7oc2RunppzomH\r\nGUq+oiNsZfYiXsH1AZyVU4qmoEXSLqhPb35IvDlB7tXC5K16W4nZKDODEzTi\r\nDyJWZZtJU5+tNT3sj7twHDKvNpvl8oGeeVtBFsTykGApm/Duw4gk8mV5tRZ6\r\nb/vVKNxy16hd1NUIriS1UPL/15nPsL00P/DZuGnZEd8G+KC6eTRQ2grn4uXJ\r\nOaaiK9P6IJ7EVQWbAmrn8RYZHpgWqQfwu+gNs5fwEegTL3A0egsNXHXN/NQp\r\nlHeHFk2okXg01xVDJ+6KJ8ueAmzBk8apsh8=\r\n=3P6z\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"alsolovyev","email":"solovyev.a@icloud.com"},"directories":{},"maintainers":[{"name":"alsolovyev","email":"solovyev.a@icloud.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/local-storage_0.1.0_1671966606508_0.4504646574294271"},"_hasShrinkwrap":false},"0.2.0":{"name":"@alsolovyev/local-storage","description":"Simplified local storage API for any environment","version":"0.2.0","license":"ISC","author":{"name":"Aleksey Solovyev","email":"solovyev.a@icloud.com","url":"https://alsolovyev.github.io"},"homepage":"https://github.com/alsolovyev/npm-packages/tree/master/packages/local-storage#readme","bugs":{"url":"https://github.com/alsolovyev/npm-packages/issues","email":"solovyev.a@icloud.com"},"keywords":["storage","localstorage","local-storage"],"scripts":{"build":"pnpm run build:types && pnpm run build:pkg","build:pkg":"node scripts/build.js","build:types":"tsc --project ./tsconfig.types.json && node scripts/renameModuleName.js","test":"jest"},"publishConfig":{"access":"public"},"main":"dist/cjs/index.js","module":"dist/esm/index.js","types":"types/index.d.ts","exports":{".":{"types":"./types/index.d.ts","require":"./dist/cjs/index.js","import":"./dist/esm/index.js"}},"devDependencies":{"@swc/cli":"^0.1.57","@swc/core":"^1.3.23","typescript":"^4.9.4"},"gitHead":"5133a73fe6579632ff1c7aadbc3c5a4def8f5e20","_id":"@alsolovyev/local-storage@0.2.0","_nodeVersion":"18.4.0","_npmVersion":"8.12.1","dist":{"integrity":"sha512-AUho39EvDvzg/JzBcgMG5ja+/BZT3uQv6pYMfA7aLbPXXFXj1qfq1okR5PeXstmxtKFpwDbxUxxr3qOxxtryqw==","shasum":"5a3b3ae52465661380860041dae81338d5bffa8e","tarball":"https://registry.npmjs.org/@alsolovyev/local-storage/-/local-storage-0.2.0.tgz","fileCount":5,"unpackedSize":16962,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIF5DMWgRZ1Lk8UxqVLQ+W1NU73zVOg2+kq2pfuDN94CrAiA0GWlokSp/ZuhzNR448b2VXZv1lC75fCIIwyPf2PNLAQ=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjqr5nACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpnoA/9HtEjJJeJBOM425sP1FNFiWb+njfVhh3bDijh9cMIYg8UmG+8\r\ntU36O3XrYQtNpn5LKEmSNzCuV/NWPbQy0hLhQ/S0vj+SjB5IEYHzaqTEzkgg\r\nLYzrFTRMSwhPknUIZwamMPFIfTCEKGw0hl0398vYKHFe4xeP/FTkNatptYDk\r\nKrtQVlUGiUdxXOYj2tih+cHnpfbUwYVfD71bC3BJlxclG7Z4zaz/6xMTSig3\r\n6bGrWxsC9oPW7egox/B9v5qbp6VKv9FfSBUn2wyRDgGleerWHumwZ8A1ddPm\r\nM2NNVmad3vohZdw9P7atT5V/0F2RD1sBE+mgRTiRzZxNjy8obTCGghNhj3dt\r\nUTHZYjjQBS7c434xiqIm8cfajFZwaJc5mCecyfvFR0aZ6Z7+QU8FiePNkTlP\r\nyJvk0q6P1cjxFa8zeyZwVwckQfChvtgUDGUp3QNndcfEJu7KpohbH2g4iakl\r\nSJ7PJZOvszdbTdl/rGJ8Q3UYnH65jikeRtGM6ASjPIZYMGV6uy4QCIgwYvAm\r\ns0/R955n4f5HtAP8zz7RoFE2wDh93hq8JcpIPAN6rLC8PIWm1SjawQ6eBneq\r\n/o9v1YWg9pr4eJk/GqbZDvH9FFE/i0owEBqpdgCzmtvlqlhJID172kLAfOiE\r\ngNdtALNEh4qjLGCUmDzNUYditxTP4zlrLyk=\r\n=kE+6\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"alsolovyev","email":"solovyev.a@icloud.com"},"directories":{},"maintainers":[{"name":"alsolovyev","email":"solovyev.a@icloud.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/local-storage_0.2.0_1672134247449_0.5028285079413402"},"_hasShrinkwrap":false},"0.2.1":{"name":"@alsolovyev/local-storage","description":"Simplified local storage API for any environment","version":"0.2.1","license":"ISC","author":{"name":"Aleksey Solovyev","email":"solovyev.a@icloud.com","url":"https://alsolovyev.github.io"},"homepage":"https://github.com/alsolovyev/npm-packages/tree/master/packages/local-storage#readme","bugs":{"url":"https://github.com/alsolovyev/npm-packages/issues","email":"solovyev.a@icloud.com"},"keywords":["storage","localstorage","local-storage"],"scripts":{"build":"pnpm run build:types && pnpm run build:pkg","build:pkg":"node scripts/build.js","build:types":"tsc --project ./tsconfig.types.json && node scripts/renameModuleName.js","test":"jest"},"publishConfig":{"access":"public"},"main":"dist/cjs/index.js","module":"dist/esm/index.js","types":"types/index.d.ts","exports":{".":{"types":"./types/index.d.ts","require":"./dist/cjs/index.js","import":"./dist/esm/index.js"}},"devDependencies":{"@swc/cli":"^0.1.57","@swc/core":"^1.3.23","typescript":"^4.9.4"},"_id":"@alsolovyev/local-storage@0.2.1","gitHead":"e4b1c309e6ec12c483ac451915aff691c7d7caaa","_nodeVersion":"20.6.1","_npmVersion":"9.8.1","dist":{"integrity":"sha512-BMcSzEHGKEdl3vyGFSmYclVzG6Q3pE4HLuuXjHwfoxxSfcGILW94ljmVHKCSzujeZzHtTKcS5ELHYtI77hoh7A==","shasum":"6b4133647524144e4dfaf12e13e5dfd4047f9fed","tarball":"https://registry.npmjs.org/@alsolovyev/local-storage/-/local-storage-0.2.1.tgz","fileCount":5,"unpackedSize":21571,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIA9IKZl6rl/sgjNn1w3QSh20+adw7ocahneOgxaw9RLtAiEA2sJqQ1QXqTqJ2f6oteBq9tunSpFTF8B92uUiF4BQ1y4="}]},"_npmUser":{"name":"alsolovyev","email":"solovyev.a@icloud.com"},"directories":{},"maintainers":[{"name":"alsolovyev","email":"solovyev.a@icloud.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/local-storage_0.2.1_1694804961101_0.2575760791470372"},"_hasShrinkwrap":false}},"time":{"created":"2022-12-25T11:10:06.457Z","0.1.0":"2022-12-25T11:10:06.683Z","modified":"2023-09-15T19:09:21.450Z","0.1.1":"2022-12-25T11:12:56.083Z","0.1.2":"2022-12-25T11:33:56.593Z","0.2.0":"2022-12-27T09:44:07.595Z","0.2.1":"2023-09-15T19:09:21.277Z"},"maintainers":[{"name":"alsolovyev","email":"solovyev.a@icloud.com"}],"description":"Simplified local storage API for any environment","homepage":"https://github.com/alsolovyev/npm-packages/tree/master/packages/local-storage#readme","keywords":["storage","localstorage","local-storage"],"author":{"name":"Aleksey Solovyev","email":"solovyev.a@icloud.com","url":"https://alsolovyev.github.io"},"bugs":{"url":"https://github.com/alsolovyev/npm-packages/issues","email":"solovyev.a@icloud.com"},"license":"ISC","readme":"<br />\n<div align=\"center\">\n  <img src=\"https://raw.githubusercontent.com/alsolovyev/npm-packages/master/packages/local-storage/assets/icon.png?raw=true\" width=\"50\" alt=\"Local Storage Package\"/>\n  <h1>Local Storage</h1>\n  <p>Simplified local storage API for any environment, <br/> if local storage is not supported, in-memory storage will be used as a fallback.</p>\n\n  <p>\n    <a href=\"https://github.com/alsolovyev/npm-packages/blob/master/LICENSE\">\n      <img src=\"https://img.shields.io/badge/license-MIT-blue.svg\" alt=\"npm packages are released under the MIT license.\" />\n    </a>\n    <img src=\"https://img.shields.io/badge/PRs-welcome-brightgreen.svg\" alt=\"PRs welcome!\" />\n  </p>\n</div>\n\n![Local Storage Package](https://raw.githubusercontent.com/alsolovyev/npm-packages/master/packages/local-storage/assets/thumbnail.jpg)\n\n<br />\n\n## Features\n\n- support for devices without local storage\n- support for custom storage engine\n- automatic parsing of data upon receipt\n- an optional default value as a fallback\n- type safety\n\n<br />\n\n## Usage\n\n### Installation:\n\n```sh\nnpm install @alsolovyev/local-storage\n```\n\n### Basic example:\n\n```ts\n// For CommonJS:\n// const LocalStorage = require('@alsolovyev/local-storage').default\nimport LocalStorage from '@alsolovyev/local-storage'\n\ninterface IUser {\n  _id: number\n  name: string\n  email: string\n}\n\nconst myLocalStorage = new LocalStorage()\nconst USER_KEY = 'user'\nconst user: IUser = {\n  _id: 0,\n  name: 'Jane Rivas',\n  email: 'solovyev.a@icloud.com'\n}\n\nmyLocalStorage.set(USER_KEY, user)\nmyLocalStorage.get<IUser | Pick<IUser, '_id'>>(USER_KEY, { _id: -1 })\nmyLocalStorage.remove(USER_KEY)\n```\n\n### Custom storage engine example:\n\n```ts\nimport LocalStorage from '@alsolovyev/local-storage'\nimport type { IStorageEngine } from '@alsolovyev/local-storage'\n\ninterface IUser {\n  _id: number\n  name: string\n  email: string\n}\n\nclass CustomStorageEngine implements IStorageEngine {\n  get length(): number {\n    /* ... */\n  }\n  clear(): void {\n    /* ... */\n  }\n  getItem(key: string): string {\n    /* ... */\n  }\n  removeItem(key: string): void {\n    /* ... */\n  }\n  setItem(key: string, value: string): void {\n    /* ... */\n  }\n}\n\nconst myStorage = new LocalStorage(new CustomStorageEngine())\nconst USER_KEY = 'user'\nconst user: IUser = {\n  _id: 0,\n  name: 'Jane Rivas',\n  email: 'solovyev.a@icloud.com'\n}\n\nmyStorage.set(USER_KEY, user)\nmyStorage.get<IUser | Pick<IUser, '_id'>>(USER_KEY, { _id: -1 })\nmyStorage.remove(USER_KEY)\n```\n\n<br />\n\n## Interfaces\n\n````ts\nexport interface IStorageEngine\n  extends Pick<Storage, 'clear' | 'getItem' | 'length' | 'removeItem' | 'setItem'> {}\n\nexport interface ILocalStorage {\n  readonly length: number\n  clear(): boolean\n  get<T>(key: string, defaultValue?: T): T | null\n  remove(key: string): boolean\n  set<T>(key: string, value: T): boolean\n}\n\n/**\n * A class to simplify work with local storage.\n *\n * @remarks\n * If local storage is not supported, in-memory storage will be used as a fallback.\n *\n * @param [customStorageEngine] - implementation of a custom storage engine\n *\n * @example\n * Basic usage:\n * ```ts\n * const localStorage = new LocalStorage()\n * localStorage.set('key', { a: 1, b: ['uno', 'dos', 'tres'] })\n * localStorage.get<{ a: number, b: string[] }>('key', { a: 1, b: [] })\n * localStorage.remove('key')\n * ```\n *\n * @example\n * Use with a custom storage engine:\n * ```ts\n * const customStorage = new LocalStorage(customEngine)\n * customStorage.set('key', { a: 1, b: ['uno', 'dos', 'tres'] })\n * customStorage.get<{ a: number, b: string[] }>('key', { a: 1, b: [] })\n * customStorage.remove('key')\n * ```\n */\nexport default class LocalStorage implements ILocalStorage {\n  private readonly _storageEngine\n\n  constructor(customStorageEngine?: IStorageEngine)\n\n  /**\n   * The number of key/value pairs currently present in local storage.\n   * @readonly\n   */\n  get length(): number\n\n  /**\n   * Removes all key/value pairs from the store, if any.\n   *\n   * @returns true if removing was successful, otherwise false\n   */\n  clear(): boolean\n\n  /**\n   * Returns the current value associated with the given key.\n   * If the given key does not existin the list associated with the object,\n   * then it returns the default value or null.\n   *\n   * @remarks\n   * The return value is automatically parsed using JSON.parse()\n   *\n   * @param key - the key to look up the value in local storage\n   * @param [defaultValue] - the fallback value\n   * @returns the current value associated with the given key, or null\n   *\n   * @example Basic example:\n   * ```ts\n   * const localStorage = new LocalStorage()\n   * localStorage.get<string>('key')\n   * ```\n   *\n   * @example Default value example:\n   * ```ts\n   * const localStorage = new LocalStorage()\n   * localStorage.get<string>('key', 'default value')\n   * ```\n   */\n  public get<T>(key: string): T | null\n  public get<T>(key: string, defaultValue: T): T\n  public get<T>(key: string, defaultValue?: T): T | null\n\n  /**\n   * Removes the key/value pair with the given key from the list associated\n   * with the object, if a key/value pair with the given key exists.\n   *\n   * @param key - the key to be removed from local storage\n   * @returns true if the key/value has been removed, otherwise false\n   */\n  remove(key: string): boolean\n\n  /**\n   * Sets the value of the pair identified by key to value, creating\n   * a new key/value pair if none existed for key previously.\n   *\n   * @remark\n   * The value will be converted to a string using JSON.stringify() before being stored\n   *\n   * @param key - the key by which a value will be stored in local storage\n   * @param value - the value to be stored\n   *\n   * @returns true if the key/value has been saved, otherwise false\n   */\n  set<T>(key: string, value: T): boolean\n\n  /**\n   * Checks local storage support\n   */\n  private _checkLocalStorageSupport\n}\n````\n\n<br/>\n\n## References\n\n- [Window.localStorage - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage)\n\n<br/>\n\n## Authors\n\n- **[Aleksey Solovyev](https://github.com/alsolovyev)** - [solovyev.a@icloud.com](mailto:solovyev.a@icloud.com)\n\n<br/>\n\n## License\n\nThis project is licensed under the [MIT](https://github.com/alsolovyev/npm-packages/blob/master/LICENSE) License\n","readmeFilename":"README.md"}