UNPKG

2.6 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports["default"] = void 0;
5
6/*!
7 * Copyright 2016 Amazon.com,
8 * Inc. or its affiliates. All Rights Reserved.
9 *
10 * Licensed under the Amazon Software License (the "License").
11 * You may not use this file except in compliance with the
12 * License. A copy of the License is located at
13 *
14 * http://aws.amazon.com/asl/
15 *
16 * or in the "license" file accompanying this file. This file is
17 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
18 * CONDITIONS OF ANY KIND, express or implied. See the License
19 * for the specific language governing permissions and
20 * limitations under the License.
21 */
22var dataMemory = {};
23/** @class */
24
25var MemoryStorage = /*#__PURE__*/function () {
26 function MemoryStorage() {}
27
28 /**
29 * This is used to set a specific item in storage
30 * @param {string} key - the key for the item
31 * @param {object} value - the value
32 * @returns {string} value that was set
33 */
34 MemoryStorage.setItem = function setItem(key, value) {
35 dataMemory[key] = value;
36 return dataMemory[key];
37 }
38 /**
39 * This is used to get a specific key from storage
40 * @param {string} key - the key for the item
41 * This is used to clear the storage
42 * @returns {string} the data item
43 */
44 ;
45
46 MemoryStorage.getItem = function getItem(key) {
47 return Object.prototype.hasOwnProperty.call(dataMemory, key) ? dataMemory[key] : undefined;
48 }
49 /**
50 * This is used to remove an item from storage
51 * @param {string} key - the key being set
52 * @returns {string} value - value that was deleted
53 */
54 ;
55
56 MemoryStorage.removeItem = function removeItem(key) {
57 return delete dataMemory[key];
58 }
59 /**
60 * This is used to clear the storage
61 * @returns {string} nothing
62 */
63 ;
64
65 MemoryStorage.clear = function clear() {
66 dataMemory = {};
67 return dataMemory;
68 };
69
70 return MemoryStorage;
71}();
72/** @class */
73
74
75var StorageHelper = /*#__PURE__*/function () {
76 /**
77 * This is used to get a storage object
78 * @returns {object} the storage
79 */
80 function StorageHelper() {
81 try {
82 this.storageWindow = window.localStorage;
83 this.storageWindow.setItem('aws.cognito.test-ls', 1);
84 this.storageWindow.removeItem('aws.cognito.test-ls');
85 } catch (exception) {
86 this.storageWindow = MemoryStorage;
87 }
88 }
89 /**
90 * This is used to return the storage
91 * @returns {object} the storage
92 */
93
94
95 var _proto = StorageHelper.prototype;
96
97 _proto.getStorage = function getStorage() {
98 return this.storageWindow;
99 };
100
101 return StorageHelper;
102}();
103
104exports["default"] = StorageHelper;
\No newline at end of file