{"id":13760207,"url":"https://github.com/andris9/jStorage","last_synced_at":"2025-05-10T10:31:53.264Z","repository":{"id":844863,"uuid":"570427","full_name":"andris9/jStorage","owner":"andris9","description":"jStorage is a simple key/value database to store data on browser side","archived":false,"fork":false,"pushed_at":"2020-05-16T21:46:48.000Z","size":266,"stargazers_count":1537,"open_issues_count":23,"forks_count":268,"subscribers_count":70,"default_branch":"master","last_synced_at":"2024-10-28T20:58:41.142Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andris9.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}},"created_at":"2010-03-19T19:47:24.000Z","updated_at":"2024-10-16T05:04:16.000Z","dependencies_parsed_at":"2022-07-05T18:08:39.528Z","dependency_job_id":null,"html_url":"https://github.com/andris9/jStorage","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andris9%2FjStorage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andris9%2FjStorage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andris9%2FjStorage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andris9%2FjStorage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andris9","download_url":"https://codeload.github.com/andris9/jStorage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224949726,"owners_count":17397221,"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":[],"created_at":"2024-08-03T13:01:05.402Z","updated_at":"2024-11-16T17:30:48.828Z","avatar_url":"https://github.com/andris9.png","language":"JavaScript","readme":"## NB!\n\n\u003e This project is in a frozen state. No more API changes. Pull requests for bug fixes are welcomed, anything else gets most probably ignored. A bug is something that breaks the application, outdated package file is not a bug.\n\n----\n\n# jStorage\n\n**jStorage** is a cross-browser key-value store database to store data locally in the browser - jStorage supports all major browsers, both in **desktop** (yes - even Internet Explorer 6) and in **mobile**.\n\nAdditionally jStorage is library agnostic, it works well with any other JavaScript library on the same webpage, be it jQuery, Prototype, MooTools or something else. Though you still need to have either a third party library (Prototype, MooTools) or [JSON2](https://github.com/douglascrockford/JSON-js/blob/master/json2.js) on the page to support older IE versions.\n\njStorage supports storing Strings, Numbers, JavaScript objects, Arrays and even native XML nodes which kind of makes it a JSON storage. jStorage also supports setting TTL values for auto expiring stored keys and - best of all - notifying other tabs/windows when a key has been changed, which makes jStorage also a local PubSub platform for web applications.\n\njStorage is pretty small, about 7kB when minified, 3kB gzipped.\n\n## Function reference\n\n### set(key, value[, options])\n\n```javascript\n$.jStorage.set(key, value, options)\n```\n\nSaves a value to local storage. key needs to be string otherwise an exception is thrown. value can be any JSONeable value, including objects and arrays or a XML node.\nCurrently XML nodes can't be nested inside other objects: `$.jStorage.set(\"xml\", xml_node)` is OK but `$.jStorage.set(\"xml\", {xml: xml_node})` is not.\n\nOptions is an optional options object. Currently only available option is options.TTL which can be used to set the TTL value to the key `$.jStorage.set(key, value, {TTL: 1000})`. NB - if no TTL option value has been set, any currently used TTL value for the key will be removed.\n\n### get(key[, default])\n\n```javascript\nvalue = $.jStorage.get(key)\nvalue = $.jStorage.get(key, \"default value\")\n```\n\nget retrieves the value if key exists, or default if it doesn't. key needs to be string otherwise an exception is thrown. default can be any value.\n\n### deleteKey(key)\n\n```javascript\n$.jStorage.deleteKey(key)\n```\n\nRemoves a key from the storage. key needs to be string otherwise an exception is thrown.\n\n### setTTL(key, ttl)\n\n```javascript\n$.jStorage.set(\"mykey\", \"keyvalue\");\n$.jStorage.setTTL(\"mykey\", 3000); // expires in 3 seconds\n```\n\nSets a TTL (in milliseconds) for an existing key. Use 0 or negative value to clear TTL.\n\n### getTTL(key)\n\n```javascript\nttl = $.jStorage.getTTL(\"mykey\"); // TTL in milliseconds or 0\n```\n\nGets remaining TTL (in milliseconds) for a key or 0 if not TTL has been set.\n\n### flush()\n\n```javascript\n$.jStorage.flush()\n```\n\nClears the cache.\n\n### index()\n\n```javascript\n$.jStorage.index()\n```\n\nReturns all the keys currently in use as an array.\n\n```javascript\nvar index = $.jStorage.index();\nconsole.log(index); // [\"key1\",\"key2\",\"key3\"]\n```\n\n### storageSize()\n\n```javascript\n$.jStorage.storageSize()\n```\n\nReturns the size of the stored data in bytes\n\n### currentBackend()\n\n```javascript\n$.jStorage.currentBackend()\n```\n\nReturns the storage engine currently in use or false if none\n\n### reInit()\n\n```javascript\n$.jStorage.reInit()\n```\n\nReloads the data from browser storage\n\n### storageAvailable()\n\n```javascript\n$.jStorage.storageAvailable()\n```\n\nReturns true if storage is available\n\n### subscribe(channel, callback)\n\n```javascript\n$.jStorage.subscribe(\"ch1\", function(channel, payload){\n    console.log(payload+ \" from \" + channel);\n});\n```\n\nSubscribes to a Publish/Subscribe channel (see demo)\n\n### publish(channel, payload)\n\n```javascript\n$.jStorage.publish(\"ch1\", \"data\");\n```\n\nPublishes payload to a Publish/Subscribe channel (see demo)\n\n### listenKeyChange(key, callback)\n\n```javascript\n$.jStorage.listenKeyChange(\"mykey\", function(key, action){\n    console.log(key + \" has been \" + action);\n});\n```\n\nListens for updates for selected key. NB! even updates made in other windows/tabs are reflected, so this feature can also be used for some kind of publish/subscribe service.\n\nIf you want to listen for any key change, use `\"*\"` as the key name\n\n```javascript\n$.jStorage.listenKeyChange(\"*\", function(key, action){\n    console.log(key + \" has been \" + action);\n});\n```\n\n### stopListening(key[, callback])\n\n```javascript\n$.jStorage.stopListening(\"mykey\"); // cancel all listeners for \"mykey\" change\n```\n\nStops listening for key change. If callback is set, only the used callback will be cleared, otherwise all listeners will be dropped.\n\n## Donate\n\nSupport jStorage development\n\n[![Donate to author](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=DB26KWR2BQX5W)\n\n## Features\n\njStorage supports the following features:\n\n  * store and retrieve data from browser storage using any JSON compatible data format (+ native XML nodes)\n  * set TTL values to stored keys for auto expiring\n  * publish and subscribe to cross-window/tab events\n  * listen for key changes (update, delete) from the current or any other browser window\n  * use any browser since IE6, both in desktop and in mobile\n\n## Browser support\n\nCurrent availability: jStorage supports all major browsers - Internet Explorer 6+, Firefox 2+,\nSafari 4+, Chrome 4+, Opera 10.50+\n\nIf the browser doesn't support data caching, then no exceptions are raised - jStorage can still\nbe used by the script but nothing is actually stored.\n\n## License\n\n[Unlicense](http://unlicense.org/) Since version 0.4.7\n\n**MIT** (versions up to 0.4.6)\n","funding_links":["https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=DB26KWR2BQX5W"],"categories":["Storage","Storage [🔝](#readme)","存储"],"sub_categories":["Runner","运行器","运行器e2e测试"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandris9%2FjStorage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandris9%2FjStorage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandris9%2FjStorage/lists"}