Retrieve the current data set using this instance.
Reset the data back to its original value set with the init
method.
Set new data or overwrite old data in localStorage or sessionStorage. For TS developers, saving data of a different type to the one specified in the type parameter is prevented.
The data to save to localStorage or sessionStorage.
import storeBuddy from "store-buddy";
// Saves the string "bar" to the localStorage entry with the key "foo"
const storage1 = storeBuddy("foo").init("bar");
// Overwrites that same string with different data. Note that, without
// specifying a specific type when initialising, there is no type safety
// provided for TypeScript developers
storage1.save("baz");
storage1.save(123);
// This is type-safe...
const storage2 = storeBuddy<number>("foo").init(123);
// ...so this works...
storage2.save(456);
// ...and this does not work :)
storage2.save("I am not a number");
Remove all data set using this instance.