teko-oauth2
Version:
Teko Identity OAuth 2 Javascript Library for Web App Client
76 lines (57 loc) • 2.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var Storage = /*#__PURE__*/function () {
function Storage() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
_ref$prefix = _ref.prefix,
prefix = _ref$prefix === void 0 ? 'tekoid.' : _ref$prefix,
_ref$store = _ref.store,
store = _ref$store === void 0 ? sessionStorage : _ref$store;
_classCallCheck(this, Storage);
this._store = store;
this._prefix = prefix;
}
_createClass(Storage, [{
key: "set",
value: function set(key, value) {
key = this._prefix + key;
value = JSON.stringify(value);
this._store.setItem(key, value);
}
}, {
key: "get",
value: function get(key) {
key = this._prefix + key;
var value = this._store.getItem(key);
return JSON.parse(value);
}
}, {
key: "remove",
value: function remove(key) {
key = this._prefix + key;
var item = this._store.getItem(key);
this._store.removeItem(key);
return item;
}
}, {
key: "getAllKeys",
value: function getAllKeys() {
var keys = [];
for (var index = 0; index < this._store.length; index++) {
var key = this._store.key(index);
if (key.indexOf(this._prefix) === 0) {
keys.push(key.substr(this._prefix.length));
}
}
return keys;
}
}]);
return Storage;
}();
exports["default"] = Storage;