@russo-programmisto/easy-storage
TypeScript icon, indicating that this package has built-in type declarations

2.1.8 • Public • Published

At a Glance

easyStorage is a library that solves known issues of JavaScript's localStorage and sessionStorage.

When you use localStorage, you can read and write only string values. With this library, you can use any type of data including numbers, boolean values, JSON objects, etc. Sounds amazing, right? :)

How to Get Started

Type in Terminal:

npm install --save @russo-programmisto/easy-storage

or, if you prefer yarn over npm, type:

yarn add @russo-programmisto/easy-storage

Then add import instruction to your code:

import { S } from '@russo-programmisto/easy-storage'

Requirements

Basic knowledge of TypeScript and NPM.

Usage

easyStorage uses both localStorage and sessionStorage under the hood. The main idea is to keep everything simple yet functional.

How to Read

From local storage:

const firstName = S.local.get("first-name")

From session storage:

const firstName = S.session.get("first-name")

How to Write

To local storage:

S.local.set("first-name", "John")

To session storage:

S.session.set("first-name", "John")

Unlike the traditional localStorage and sessionStorage that accept only string values, you can set value of any type here:

// JSON
S.local.set("profile", {
    firstName: "John",
    lastName: "Appleseed",
    social: {
        reddit: "http://reddit.com/..."
    }
})

// number
S.local.set("click-count", 20)

// boolean
S.local.set("is-verified", true)

Timing

You can get the timestamp of the last change:

const timestamp = S.local.updatedOn("profile")

Then you can easily convert this timestamp to Date object:

const date = new Date(timestamp)

License

easyStorage is available under the MIT license. See the LICENSE file for more info.

Package Sidebar

Install

npm i @russo-programmisto/easy-storage

Weekly Downloads

0

Version

2.1.8

License

MIT

Unpacked Size

30.7 kB

Total Files

39

Last publish

Collaborators

  • russo-programmisto