0.4.3 • Published 10 months ago

local-data-storage v0.4.3

Weekly downloads
2
License
ISC
Repository
github
Last release
10 months ago

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
}
0.4.3

10 months ago

0.4.1

2 years ago

0.4.0

2 years ago

0.4.2

2 years ago

0.3.0

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago