Socket
Socket
Sign inDemoInstall

simple-storage

Package Overview
Dependencies
0
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    simple-storage

Simple localStorage / sessionStorage supporting objects and arrays


Version published
Weekly downloads
307
increased by141.73%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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

FAQs

Last updated on 14 Mar 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc