@aws-amplify/core
Version:
Core category of aws-amplify
59 lines (57 loc) • 1.75 kB
JavaScript
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.KeyValueStorage = void 0;
const errors_1 = require("../errors");
/**
* @internal
*/
class KeyValueStorage {
constructor(storage) {
this.storage = storage;
}
/**
* This is used to set a specific item in storage
* @param {string} key - the key for the item
* @param {object} value - the value
* @returns {string} value that was set
*/
async setItem(key, value) {
if (!this.storage)
throw new errors_1.PlatformNotSupportedError();
this.storage.setItem(key, value);
}
/**
* This is used to get a specific key from storage
* @param {string} key - the key for the item
* This is used to clear the storage
* @returns {string} the data item
*/
async getItem(key) {
if (!this.storage)
throw new errors_1.PlatformNotSupportedError();
return this.storage.getItem(key);
}
/**
* This is used to remove an item from storage
* @param {string} key - the key being set
* @returns {string} value - value that was deleted
*/
async removeItem(key) {
if (!this.storage)
throw new errors_1.PlatformNotSupportedError();
this.storage.removeItem(key);
}
/**
* This is used to clear the storage
* @returns {string} nothing
*/
async clear() {
if (!this.storage)
throw new errors_1.PlatformNotSupportedError();
this.storage.clear();
}
}
exports.KeyValueStorage = KeyValueStorage;
//# sourceMappingURL=KeyValueStorage.js.map
;