You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
Go to file
Derek Petersen 287db97a10 Bump version to 6.0.2 2 weeks ago
.vscode Add prettier 4 years ago
lib add compiled library to repo 7 months ago
src cleanup types, return unknown instead of any for getItem, update getAllItems return data 7 months ago
.editorconfig Move vscode settings to .editorconfig 5 years ago
.gitignore add compiled library to repo 7 months ago
.node-version add .node-version 7 months ago
.npmignore remove src from npmignore 7 months ago
.prettierignore Add prettier 4 years ago
LICENSE gitea -> codeberg 3 months ago
README.md codeberg -> self-hosted forgejo 2 weeks ago
build.js add esm build 7 months ago
package-lock.json Bump version to 6.0.2 2 weeks ago
package.json Bump version to 6.0.2 2 weeks ago
tsconfig.esm.json add esm build 7 months ago
tsconfig.umd.json add esm build 7 months ago

README.md

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