UNPKG

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