UNPKG

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