{"id":18889064,"url":"https://github.com/naver/egjs-persist","last_synced_at":"2025-04-14T23:24:59.261Z","repository":{"id":22221472,"uuid":"89564640","full_name":"naver/egjs-persist","owner":"naver","description":"Provide cache interface to handle persisted data among history navigation.","archived":false,"fork":false,"pushed_at":"2023-03-02T13:50:30.000Z","size":1687,"stargazers_count":42,"open_issues_count":14,"forks_count":10,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-04-14T08:30:24.209Z","etag":null,"topics":["bfcache","cache","egjs","persist","storage"],"latest_commit_sha":null,"homepage":"https://naver.github.io/egjs-persist/","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/naver.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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}},"created_at":"2017-04-27T06:43:07.000Z","updated_at":"2024-02-26T21:39:39.000Z","dependencies_parsed_at":"2024-11-08T07:47:27.516Z","dependency_job_id":"8fed1f01-6801-4ac6-9827-d3d533d5179b","html_url":"https://github.com/naver/egjs-persist","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naver%2Fegjs-persist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naver%2Fegjs-persist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naver%2Fegjs-persist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/naver%2Fegjs-persist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/naver","download_url":"https://codeload.github.com/naver/egjs-persist/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248976544,"owners_count":21192417,"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":["bfcache","cache","egjs","persist","storage"],"created_at":"2024-11-08T07:47:21.973Z","updated_at":"2025-04-14T23:24:59.232Z","avatar_url":"https://github.com/naver.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# egjs-persist [![npm version](https://badge.fury.io/js/%40egjs%2Fpersist.svg)](https://badge.fury.io/js/%40egjs%2Fpersist) [![Build Status](https://travis-ci.org/naver/egjs-persist.svg?branch=master)](https://travis-ci.org/naver/egjs-persist) [![Coverage Status](https://coveralls.io/repos/github/naver/egjs-persist/badge.svg?branch=master)](https://coveralls.io/github/naver/egjs-persist?branch=master)\n\nProvide cache interface to handle persisted data among history navigation.\n\n## Documents\n- [Get Started and Demos](https://naver.github.io/egjs-persist/)\n- [API documentation](https://naver.github.io/egjs-persist/release/latest/doc/)\n\n## Download and Installation\n\nDownload dist files from repo directly or install it via npm. \n\n### For development (Uncompressed)\n\nYou can download the uncompressed files for development\n\n- Latest : https://naver.github.io/egjs-persist/release/latest/dist/persist.js\n- Specific version : https://naver.github.io/egjs-persist/release/[VERSION]/dist/persist.js\n\n### For production (Compressed)\n\nYou can download the compressed files for production\n\n- Latest : https://naver.github.io/egjs-persist/release/latest/dist/persist.min.js\n- Specific version : https://naver.github.io/egjs-persist/release/[VERSION]/dist/persist.min.js\n\n\n### Installation with npm\n\nThe following command shows how to install egjs-persist using npm.\n\n```bash\n$ npm install @egjs/persist\n```\n\n## How to use\n```js\nimport Persist from \"@egjs/persist\";\n\nconst persist = new Persist(key);\n\n// Get information about that page.\nconst aInfo = persist.get(\"a\");\n\n// Set information about that page.\npersist.set(\"a\", \"aa\");\n\n// Remove information about that page.\npersist.remove(\"a\");\n```\n\n### Handle the error \nIf the information stored in Persist exceeds the storage quota, a `PersistQuotaExceededError` error occurs.\n\nThe template of the error message is as follows.\n```\nUncaught PersistQuotaExceededError: Setting the value (size: 000) of 'Key' exceeded the SessionStorage's quota. The highest values of SessionStorage are {\"key0\":0}, {\"key1\":0}, {\"key2\":0}.\n```\nIf you handle the error, you can check the storage information, the key you want to save, and the size of the information.\n```js\nimport Persist, { PersistQuotaExceededError } from \"@egjs/persist\";\n\nconst persist = new Persist(key);\n\ntry {\n    // Get information about that page.\n    const aInfo = persist.get(\"a\");\n\n    // Set information about that page.\n    persist.set(\"a\", \"aa\");\n\n    // Remove information about that page.\n    persist.remove(\"a\");\n} catch (e) {\n    if (e instanceof PersistQuotaExceededError) {\n        console.log(e.key, e.size);\n    }\n}\n```\n\n\n### Used in SPA\n\nWe cannot detect changes in history. The entity using the SPA must respond to changes.\n\n#### Vanilla\n```js\nimport { updateDepth, replaceDepth } from \"@egjs/persist\";\n\n// use pushState function\nconst orgPushState = history.pushState;\n\nObject.defineProperty(history, \"pushState\", {\n    configurable: true,\n    value: (...args) =\u003e {\n        orgPushState.call(history, ...args);\n        updateDepth();\n    },\n});\n\n// or\nhistory.pushState(\"/aa\", \"title\", {});\nupdateDepth();\n\n// use replaceState function\nconst orgReplaceState = history.replaceState;\n\nObject.defineProperty(history, \"replaceState\", {\n    configurable: true,\n    value: (...args) =\u003e {\n        orgReplaceState.call(history, ...args);\n        replaceState();\n    },\n});\n\n// or\nhistory.replaceState(\"/aa\", \"title\", {});\nreplaceDepth();\n\n```\n\n#### React\n```jsx\nimport React, { useEffect } from \"react\";\nimport { Router } from \"react-router-dom\";\nimport { createBrowserHistory } from \"history\";\nimport { updateDepth } from \"@egjs/persist\";\n\nconst customHistory = createBrowserHistory();\n\nexport default function App() {\n    useEffect(() =\u003e customHistory.listen(() =\u003e {\n        updateDepth();\n    }), []);\n    return (\n    \u003cRouter history={customHistory}\u003e\n        ...\n    \u003c/Router\u003e\n  );\n}\n```\n\n#### Vue\n```js\nimport VueRouter from \"vue-router\";\nimport { updateDepth } from \"@egjs/persist\";\n\nconst router = new VueRouter();\n\nrouter.afterEach(() =\u003e {\n    updateDepth();\n});\n```\n\n## Supported Browsers\nThe following are the supported browsers.\n\n|Internet Explorer|Chrome|Firefox|Safari|iOS|Android|\n|---|---|---|---|---|---|\n|9+|latest|latest|latest|7+|2.3+ (except 3.x)|\n\n\n\n## How to start developing egjs-persist?\n\nFor anyone interested to develop egjs-persist, follow the instructions below.\n\n### Development Environment\n\n#### 1. Clone the repository\n\nClone the egjs-persist repository and install the dependency modules.\n\n```bash\n# Clone the repository.\n$ git clone https://github.com/naver/egjs-persist.git\n```\n\n#### 2. Install dependencies\n`npm` is supported.\n\n```\n# Install the dependency modules.\n$ npm install\n```\n\n#### 3. Build\n\nUse npm script to build eg.Persist\n\n```bash\n# Run webpack-dev-server for development\n$ npm start\n\n# Build\n$ npm run build\n\n# Generate jsdoc\n$ npm run jsdoc\n```\n\nTwo folders will be created after complete build is completed.\n\n- **dist** folder: Includes the **persist.js** and **persist.min.js** files.\n- **doc** folder: Includes API documentation. The home page for the documentation is **doc/index.html**.\n\n### Linting\n\nTo keep the same code style, we adopted [ESLint](http://eslint.org/) to maintain our code quality. The [rules](https://github.com/naver/eslint-config-naver/tree/master/rules) are modified version based on [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript).\nSetup your editor for check or run below command for linting.\n\n```bash\n$ npm run lint\n```\n\n### Test\n\nOnce you created a branch and done with development, you must perform a test running `npm run test` command before you push code to a remote repository.\n\n```bash\n$ npm run test\n```\nRunning a `npm run test` command will start [Mocha](https://mochajs.org/) tests via [Karma-runner](https://karma-runner.github.io/).\n\n\n## Bug Report\n\nIf you find a bug, please report it to us using the [Issues](https://github.com/naver/egjs-persist/issues) page on GitHub.\n\n\n## License\negjs-persist is released under the [MIT license](http://naver.github.io/egjs/license.txt).\n\n\n```\nCopyright (c) 2015 NAVER Corp.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaver%2Fegjs-persist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnaver%2Fegjs-persist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnaver%2Fegjs-persist/lists"}