6.0.2 • Published 1 year ago

simple-storage v6.0.2

Weekly downloads
52
License
MIT
Repository
-
Last release
1 year ago

simple-storage

Store strings and objects to local or session storage. Falls back to storing data in memory if run on platforms where the Storage API is unavailable (such as node).

sessionStorage

Store items for current session

import { simpleSessionStorage } from "simple-storage";

// set item
simpleSessionStorage.setItem("pets", {
  dogs: 3,
  cats: 1,
});

// get item
const pets = simpleSessionStorage.getItem("pets");
console.log(pets); // { dogs: 3, cats: 1 }

// get all items
const items = simpleSessionStorage.getAllItems();
console.log(items); // [ [ "pets", {dogs: 3, cats: 1} ] ]

// get all items async
const i = await simpleSessionStorage.getAllItemsAsync();
console.log(i); // [ [ "pets", {dogs: 3, cats: 1} ] ]

// remove item
simpleSessionStorage.removeItem("pets");

// remove all items
simpleSessionStorage.clear();

localStorage

Store items for longer than current session when possible

import { simpleLocalStorage } from "simple-storage";

// set item
simpleLocalStorage.setItem("pets", {
  dogs: 3,
  cats: 1,
});

// get item
const pets = simpleLocalStorage.getItem("pets");
console.log(pets); // { dogs: 3, cats: 1 }

// get all items
const items = simpleLocalStorage.getAllItems();
console.log(items); // [ [ "pets", {dogs: 3, cats: 1} ] ]

// get all items async
const i = await simpleLocalStorage.getAllItemsAsync();
console.log(i); // [ [ "pets", {dogs: 3, cats: 1} ] ]

// remove item
simpleLocalStorage.removeItem("pets");

// remove all items
simpleLocalStorage.clear();

https://git.fedi.ai/tuxracer/simple-storage

6.0.2

1 year ago

6.0.1

1 year ago

6.0.0

2 years ago

4.0.4

2 years ago

4.0.3

2 years ago

5.0.1

5 years ago

5.0.0

5 years ago

4.0.2

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.2.0

6 years ago

3.1.0

6 years ago

3.0.0

6 years ago

2.2.0

10 years ago

2.1.5

10 years ago

2.1.4

11 years ago

2.1.3

11 years ago

2.1.2

11 years ago

2.1.1

11 years ago

2.1.0

11 years ago

2.0.4

11 years ago