bc-node-sdk
Version:
BetterCommerce's NodeJS SDK encapsulates the base framework for all the Next.js applications.
41 lines (40 loc) • 1.29 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const parse_util_1 = __importDefault(require("./parse-util"));
class LocalStorageUtil {
/**
* Sets an item in local storage by key.
* @param key the key
* @param data the data to store
*/
static setItem(key, data) {
if (typeof window !== "undefined") {
localStorage.setItem(key, parse_util_1.default.jsonStringify(data));
}
}
/**
* Retrieves an item from local storage by key.
* @param key the key
* @returns the item if it exists, otherwise null
*/
static getItem(key) {
let item = null;
if (typeof window !== "undefined") {
item = localStorage.getItem(key);
}
return parse_util_1.default.tryParseJson(item);
}
/**
* Removes an item from local storage by key.
* @param key the key of the item to remove
*/
static removeItem(key) {
if (typeof window !== "undefined") {
localStorage.removeItem(key);
}
}
}
exports.default = LocalStorageUtil;