A lightweight JavaScript library that's make dealing with localStorage
and sessionStorage
so easy.
By:
- Storing data with types so you don't need to convert objects or any other data type before and after using
Storage
. - Making a shortcuts for
Storage
functions names. - Adding new functions.
just include ls.min.js
file in your page.
<script src="path/to/ls.min.js"></script>
Note:
- that all functions below are aviable for localStorage
and sessionStroage
.
- ls
is a shortcut for localStorage
and ss
is short cut for sessionStorage
.
-
ls.l
=> equals tolocalStorage.length
. -
ls.set(key, val)
=> equals tolocalStorage.setItem(key, val)
-
ls.get(key)
=> equals tolocalStorage.setItem(key)
but convert the returned value to by with it's original type. -
ls.remove(key)
=> equals tolocalStorage.removeItem(key)
-
ls.rm(key)
=> equals tolocalStorage.removeItem(key)
-
ls.clear()
=> equals tolocalStorage.clear()
-
ls.c()
=> equals tolocalStorage.clear()
-
ls.keys()
=> returns all stored keys -
ls.values()
=> returns all stored values -
ls.getType(key)
=> returns the type of thatkey
-
ls.pushTo(key, item)
=> if the stored value with keykey
is an array then push the newitem
to it -
ls.removeByIdFrom(itemId, arr)
=> remove elment with iditemId
fromarr
item.