{"_id":"@azerion/phaser-super-storage","_rev":"13-a401f33f8bcbcff2eaabfd7e568460ba","name":"@azerion/phaser-super-storage","dist-tags":{"latest":"2.0.0-rc.1"},"versions":{"1.0.4":{"name":"@azerion/phaser-super-storage","version":"1.0.4","author":{"name":"Azerion"},"_id":"@azerion/phaser-super-storage@1.0.4","maintainers":[{"name":"zbart","email":"b.smallenburg@azerion.com"},{"name":"florisdh","email":"florisdh@gmail.com"},{"name":"fbrq","email":"fabrique@orangegames.com"},{"name":"alebles","email":"a.bles@orangegames.com"}],"contributors":[{"name":"Ale Bles","email":"a.bles@azerion.com"}],"homepage":"https://github.com/azerion/phaser-super-storage#readme","dist":{"shasum":"343252ea2e1a9dc8cdcc6cada6e2e8965c61678e","tarball":"https://registry.npmjs.org/@azerion/phaser-super-storage/-/phaser-super-storage-1.0.4.tgz","fileCount":27,"integrity":"sha512-HozMJAzX+48QAdxgVi3zWCpyzttHOciqxXA0Nd34SYGUrZGXNjwOutcS9K0f/hEu1417dOS83X7/XATCa8hakA==","signatures":[{"sig":"MEUCIQC0TjBo8kXsTmwP5pLLbD79ThgWMZVQJSZBrploaSdv2gIgayIdVaKoN/KYpD7PvDz+RA6NiYhYc0sMtPTK4cthpp4=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":99607,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJci3hrCRA9TVsSAnZWagAAJtkP/1hUOQfuf0saoPaIAlUC\npMxl3fq4UBC0OQ3TmP1rPtKCHfh+Ghz2odK8S7mUI2ZmVeT5TcYkBZB30HqA\ncRGbN/Q7FXM1KH9H8HM+bnqt6nybUjHCYWd5ImeXCYCIS0RXby/zHDj9Em5p\nDNx6hK/KMnD1SBZetks36IMkTcBYrXINbkdEUl0L4aJykZpENMtHK1MMXJ6f\n1GMVlpKM6d2xhgrRXcyuxacwLFUtOlRG6YjlgRiws4dvUSckUvz/6WrE+RFf\nX9neMPwYR+Z/pWnFyjq/qbvr4iHQrF9aLx6f3p1mx/sjM5nccLYGG/6F5CiU\naWz4L87l+RKTMkZX2pHoFOYPLqifithCm7Y7We6hONQ8s5xNLhNOwv/KN75O\nWtjinx5D+Ia9s25B2Nov8e6C0ynypPKaKF04ZeMs/RFrKj3VO+5U0B45eUSq\n7Iuq8K0OMoH3PoYpgdB1Lk6Ly5dN0hlYk8L4XlI1yOiEWgDOphA7tElyN8Oo\nAFbzYODRyeAKvK/CPNZ7GkG6wlfdoYIYZvutsMYivQwzBU98s9i0BJUpbVms\nUsAU2d8CsfguLZor9a8WOsGEn3FQrAyoP79zOjTQmI5qMuPMa4fz9yuf25ip\nq9sfVrgAxuF0Fdiv/UpdrMDYM3Q6+9hp931Awq49Wn0tF+D2SFt5BbrHk81o\nF3pT\r\n=O2Xh\r\n-----END PGP SIGNATURE-----\r\n"},"config":{"name":"phaser-super-storage"},"gitHead":"b2294c67332fbdee83ad81eda65437a260761100","_npmUser":{"name":"florisdh","email":"florisdh@gmail.com"},"licenses":[{"url":"https://github.com/azerion/phaser-super-storage/raw/master/LICENSE","type":"MIT"}],"repository":{"url":"git+ssh://git@github.com/azerion/phaser-super-storage.git","type":"git"},"_npmVersion":"6.9.0","description":"A cross platform storage plugin for Phaser","directories":{},"_nodeVersion":"8.11.1","_hasShrinkwrap":false,"devDependencies":{"grunt":"1.0.x","phaser":"2.6.2","tslint":"^3.15.1","grunt-ts":"^6.0.0-beta.3","typescript":"2.1.x","grunt-banner":"^0.6.0","grunt-tslint":"^3.3.0","@types/es6-promise":"0.0.32","grunt-contrib-clean":"1.0.x","grunt-contrib-watch":"1.0.x","grunt-contrib-concat":"1.0.x","grunt-contrib-uglify":"2.0.x","grunt-contrib-connect":"1.0.x"},"_npmOperationalInternal":{"tmp":"tmp/phaser-super-storage_1.0.4_1552644202872_0.7490628053900967","host":"s3://npm-registry-packages"}},"2.0.0-rc.1":{"name":"@azerion/phaser-super-storage","version":"2.0.0-rc.1","author":{"name":"Azerion"},"license":"MIT","_id":"@azerion/phaser-super-storage@2.0.0-rc.1","maintainers":[{"name":"alebles","email":"a.bles@orangegames.com"},{"name":"fbrq","email":"fabrique@orangegames.com"},{"name":"florisdh","email":"florisdh@gmail.com"},{"name":"zbart","email":"b.smallenburg@azerion.com"}],"contributors":[{"name":"Ale Bles","email":"a.bles@azerion.com"}],"homepage":"https://github.com/azerion/phaser-super-storage#readme","bugs":{"url":"https://github.com/azerion/phaser-super-storage/issues"},"dist":{"shasum":"5bff8233af89b76b3d85520672d09856e36761bf","tarball":"https://registry.npmjs.org/@azerion/phaser-super-storage/-/phaser-super-storage-2.0.0-rc.1.tgz","fileCount":40,"integrity":"sha512-N/GKkO1AmfM2OF3HdcIp7XbJMji6du2wqPxP2Z+kuOxtOPlLFvhJpxwJIg155a+XUDCZ2MVPA9aDlfj7XGoU1A==","signatures":[{"sig":"MEQCIAFRmlh3gIftbgXK46oxYS+cBqezsa/js8FZjUmXbEk/AiBi74GZjohO9CpC7jgB7rIaRGkfGvq5Y9jgubT/U3R4Gg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2607189,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJci3spCRA9TVsSAnZWagAAxO8QAKMY9O634WIPk54IJP2u\nn2KRHQllUkl6FKpkx1cKsUeIdW38xiQ41lDPHB7LXAmf3xePom59K5pK4RGa\naJKITxskVSnUqwZA4KP2GkNn2jEmlxGKyrz09M+7YCbZt5MNY4HL7Bep7VqO\nAcRNdjWEviMvfdiewX6FZ1AEyMOU4/0lrpjLB3+4/OZlhsCRzc6B4+GnMXAF\nXmhhKiUvagPdHMzRhi4TttC436Gv5xc6wXuA+bMlt9XRhEi/bACqWtm8F3lL\nQKtHH4gJyzL0tIAQFinn4A7N9NcB9m8YCU9/7UvfxMYkTveF74uYlebHK9Al\nxxHy9h3slcB6/ZFiHdgmmldlCa6Vzmrmr52JJeEAVV39rFzMRshTcDPDpyaD\n2Iqq9ijf0D+JbEHVJfUTikDN1s42tN8c4xlweBWlAFdR/ctNeKfEmwWcr/gv\n0tX+aK/E/dMPxjl2Ui1AJz6YelGyqr1WpiHlKpmEcE0M+cOIUH8uGrS0N/Xe\nOEPJ5jGFTVPCf7aQvieDClJMM24Hl5ckYxITn4dDV3agKJ1Csxu5QzNHXpHp\nXAOrEntWfm1nNrUZ9eRO1ow6r0o0VJeUWRHuoa887CJxIxgg33nP2MJrogg8\nrCnmE/b1L00D5sdSEWYM3u+yod1XSRkKd2zgn+bBij2kffnRE7GKLdKmF/8/\n8SBp\r\n=1wZW\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./build/phaser-super-storage.min.js","types":"./build/ts/index.d.ts","config":{"name":"phaser-super-storage"},"gitHead":"56095b3c231afb15798aab17692ceab3a2b2fe2b","scripts":{"dev":"webpack-dev-server --mode development --config ./config/webpack.dev.config.js","dist":"webpack --mode production --config ./config/webpack.dist.config.js --progress --colors"},"_npmUser":{"name":"florisdh","email":"florisdh@gmail.com"},"repository":{"url":"git+ssh://git@github.com/azerion/phaser-super-storage.git","type":"git"},"_npmVersion":"6.9.0","description":"A cross platform storage plugin for Phaser","directories":{},"_nodeVersion":"8.11.1","dependencies":{"phaser":"^3.9.0","es6-promise-polyfill":"^1.2.0"},"_hasShrinkwrap":false,"devDependencies":{"tslint":"^5.10.0","webpack":"^4.12.0","ts-loader":"^4.4.0","typescript":"2.9.x","file-loader":"^1.1.11","webpack-cli":"^3.0.3","browser-sync":"^2.24.4","cache-loader":"^1.2.2","tslint-loader":"^3.6.0","@types/es6-promise":"^3.3.0","webpack-dev-server":"^3.1.4","@types/webfontloader":"^1.6.29","clean-webpack-plugin":"^0.1.19","browser-sync-webpack-plugin":"^1.2.0"},"_npmOperationalInternal":{"tmp":"tmp/phaser-super-storage_2.0.0-rc.1_1552644905257_0.9548711126336158","host":"s3://npm-registry-packages"}}},"time":{"created":"2019-03-15T10:03:22.670Z","modified":"2026-06-13T19:00:14.035Z","1.0.4":"2019-03-15T10:03:23.013Z","2.0.0-rc.1":"2019-03-15T10:15:05.416Z"},"bugs":{"url":"https://github.com/azerion/phaser-super-storage/issues"},"author":{"name":"Azerion"},"license":"MIT","homepage":"https://github.com/azerion/phaser-super-storage#readme","repository":{"url":"git+ssh://git@github.com/azerion/phaser-super-storage.git","type":"git"},"description":"A cross platform storage plugin for Phaser","contributors":[{"name":"Ale Bles","email":"a.bles@azerion.com"}],"maintainers":[{"email":"a.bles@azerion.com","name":"alebles"},{"email":"adsdk-support@azerion.com","name":"azerbot"},{"email":"a.hulsman@azerion.com","name":"hulsman1986"},{"email":"mr.muhasan@gmail.com","name":"moin.hasan"}],"readme":"Phaser Super Storage\r\n====================\r\nA cross platform pluggable storage plugin for Phaser V3.\r\nTe original for v2 is still available both here and on npm, but won't receive any feature updates anymore.\r\n\r\nKey features:\r\n - Cross browser support\r\n - Cookie Fallback\r\n - Support for iframes with helper script\r\n - Support for custom storage adapters\r\n \r\nRequirements\r\n - If you use TypeScript, also include the types for es6-promise in your project\r\n\r\nGetting Started\r\n===============\r\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.\r\n```\r\nnpm install @azerion/phaser-super-storage@2.0.0\r\n```\r\n\r\nAfter adding the script to the page you can activate it by preloading the plugin and installing it as a global plugin:\r\n```javascript\r\nimport PhaserSuperStorage from '@azerion/phaser-super-storage';\r\n\r\nclass MyScene extends Phaser.Scene {\r\n    preload: () => {\r\n        //either install or preload\r\n        this.plugins.install(\r\n            'PhaserSuperStorage',   //Plugin unique key\r\n            PhaserSuperStorage,     //The plugin\r\n            true,                   //Auto start\r\n            'storage'               //The scene mapping\r\n        );\r\n    }\r\n    \r\n    create: () => {\r\n        this.plugins.get().setNamespace('my-namespace');\r\n    }\r\n}\r\n\r\n```\r\n\r\nIt's imperitive to install this plugin as global plugin due to how the namespacing of storage key's is handled!\r\n\r\nUsage\r\n=====\r\nWhen you load the plugin, it automatically checks for availability of localStorage and fallbacks to cookies if it's not available.\r\nBoth of these are StorageAdapters and will be overwritten if you register a custom StorageAdaper, but more on this later.\r\n\r\nWhen you installed the plugin in your scene you can access it trough this.sys.storage. (Or this.storage if you have added it to your InjectionMap)\r\n\r\n```javascript\r\n//Store Tetris at FavoriteGame\r\nthis.storage.setItem('FavoriteGame', 'Tetris');\r\n\r\n//Get FavoriteGame\r\nlet favoriteGame = this.storage.getItem('FavoriteGame');  // Tetris\r\n\r\n//Remove FavoriteGame\r\nthis.storage.removeItem('FavoriteGame');\r\n\r\n//get the length of all items in storage\r\nlet l = this.storage.length;    // 1\r\n\r\n//Get the name of the key at the n'th position\r\nlet keyName = this.storage.key(0); // FavoriteGame\r\n\r\n//Clear all keys\r\nthis.storage.clear();\r\n```\r\n\r\nNamespaces\r\n----------\r\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 segeregated by namespaces.\r\nThis allows you to set a 'score' key for multiple games on the same domain, and they'll always get their own stored value\r\n\r\n```javascript\r\nthis.storage.setNamespace('tetris');\r\nthis.storage.setItem('score', 250);\r\n\r\nthis.storage.setNamespace('pong');\r\n\r\n//Length also takes namespaces into account\r\nlet l = this.storage.length;    // 0\r\n\r\n//this won't do because the score was registered under a different namespace\r\nlet value = this.storage.get('score'); // null\r\n\r\n```\r\n\r\nPromises\r\n--------\r\nBoth Cookies and localStorage work synchronous, meaning you immediatly get a return value after calling a funtion, e.g; getItem('key');\r\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 comming back in an asynchronous manner.\r\nIn order for you to parse your result nicely phaser-super-storage uses Promises to get you the result.\r\n\r\nIt is also possible to enable promises on the Cookie and localStorage adapters by setting forcePromises to true.\r\n```javascript\r\n//classical way of getting your item\r\nlet item = this.storage.getItem('key');\r\n\r\n//Now we are gonna force promises\r\nthis.storage.forcePromises = true;\r\nthis.storage.getItem('key').then(function (item) {\r\n    //do something with the item here\r\n});\r\n```\r\n\r\nAdapters\r\n========\r\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:\r\n```typescript\r\n interface IStorage {\r\n    //Promises or no Promises\r\n    forcePromises: boolean;\r\n\r\n    //The amount of items in the storage\r\n    length: number;\r\n\r\n    //The namespace for the current storge\r\n    namespace:string;\r\n\r\n    //Get an item from the storage\r\n    getItem(key: string): any | Promise<any>;\r\n\r\n    //remove an item from the localStorage\r\n    removeItem(key: string): any | Promise<any>;\r\n\r\n    //Set an item in the storage\r\n    setItem(key: string, value:any): void | Promise<void>;\r\n\r\n    //Get the n'th key\r\n    key(n: number): any | Promise<any>;\r\n\r\n    //empty the (namespaced) storage\r\n    clear(): void | Promise<void>;\r\n\r\n    setNamespace(namespace: string): void | Promise<void>;\r\n}\r\n```\r\n\r\nLocal & Cookie Storage\r\n----------------------\r\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 sotrage, no configuration needed!\r\n\r\nCordova\r\n-------\r\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:\r\n```javascript\r\nthis.storage.setAdapter(new PhaserSuperStorage.StorageAdapters.CordovaStorage());\r\n```\r\n\r\n\r\nIframe\r\n------\r\nWe publish our games on HTML5 game portals trough 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, than the helper script included in the build folder should be loaded in the parent frame.\r\nThis way we'll utilize the storage capacity of the parent frame to store our data\r\n\r\n```html\r\n<!--So in the parent frame we include the following: -->\r\n<script src=\"http://cdn.fbrq.io/phaser-super-storage/phaser-storage-helper.min.js\" type=\"text/javascript\"></script>\r\n```\r\n\r\n```javascript\r\n//Then in our game we add the iframe adapter\r\nlet iframeAdapter = new IframeStorage(\r\n    '',                     //The namespace to store the data under\r\n    document.referrer       //Then url of the parent domain, you need this for security reasons\r\n);\r\n\r\n//We call init first to see if the helper script is available, result as a Promise due to asynchronous communication\r\niframeAdapter.init().then(() => {\r\n    //It succeeded! Now set the iframe adapter as the main storage adapter\r\n    this.storage.setAdapter(iframeAdapter);\r\n}).catch((e) => {\r\n    //failed to start communication with parent, so lets enable promises on the original storage adapter to keep the API the same\r\n    this.storage.forcePromises = true;\r\n});\r\n```\r\n\r\nCaveats\r\n=======\r\nAltho 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 offcourse about private browsing. Both LocalStorage and Cookies will be cleared, so if you want to keep userdata alive their I suggest you try to get people to login and use a custom StorageAdapter to save the data server sided. Please note that we use the colon as namespace appendix, so we advice you not to use it yourself.   \r\n\r\nDisclaimer\r\n==========\r\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!\r\n\r\nPhaser Super Storage is distributed under the MIT license. All 3rd party libraries and components are distributed under their\r\nrespective license terms.","readmeFilename":"README.md"}