Custom simple storage
npm i @foxmon/storage
// In memory storage
const storage = Storage.asInMemory();
storage.set("A", "Data-A"); // A: Data-A
storage.set("B", "Data-B"); // B: Data-B
storage.get("A"); // Data-A
storage.get("B"); // Data-B
// As sessionStorage
const storage = Storage.asSessionMemory();
storage.set("A", "Data-A"); // A: Data-A
storage.get("A"); // Data-A
// As sessionStorage
const storage = Storage.asLocalMemory();
storage.set("A", "Data-A"); // A: Data-A
storage.get("A"); // Data-A
Save key-value
const storage = Storage.asInMemory();
storage.set("A", "Data-A"); // A: Data-A
Get item
const storage = Storage.asInMemory();
storage.set("A", "Data-A"); // A: Data-A
storage.get("A"); // Data-A
Get all keys in memory
const storage = Storage.asInMemory();
storage.set("A", "Data-A"); // A: Data-A
storage.set("B", "Data-B"); // B: Data-B
storage.keys(); // return ["A", "B"]
Get all values in memory
const storage = Storage.asInMemory();
storage.set("A", "Data-A"); // A: Data-A
storage.set("B", "Data-B"); // B: Data-B
storage.values(); // return ["Data-A", "Data-B"]
Remove item
const storage = Storage.asInMemory();
storage.set("A", "Data-A"); // A: Data-A
storage.remove("A");
Remove all item in storage
const storage = Storage.asInMemory();
storage.set("A", "Data-A"); // A: Data-A
storage.set("B", "Data-B"); // B: Data-B
storage.removeAll();
Count of items in storage
const storage = Storage.asInMemory();
storage.set("A", "Data-A"); // A: Data-A
storage.set("B", "Data-B"); // B: Data-B
storage.length; // 2