Xtorage
Install
$ npm i --save xtorage
What is this?
This is a tiny, yet powerful framework-agnostic wrapper for the web storage.
You shouldn't keep parsing strings/arrays/numbers/objects left and right to save/retrieve stuff into and from the storage.
Just call save()
, saveInFirstPosition()
, remove()
, removeLast()
and so on.
You can use it pretty much everywhere that is javascript in the client; So, it'll work for: angular
, aurelia
, vue
, electron
, etc.
API
constructor
new Xtoragestorage: 'localStorage' | 'sessionStorage', unique: boolean
let _x1 = 'localStorage'; _x1; // saves 1, with the key 'k' in the localStorage let _x2 = 'sessionStorage'; _x2; // saves 1, with the key 'k' in the sessionStorage let _x3 = ; _x3; // saves 1, with the key 'k' in the localStorage - which is the default let _x4 = undefined true; _x4; // array length is 1 _x4; // array length is still 1, unique is set to true let _x5 = undefined false; _x5; // array length is 1 _x5; // array length is 2, unique is set to false let _x6 = ; _x6; // array length is 1 _x6; // array length is 2, unique, by default, is false
save
savekey:string, info:any:void
let _x = ; _x; console; // {a: 1}
saveInFirstPosition
saveInFirstPositionkey:string, info:any:void
let _x = ; _x; console; // [{a: 1}] _x; console; // [{b: 2}, {a: 1}]
saveInLastPosition
saveInLastPositionkey:string, info:any:void
let _x = ; _x; console; // [{a: 1}] _x; console; // [{a: 1}, {b: 2}]
get
getkey:string:any
let _x = ; _x; console; // [1, true, {a: 1}, [{c: 'abc'}]
getFirst
getFirstkey:string:void
let _x = ; _x; console; // {a: 1} _x; console; // {a: 1}
getLast
getLastkey:string:void
let _x = ; _x; console; // {a: 1} _x; console; // {b: 2}
remove
removekey:string:void
let _x = ; _x; console; // {a: 1} _x; console; // undefined
removeAll
removeAll:void
let _x = ; _x; _x; console; // {a: 1} console; // [{somethingElse: true}] _x; console; // undefined console; // undefined
removeFirst
removeFirstkey:string:void
let _x = ; _x; _x; console; // [{a: 1}, {b: 2}] _x; console; // [{b: 2}]
removeLast
removeLastkey:string:void
let _x = ; _x; _x; console; // [{a: 1}, {b: 2}] _x; console; // [{a: 1}]