New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

local-data-storage

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

local-data-storage

Just another LocalStorage wrapper.

latest
Source
npmnpm
Version
0.4.4
Version published
Maintainers
0
Created
Source

Local Data Storage

It's a simple wrapper over browsers native localStorage. It uses "smart" items and can work with existing localStorage entries. It always returns success of operation as boolean.

Installation

$ npm install local-data-storage

Usage

NameParametersDescriptionReturn value
isAvailable()It tests if localStorage is availableboolean
itemExists()key: stringIt check existence of an itemboolean
clearExpiredItems()Clears expired itemsboolean
getItem()key: stringReturn an item by key*LocalDataStorageItem
setItem()key: string, obj: *LocalDataStorageItem, forceOverwrite?: booleanSaves an item with given keyboolean
removeItem()key: stringRemoves an item by keyboolean
clear()Clears the whole storageboolean

Examples:

import {
  isAvailable,
  itemExists,
  clearExpiredItems,
  getItem,
  setItem,
  removeItem,
  clear,
} from "local-data-storage";

if (isAvailable()) {
  /* do something */
}

if (itemExists("cat")) {
  /* do something */
}

clearExpiredItems();

const myItem = getItem("cat");

setItem("cat", { value: "meow" });
setItem("willExpireCat", { value: "meow", expiryDate: Date.now() + 86_400 });
setItem("cat", { value: "OVERWRITTEN" }, true);

removeItem("cat");

clear();

*LocalDataStorageItem

PropertyTypeDescription
valuestringThis will always exist, will contain unparseable items from storage as well.
createdDatenumberThis is a timestamp of creation. It will be set automatically at saving.
expiryDatenumberThis is an optional property. It's a timestamp of expiry, will be deleted by clearExpiredItems() if expired.

Example:

{
	value: 'cat',
	createdDate: 86400,
	expiryDate: 86401
}

Keywords

localstorage

FAQs

Package last updated on 17 Sep 2024

Did you know?

Socket

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