{"id":14964022,"url":"https://github.com/azerion/phaser-super-storage","last_synced_at":"2026-03-15T22:07:19.648Z","repository":{"id":57100111,"uuid":"63939540","full_name":"azerion/phaser-super-storage","owner":"azerion","description":"A cross platform storage plugin for Phaser","archived":false,"fork":false,"pushed_at":"2019-03-19T16:16:48.000Z","size":701,"stargazers_count":52,"open_issues_count":0,"forks_count":4,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-10-30T00:43:03.427Z","etag":null,"topics":["cookie","localstorage","namespace","phaser","phaser-plugin","storage"],"latest_commit_sha":null,"homepage":null,"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/azerion.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}},"created_at":"2016-07-22T09:02:04.000Z","updated_at":"2024-05-29T10:56:37.000Z","dependencies_parsed_at":"2022-09-05T18:50:21.444Z","dependency_job_id":null,"html_url":"https://github.com/azerion/phaser-super-storage","commit_stats":null,"previous_names":["orange-games/phaser-super-storage"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azerion%2Fphaser-super-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azerion%2Fphaser-super-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azerion%2Fphaser-super-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azerion%2Fphaser-super-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/azerion","download_url":"https://codeload.github.com/azerion/phaser-super-storage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238030233,"owners_count":19404860,"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":["cookie","localstorage","namespace","phaser","phaser-plugin","storage"],"created_at":"2024-09-24T13:32:29.083Z","updated_at":"2025-10-25T03:31:09.320Z","avatar_url":"https://github.com/azerion.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Phaser Super Storage\n====================\nA cross platform pluggable storage plugin for Phaser.\n\nKey features:\n - Cross browser support\n - Cookie Fallback\n - Support for iframes with helper script\n - Support for custom storage adapters\n \nRequirements\n - If you use TypeScript, also include the types for es6-promise in your project\n\nGetting Started\n===============\nFirst you want to get a fresh copy of the plugin. You can get it from this repo or from npm, ain't that handy.\n```\nnpm install @azerion/phaser-super-storage --save-dev\n```\n\nNext up you'd want to add it to your list of js sources you load into your game\n```html\n\u003cscript src=\"path/to/phaser-super-storage.min.js\"\u003e\u003c/script\u003e\n```\n\nAfter adding the script to the page you can activate it by enabling the plugin:\n```javascript\ngame.add.plugin(PhaserSuperStorage.StoragePlugin);\n```\n\nUsage\n=====\nWhen you load the plugin, it automatically checks for availability of localStorage and fallbacks to cookies if it's not available.\nBoth of these are StorageAdapters and will be overwritten if you register a custom StorageAdaper, but more on this later.\n\nThe plugin will append the Phaser game object with a storage object, you can reference this object with exactly the same API as localStorage, and should therefore be fairly easy for you to implement.\n\n```javascript\n//Store Tetris at FavoriteGame\ngame.storage.setItem('FavoriteGame', 'Tetris');\n\n//Get FavoriteGame\nvar favoriteGame = game.storage.getItem('FavoriteGame');  // Tetris\n\n//Remove FavoriteGame\ngame.storage.removeItem('FavoriteGame');\n\n//get the length of all items in storage\nvar l = game.storage.length;    // 1\n\n//Get the name of the key at the n'th position\nvar keyName = game.storage.key(0); // FavoriteGame\n\n//Clear all keys\ngame.storage.clear();\n```\n\nNamespaces\n----------\nIf you are like us, and put multiple games on the same domain, you might want to add namespaces to your localStorage. Namespaces get prepended to any key value pair you set, and all API calls to the storage object are segregated by namespaces.\nThis allows you to set a 'score' key for multiple games on the same domain, and they'll always get their own stored value\n\n```javascript\ngame.storage.setNamespace('tetris');\ngame.storage.setItem('score', 250);\n\ngame.storage.setNamespace('pong');\n\n//Length also takes namespaces into account\nvar l = game.storage.length;    // 0\n\n//this won't do because the score was registered under a different namespace\nvar value = game.storage.get('score'); // null\n\n```\n\nPromises\n--------\nBoth Cookies and localStorage work synchronous, meaning you immediately get a return value after calling a function, e.g; `getItem('key');`\nBut when you are using a HTTP service (Amazon Cognito Sync, or custom REST server) or when you are using the iFrameStorage supported by this library, the results are coming back in an asynchronous manner.\nIn order for you to parse your result nicely phaser-super-storage uses Promises to get you the result.\n\nIt is also possible to enable promises on the Cookie and localStorage adapters by setting forcePromises to true.\n```javascript\n//classical way of getting your item\nvar item = game.storage.getItem('key');\n\n//Now we are gonna force promises\ngame.storage.forcePromises = true;\ngame.storage.getItem('key').then(function (item) {\n    //do something with the item here\n});\n```\n\nAdapters\n========\nThe actual Storage of content happens within these so-called StorageAdapters. Basicly a StorageAdapter can store data somewhere, as long as it implements the following interface:\n```typescript\n interface IStorage {\n    //Promises or no Promises\n    forcePromises: boolean;\n\n    //The amount of items in the storage\n    length: number;\n\n    //The namespace for the current storage\n    namespace:string;\n\n    //Get an item from the storage\n    getItem(key: string): any | Promise\u003cany\u003e;\n\n    //remove an item from the localStorage\n    removeItem(key: string): any | Promise\u003cany\u003e;\n\n    //Set an item in the storage\n    setItem(key: string, value:any): void | Promise\u003cvoid\u003e;\n\n    //Get the n'th key\n    key(n: number): any | Promise\u003cany\u003e;\n\n    //empty the (namespaced) storage\n    clear(): void | Promise\u003cvoid\u003e;\n\n    setNamespace(namespace: string): void | Promise\u003cvoid\u003e;\n}\n```\n\nLocal \u0026 Cookie Storage\n----------------------\nThe default usage of phaser-super-storage require the LocalStorage and CookieStorage adapter. It will always try to use the LocalStorage Adapater, but when all fails it falls back to Cookie storage, no configuration needed!\n\nCordova\n-------\nYou can now also use the CordovaStorage adapter, which uses the NativeStorage plugin of Cordova. This prevents the auto-deletion of data on IOS when not having enough memory. If you are using the adapter, please note that passing the namespace in the constructor is not allowed and that it is only testable in a Cordova application. It can be enabled by the following command:\n```javascript\ngame.storage.setAdapter(new PhaserSuperStorage.StorageAdapters.CordovaStorage());\n```\n\n\nIframe\n------\nWe publish our games on HTML5 game portals through the usage of iframes, a downside of this is that for iOS both localStorage and Cookies aren't persisted for iframes. In order to counter this we included an IframeStorage adapter that should be set in the game, then the helper script included in the build folder should be loaded in the parent frame.\nThis way we'll utilize the storage capacity of the parent frame to store our data\n\n```html\n\u003c!--So in the parent frame we include the following: --\u003e\n\u003cscript src=\"http://cdn.fbrq.io/phaser-super-storage/phaser-storage-helper.min.js\" type=\"text/javascript\"\u003e\u003c/script\u003e\n```\n\n```javascript\n//Then in our game we add the iframe adapter\nvar iframeAdapter = new IframeStorage(\n    '',                     //The namespace to store the data under\n    document.referrer       //Then url of the parent domain, you need this for security reasons\n);\n\n//We call init first to see if the helper script is available, result as a Promise due to asynchronous communication\niframeAdapter.init().then(function() {\n    //It succeeded! Now set the iframe adapter as the main storage adapter\n    game.storage.setAdapter(iframeAdapter);\n}).catch(function (e) {\n    //failed to start communication with parent, so lets enable promises on the original storage adapter to keep the API the same\n    game.storage.forcePromises = true;\n});\n```\n\nCaveats\n=======\nAlthough we try our best to store data, in some cases you can consider data lost when a user closes his browser or ends his session. I'm talking of course about private browsing. Both LocalStorage and Cookies will be cleared, so if you want to keep userdata alive there I suggest you try to get people to login and use a custom StorageAdapter to save the data server-side. Please note that we use the colon as namespace appendix, so we advice you not to use it yourself.   \n\nDisclaimer\n==========\nWe at Azerion just love playing and creating awesome games. We aren't affiliated with Phaser.io. We just needed to storage some awesome data in our awesome HTML5 games. Feel free to use it for enhancing your own awesome games!\n\nPhaser Super Storage is distributed under the MIT license. All 3rd party libraries and components are distributed under their\nrespective license terms.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazerion%2Fphaser-super-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazerion%2Fphaser-super-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazerion%2Fphaser-super-storage/lists"}