UNPKG

react-simple-game-engine

Version:

[WIP] not able to use in currently. <!-- Document cumming soon... -->

45 lines (44 loc) 1.59 kB
var _Saver = /** @class */ (function () { function _Saver() { this.store = window.localStorage; this.store ? console.log("Initial saver success") : console.log("Initial saver fail"); } _Saver.prototype.remove = function (key) { this.store.removeItem("".concat(_Saver.STORAGE_PREFIX).concat(key)); }; _Saver.prototype.set = function (key, value) { this.store.setItem("".concat(_Saver.STORAGE_PREFIX).concat(key), JSON.stringify(value)); }; _Saver.prototype.get = function (key, type) { var raw = this.store.getItem("".concat(_Saver.STORAGE_PREFIX).concat(key)); var parsed = (raw == null ? raw : JSON.parse(raw)); if (type === Boolean) { if (raw == null) { return undefined; } return (parsed === "0" || parsed === "false" || !parsed ? false : true); } if (type === Number) { return (parsed == null || isNaN(parsed) ? parsed : +parsed); } if (type === String) { return (parsed == null || typeof type === "string" ? parsed : parsed.toString()); } return parsed; }; _Saver.prototype.getWithDefault = function (key, defaultValue, type) { var value = this.get(key, type); return value !== null && value !== void 0 ? value : defaultValue; }; _Saver.STORAGE_PREFIX = "rsgn::"; return _Saver; }()); export var Saver = new _Saver();