0.3.0 • Published 7 years ago

browser-lsc-storage v0.3.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

browser-lsc-storage Build Status npm version Coverage Status license

localStorage, Session Storage and Cookies API wrapper for browser

TL;DR

import browserStorage from '../index'; // import Storage API Object
browserStorage.local.prefix = 'myApp'; // use localStorage and set a prefix
browserStorage.local.key('key', 'value'); // store 'key' with 'value'
console.log(browserStorage.local.key('key')); // read 'key'

const session = require('../index').default.session; // import SessionStorage API wrapper
session.key('session_id', '2017'); // store a key 'sesion_id' with value '2017'
console.log(session.key('session_id')); // read 'session_id'

localStorage/sessionStorage Class

Initialization

import StorageClass from '../storage'; // import Storage API wrapper
const Local = new StorageClass(); // create localStorage Class new instance
const Session = new StorageClass('sessionStorage'); // create sessionStorage Class new instance

Methods

isAvailable: check for availability.

const hasLocalStorage = Local.isAvailable(); // returns Boolean

prefix: set or read a prefix

Local.prefix = 'abc'; // set a prefix
const thisPrefix = Local.prefix; // read for a prefix, returns String

hasKey: check for a key

const res = Local.hasKey(key); // returns Boolean

key: write & read a key-value pair

Local.key(key, value); // store a Key with a defined Value, returns True if successful
const thisKey = Local.key(key); // read a key, returns String

removeKey: delete a key

Local.removeKey(key); // returns True if successful

length: get quantity of keys in DB

let keysNumber = Local.length; // returns a number of keys

clear: clear localStorage using prefix

let res = Local.clear(); // returns True if cleared

each: get all elements in the storage

let res = Local.each(); // returns an array of elements in the storage

forEach: iterate over all elements and run a callback function

Local.forEach((key, value, index) = > {}); // returns True always

Cookies Class

Initialization

import CookiesClass from '../cookies'; // import Cookies API wrapper
const Cookies = new CookiesClass(); // create Cookies Class new instance

Methods

isAvailable: check for availability.

const hasCookies = Cookies.isAvailable(); // returns Boolean

hasKey: check for a key

const res = Cookies.hasKey(key); // returns Boolean

key: write & read a key-value pair

Cookies.key(key, value, options); // store a Key with a defined Value and {Options}, returns True if successful
const thisKey = Cookies.key(key); // read a key, returns String

removeKey: delete a key

Cookies.removeKey(key); // returns always True

each: get all cookies

let res = Cookies.each(); // returns an array of elements

Copyright

coded by Anatol Marezhanyi @e1r0nd_crg

http://linkedin.com/in/merezhany/ https://www.youtube.com/c/AnatolMerezhanyi

License

MIT License

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago

1.0.0

7 years ago